| | |
mysql_query() failing. Why?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
[PHP]<?
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');
?>[/PHP]
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?
Here's the code:
[PHP]<?
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');
?>[/PHP]
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.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
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:
Good luck.
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.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
•
•
Join Date: Jul 2004
Posts: 494
Reputation:
Solved Threads: 21
I'd suggest making use of the PHP/MySQL error functions such as mysql_errno and mysql_error.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
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!
•
•
Join Date: Jul 2004
Posts: 494
Reputation:
Solved Threads: 21
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.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
![]() |
Similar Threads
- Failing Hard Drive, need some advice (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: errors showing up when page isn't running
- Next Thread: Need a Simple Solution
| Thread Tools | Search this Thread |
ajax apache api array arrays beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external file files folder form forms forum function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu method mlm multiple mysql neutrality oop paypal pdf php phpmysql play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validator variable video web xml youtube






