This is a discussion on QUERY AND UPDATE PROBLEM within the PHP Language forums, part of the PHP Programming Forums category; //---DELETE ENTRY FROM DATABASE--- should be //---UPDATE ENTRY IN DATABASE---...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
This is the ouput for......
$query = "UPDATE calendar_events SET event_title = '" . $title . "',"; $query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'"; $query .= " WHERE id = ". $event; test2 2006-02-23 01:00:00 testYou have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '01:00:00, event_shortdesc = 'test' WHERE id =' at line 1 |
|
|||
|
Lag wrote:
> This is the ouput for...... > > $query = "UPDATE calendar_events SET event_title = '" . $title . "',"; > > $query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'"; > > $query .= " WHERE id = ". $event; > > > test2 2006-02-23 01:00:00 testYou have an error in your SQL syntax. > Check the manual that corresponds to your MySQL server version for the > right syntax to use near '01:00:00, event_shortdesc = 'test' WHERE id > =' at line 1 > It's telling you the same thing everyone else has been saying - although not so clearly. ALL non-numeric data MUST be within single quotes. And 01:00:00 is not numeric data. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
I added a count ($count) to see if or how many rows were being
affected.............even though I am tagging them by id, which auto increments for each new event. I am not selecting any row, even though I know the id is correct. I went into the database to make sure. This is the code and the result of running the code. //---UPDATE ENTRY IN DATABASE--- $result = mysql_query("SELECT * FROM calendar_events WHERE id='.$event'",$conn); $count = mysql_num_rows($result); $query = "UPDATE calendar_events SET event_title = '$title', event_start = '$date', event_shortdesc = '$desc' WHERE id = '$result'"; mysql_query($query) or die(mysql_error()); //LIST ITEMS echo "$event $title $date $desc"; echo "<br>Record Updated! Rows Affected: $count"; mysql_close(); ?> This is the result.... test2 2006-02-23 01:00:00 test Record Updated! Rows Affected: 0 |
|
|||
|
Sorry, I completely overlooked that..........I changed it and now am
getting this............... 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 '' at line 1. Thanks for the help. |
|
|||
|
Lag wrote:
> I added a count ($count) to see if or how many rows were being > affected.............even though I am tagging them by id, which auto > increments for each new event. I am not selecting any row, even though > I know the id is correct. I went into the database to make sure. > > This is the code and the result of running the code. > > //---UPDATE ENTRY IN DATABASE--- > $result = mysql_query("SELECT * FROM calendar_events WHERE > id='.$event'",$conn); > $count = mysql_num_rows($result); > $query = "UPDATE calendar_events SET event_title = '$title', > event_start = '$date', event_shortdesc = '$desc' WHERE id = '$result'"; > mysql_query($query) or die(mysql_error()); > > //LIST ITEMS > echo "$event $title $date $desc"; > > echo "<br>Record Updated! Rows Affected: $count"; > mysql_close(); > > ?> > > This is the result.... > > test2 2006-02-23 01:00:00 test > Record Updated! Rows Affected: 0 > What is the type of column `id`? If it's numeric, then it should NOT be in single quotes. Also in your update statement $result is a result set, not an id. You need to use "UPDATE calendar_events..... WHERE id= '$event'". -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Lag wrote:
> Sorry, I completely overlooked that..........I changed it and now am > getting this............... > > 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 '' at > line 1. > > Thanks for the help. > Echo your query before you run it to see if it's what you think it is. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Lag wrote:
> This is the ouput for...... > > $query = "UPDATE calendar_events SET event_title = '" . $title . "',"; > > $query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'"; > > $query .= " WHERE id = ". $event; > > > test2 2006-02-23 01:00:00 testYou have an error in your SQL syntax. > Check the manual that corresponds to your MySQL server version for the > right syntax to use near '01:00:00, event_shortdesc = 'test' WHERE id > =' at line 1 > okay.. show us the entire script - remove any passwords, usernames etc... add: echo $query."<br>; so we can see the query as the database sees it... in MySQL> show fields from calendar_events; In your code, I do not see where you are selecting the data to see if it changed or not (or are you doing this in MySql -- is so, copy/paste the select statement and the result so we can see what you are doing. Basic troubleshooting techniques -- make sure what you are contatenating is what you think it should be... |