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?

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.

I'd suggest making use of the PHP/MySQL error functions such as mysql_errno and mysql_error.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.