can you fix the problem???

Thread Solved

Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

can you fix the problem???

 
0
  #1
Jan 11th, 2009
i get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index, user_id, username, message) VALUES(' ', '4', 'zack', 'jh')' at line 1
  1. <?php
  2.  
  3. session_start();
  4.  
  5. $_SESSION['user_id'] = 4;
  6.  
  7. $user_id = $_SESSION['user_id'];
  8.  
  9. $_SESSION['username'] = "zack";
  10.  
  11. $username = $_SESSION['username'];
  12.  
  13. $message = $_POST['shout_mes'];
  14.  
  15. $insert = $_POST['shout'];
  16.  
  17.  
  18. if(!empty($message) && $insert = "shout"){
  19.  
  20. include('mysqlcon.php');
  21.  
  22. $select = mysql_select_db($db, $con);
  23. if(!$select){
  24. die('could not select db: ' . mysql_error());
  25. }
  26.  
  27.  
  28. $sql = mysql_query("INSERT INTO shoutbox (index, user_id, username, message) VALUES(' ', '$user_id', '$username', '$message')");
  29.  
  30. if(!$sql){
  31. echo "error" . mysql_error();
  32. }else{
  33. header("location: index.php");
  34. }
  35.  
  36. }else{
  37.  
  38. echo "there was an error: " . mysql_error();
  39. }
  40.  
  41. ?>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: can you fix the problem???

 
0
  #2
Jan 11th, 2009
If the user_id data type is numeric, then it won't need single quotes in the sql.
  1. $sql = mysql_query("INSERT INTO shoutbox (index, user_id, username, message) VALUES(' ', $user_id, '$username', '$message')");

This could also apply to the index, however since you are inserting an empty value, I would assume the datatype is not numeric.
Last edited by buddylee17; Jan 11th, 2009 at 6:03 pm.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

Re: can you fix the problem???

 
0
  #3
Jan 11th, 2009
thank you for your help. how dumb it was
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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