demonforce Posted September 13, 2007 Share Posted September 13, 2007 When i want to update an table, 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 'ben vandaag aan dit project begonnen, om mijn uren te vermelden, handig, makkeli' at line 1 this is with these scrips Bewerkuren.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style2 {color: #999900} .style3 { color: #000000; font-weight: bold; } .style5 {color: #999900; font-weight: bold; } --> </style> </head> <body bgcolor="#666666"> <?php require("mysql.connect.php"); if(isset($_GET['id'])){ if(!is_numeric($_GET['id'])){ die('The page doesnt exists'); } $id = mysql_real_escape_string($_GET['id']); $query = @mysql_query("SELECT * FROM uren WHERE id='$id'") or die(mysql_error()); $values = mysql_fetch_array($query); } echo '<form action="http://84.24.104.234/uren/verzondenbewerkuren.php" method="post"> <table width="212" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="68" class="style3"><input name="id" type="text" id="id" maxlength="9999" value="'.$values['id'].'"/>niet veranderen!</td> <td width="144"><div align="center"></div></td> </tr> <tr> <td valign="top" class="style3">Week NR </td>'; echo ' <td><input name="weeknr" type="text" id="weeknr" maxlength="9999" value="'.$values['weeknr'].'"/></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Datum1</td>'; echo ' <td><input name="datum1" type="text" id="datum1" maxlength="9999" value="'.$values['datum1'].'"/></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Bericht1</td>'; echo ' <td><textarea name="bericht1" cols="21" rows="10" id="bericht1">'.$values['bericht1'].'</textarea></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Uren1</td>'; echo ' <td><input name="uren1" type="text" id="uren1" maxlength="9999" value="'.$values['uren1'].'"/></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Datum2</td>'; echo ' <td><input name="datum2" type="text" id="datum2" maxlength="9999" value="'.$values['datum2'].'"/></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Bericht2</td>'; echo ' <td><textarea name="bericht2" cols="21" rows="10" id="bericht2">'.$values['bericht2'].'</textarea></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Uren2</td>'; echo ' <td><input name="uren2" type="text" id="uren2" maxlength="9999" value="'.$values['uren2'].'"/></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Datum3</td>'; echo ' <td><input name="datum3" type="text" id="datum3" maxlength="9999" value="'.$values['datum3'].'"/></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Bericht2</td>'; echo ' <td><textarea name="bericht3" cols="21" rows="10" id="bericht3">'.$values['bericht3'].'</textarea></td>'; echo ' </tr> <tr> <td valign="top" class="style3">Uren3</td>'; echo ' <td><input name="uren3" type="text" id="uren3" maxlength="9999" value="'.$values['uren3'].'"/></td>'; echo ' </tr>'; echo ' <tr> <td class="style3"><input type="submit" name="Submit" value="Inzenden" /></td> <td><div align="center"> <input type="reset" name="reset" value="Resetten" /> </div></td> </tr> </table>'; ?> </body> </html> verzondenbewerkuren.php <html> <head> <title>*</title> </head> <body bgcolor="771111"> <?php $id = $_POST["id"]; $weeknr = $_POST["weeknr"]; $datum1 = $_POST["datum1"]; $bericht1 = $_POST["bericht1"]; $uren1 = $_POST["uren1"]; $datum2 = $_POST["datum2"]; $bericht2 = $_POST["bericht2"]; $uren2 = $_POST["uren2"]; $datum3 = $_POST["datum3"]; $bericht3 = $_POST["bericht3"]; $uren3 = $_POST["uren3"]; ?> <?php require('mysql.connect.php'); $sql = "UPDATE uren SET `weeknr` = ".$weeknr.", `datum1` = ".$datum1." , `bericht1` = ".$bericht1." , `uren1` = ".$uren1." , `datum2` = ".$datum2." , `bericht2` = ".$bericht2." , `uren2` = ".$uren2." , `datum3` = ".$datum3." , `bericht3` = ".$bericht3." , `uren3` = ".$uren3."' WHERE `id` = ".$id.""; mysql_query($sql) or die(mysql_error()); echo "<font size='6'>hij staat erin.</font>"; echo "<meta http-equiv='REFRESH' content='10;URL=index.php'>"; ?> </body> </html> i dont get why i get the error :/ Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/ Share on other sites More sharing options...
chronister Posted September 13, 2007 Share Posted September 13, 2007 Try this.. $sql = "UPDATE uren SET weeknr = '$weeknr',datum1 = '$datum1' , bericht1 = '$bericht1' , uren1 = '$uren1' , datum2 = '$datum2' , bericht2 = '$bericht2' , uren2 = '$uren2' , datum3 = '$datum3' , bericht3 = '$bericht3' , uren3 = '$uren3' WHERE id = '$id'"; There is no need to concatenate the string within the query. Just surround the whole query with " and surround the vars with ' works for me every time. Nate Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/#findComment-347944 Share on other sites More sharing options...
demonforce Posted September 14, 2007 Author Share Posted September 14, 2007 okay, i now did this like you said: $sql = "UPDATE uren SET weeknr = $weeknr, datum1 = $datum1 , bericht1 = $bericht1 , uren1 = $uren1 , datum2 = $datum2 , bericht2 = $bericht2 , uren2 = $uren2 , datum3 = $datum3 , bericht3 = $bericht3 , uren3 = $uren3 WHERE `id` = $id"; mysql_query($sql) or die(mysql_error()); but i still get the same error :/ Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/#findComment-348285 Share on other sites More sharing options...
beboo002 Posted September 14, 2007 Share Posted September 14, 2007 use this code may help u and also echo the value $sql = "UPDATE uren SET weeknr = '".$_POST['weeknr']."', datum1 = '".$_POST['datum1']."' ' WHERE id = '".$_POST['id']."'; Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/#findComment-348300 Share on other sites More sharing options...
demonforce Posted September 14, 2007 Author Share Posted September 14, 2007 i did that, and now i get this error with this code: 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 '1'' at line 1 <html> <head> <title>*</title> </head> <body bgcolor="771111"> <?php $id = $_POST["id"]; $weeknr = $_POST["weeknr"]; $datum1 = $_POST["datum1"]; $bericht1 = $_POST["bericht1"]; $uren1 = $_POST["uren1"]; $datum2 = $_POST["datum2"]; $bericht2 = $_POST["bericht2"]; $uren2 = $_POST["uren2"]; $datum3 = $_POST["datum3"]; $bericht3 = $_POST["bericht3"]; $uren3 = $_POST["uren3"]; ?> <?php require('mysql.connect.php'); $sql = "UPDATE uren SET weeknr = '".$_POST['weeknr']."', datum1 = '".$_POST['datum1']."', bericht1 = '".$_POST['bericht1']."', uren1 = '".$_POST['uren1']."', datum2 = '".$_POST['datum2']."', bericht2 = '".$_POST['bericht2']."', uren2 = '".$_POST['uren2']."', datum3 = '".$_POST['datum3']."', bericht3 = '".$_POST['bericht3']."', uren3 = '".$_POST['uren3']."' ' WHERE id = '".$_POST['id']."'"; mysql_query($sql) or die(mysql_error()); echo "<font size='6'>hij staat erin.</font>"; echo "<meta http-equiv='REFRESH' content='10;URL=index.php'>"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/#findComment-348374 Share on other sites More sharing options...
chronister Posted September 14, 2007 Share Posted September 14, 2007 okay, i now did this like you said: $sql = "UPDATE uren SET weeknr = $weeknr, datum1 = $datum1 , bericht1 = $bericht1 , uren1 = $uren1 , datum2 = $datum2 , bericht2 = $bericht2 , uren2 = $uren2 , datum3 = $datum3 , bericht3 = $bericht3 , uren3 = $uren3 WHERE `id` = $id"; mysql_query($sql) or die(mysql_error()); but i still get the same error :/ No you did not do like I said. Surround your vars with ' '. and take out the ` from the id part. Just copy and paste what I gave ya in the last post. I just copied your code and took it into notepad and removed the stuff that was not needed and added the single quotes. Nate Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/#findComment-348376 Share on other sites More sharing options...
demonforce Posted September 14, 2007 Author Share Posted September 14, 2007 it works, thanks!!!! Quote Link to comment https://forums.phpfreaks.com/topic/69236-solved-erro-when-want-to-update-some-stuff/#findComment-348514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.