Jump to content

Adding data to MySQL


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...