I won't beat around the bush. A simple form is posting the field "notes" and "request_id" to this script. "billingrequest" is my tablename, "notes" is the field on the table I wish to update with the field "notes", and requestid is the field on the table that identifies which row to update.
Here's the code:

include 'config.php';
$notes = $_POST['notes'];
$request_id = $_POST['request_id'];
$query = "UPDATE billingrequest SET notes = $notes". "WHERE requestid=$request_id";
echo $notes;
echo $request_id;
mysql_query($query) or die('Error, query failed');


I keep getting the error, 'Error, query failed'. What am I doing wrong? I've doublechecked the spellings of the fields and everything. Any ideas?

10 Years
Discussion Span
Last Post by Puckdropper

Usually a bad query is what causes an error like you are experiencing. Echo your query out to the browser window and verify it actually contains the values you are expecting. You probably have a bad value in a variable or a syntax error.


Hi nathanpacker,
First of all use add_slashes() to add slashes to special input characters [string] which may result in SQL Injection Attack.
Second,use this style:

$query = "UPDATE billingrequest SET notes = '$notes'". "WHERE requestid = '$request_id'";

Good luck.


Actually, you shouldn't use addslashes(). You should should use mysql_real_escape_string(). It is the native function for MySQL and should virtually be used on every piece of data being entered into a MySQL database. See the PHP manual for more information on it.


Thanks for the replies. I feel bad for saying this, but I've been doing so much coding the last couple days, and overcoming different hurdles, I think I eventually just found a different way to do this. Oh now I remember. I was enabling the user to add notes to this record, but realized they may want to add notes more than once. So rather than trying to append notes to the end of the old notes, I just created a new table and tied them together. That way, they could ad as many notes as they want, and I could easily tie the two tables together. Thanks for the help!


Ah, the evolutionary development model. It's not important unless you intend to flood the earth (I.E. scrap it and start over) and improve your design once you've got everything figured out.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.