mysql_query() failing. Why?

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

mysql_query() failing. Why?

 
0
  #1
Sep 21st, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: mysql_query() failing. Why?

 
0
  #2
Sep 21st, 2006
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!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 155
Reputation: mostafadotnet is on a distinguished road 
Solved Threads: 10
mostafadotnet's Avatar
mostafadotnet mostafadotnet is offline Offline
Junior Poster

Re: mysql_query() failing. Why?

 
0
  #3
Sep 21st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: mysql_query() failing. Why?

 
0
  #4
Sep 21st, 2006
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!
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: mysql_query() failing. Why?

 
0
  #5
Sep 21st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql_query() failing. Why?

 
0
  #6
Sep 22nd, 2006
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!
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: mysql_query() failing. Why?

 
0
  #7
Sep 22nd, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC