| | |
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 |
301 advanced apache api array autosuggest basics beginner broken cakephp class cms code combobox compression cron curl data database date datepart display dropdownlist dynamic email eregi error execution file files folder form forms function functions google head href htaccess html httppost if...loop image include includingmysecondfileinthechain ip javascript job joomla jquery js key library limit link login md5 menu mlm multiple mysql mysql_real_escape_string oop password paypal pdf pdfdownload php phpvotingscript problem procedure query random screen script search searchbox server session sessions smarty source space sql stored system table traffic tutorial unicode upload url variable video volume votedown web website youtube zend






