Jump to content

Adding data to MySQL


dcole.ath.cx

Recommended Posts

Is everything right here? How about this part ... talk (message, response) ... should they have $ in front? If everything is right here, I set up the MySQL wrong.... what could be the problem with that?

<?php// Connect to MySQL using this data:$dbhost = 'localhost';$dbuser = 'root';$dbpass = '';$dbname = 'chat';// "talk" is name of MySQL table// Connect to MySQL and a table within it$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');mysql_select_db($dbname);// insert data into MySQL$message = 'Hey';$response = 'Hey';$query = "INSERT INTO talk (message, response) VALUES ($message, $response)";mysql_query($query) or die('Error, insert query failed');print 'Thank you, data has been learned.';?>

Link to comment
Share on other sites

The string values in the $query have to have quotation marks around them:

$query = "INSERT INTO talk (message, response) VALUES ('$message', '$response')";

Remember, you can always echo mysql_error(); to see what is wrong with a query.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...