I don't know whether this belongs here or in the MySQL section.
I'm trying to write a couple of values from a search page to a database: but no matter how I tweak the code, I always end up with "Error, insert query failed"...
The code is:
I've included the code shown as line 1 above because that always works as expected: the variables are known to the script. The original code held all the connection information in another file, but I brought it back in to simplify debugging (lol).
The table name is correct, as are the field names. There is an auto-incrementing ID as the first field in the table.
I assume there is some glaringly simple syntax error here, but I've been staring at it and tweaking it for so long that I just can't see it.
I'm trying to write a couple of values from a search page to a database: but no matter how I tweak the code, I always end up with "Error, insert query failed"...
The code is:
Code:
<h3><?php echo $_SESSION['SESS_MEMBER_ID']," ",$query; ?></h3>
<?php
$link = mysql_connect('localhost','root','EC4SPvRn');
if(!$link) {
die('Unable to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db('search_trial');
if(!$db) {
die("Unable to select database");
}
$sql = "INSERT INTO 'search_records' ('query','user') VALUES ('".$query."','".$_SESSION['SESS_MEMBER_ID']."')";
mysql_query($sql) or die ('Error, insert query failed');
?>
The table name is correct, as are the field names. There is an auto-incrementing ID as the first field in the table.
I assume there is some glaringly simple syntax error here, but I've been staring at it and tweaking it for so long that I just can't see it.
Comment