lukedouglas98 Posted October 21, 2012 Share Posted October 21, 2012 Any help appreciated i get the following error when the code is executed up to update_ac.php Parse error: syntax error, unexpected T_STRING in - on line 21 /file/update_ac.php //update.php// <?php //sql connection details here // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>id</strong></td> <td align="center"><strong>Post</strong></td> </tr> <tr> <td> </td> <td align="center"> <input name="name" type="text" id="name" value="<? echo $rows['id']; ?>"> </td> <td align="center"> <input name="lastname" type="text" id="lastname" value="<? echo $rows['input_text']; ?>" size="15"> </td> </tr> <tr> <td> </td> <td> <input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"> </td> <td align="center"> <input type="submit" name="Submit" value="Submit"> </td> <td> </td> </tr> </table> </td> </form> </tr> </table> <?php // close connection mysql_close(); ?> //update_ac.php// <?php //sql connect details here// // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $post = $_POST['lastname']; $id = $_POST['name']; // update data in mysql database $sql="UPDATE `micro_blog_posts` SET `input_text`='$post' WHERE `id`='$id' $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?> //list_records.php// <?php // sql connect details here// // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="400" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><strong>Your posts</strong> </td> </tr> <tr> <td align="center"><strong>id</strong></td> <td align="center"><strong>Post</strong></td> <td align="center"><strong>Update</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['id']; ?></td> <td><? echo $rows['input_text']; ?></td> <!-- link to update.php and send value of id --!> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> Please help.... Any help appreciated Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/ Share on other sites More sharing options...
JohnTipperton Posted October 21, 2012 Share Posted October 21, 2012 can you use the [code}[/code]. so we can see clearly. Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386723 Share on other sites More sharing options...
Pikachu2000 Posted October 21, 2012 Share Posted October 21, 2012 You're missing the closing quote and semicolon from your second query string. The second call to mysql_connect isn't needed, nor is the call to mysql_close at the end, BTW. Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386738 Share on other sites More sharing options...
johnnyd1963 Posted October 21, 2012 Share Posted October 21, 2012 try to use $sql="UPDATE micro_blog_posts SET input_text =".$post." WHERE id=".$id."; instaed of $sql="UPDATE `micro_blog_posts` SET `input_text`='$post' WHERE `id`='$id' Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386741 Share on other sites More sharing options...
Pikachu2000 Posted October 21, 2012 Share Posted October 21, 2012 There's no need for the extra concatenation. All the existing query string needs is a quote and semicolon added to the end of it. The values should be sanitized before being used in a query string, however. Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386744 Share on other sites More sharing options...
johnnyd1963 Posted October 21, 2012 Share Posted October 21, 2012 sorry i see it at ".$id."; it must be ".$id.""; Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386747 Share on other sites More sharing options...
Pikachu2000 Posted October 21, 2012 Share Posted October 21, 2012 Not quite. Simply `id`='$id'"; is all it needs. Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386750 Share on other sites More sharing options...
Christian F. Posted October 22, 2012 Share Posted October 22, 2012 Johnnyd: Do you write all numbers with +0 at the end? Concatenating an empty string (."") is the same, you know. Completely unnecessary. Link to comment https://forums.phpfreaks.com/topic/269735-update-database-error-please-help/#findComment-1386970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.