karldenton Posted March 6, 2007 Share Posted March 6, 2007 Hi, I am very new to PHP/MySQL so please forgive me if this is a really simple problem. I have wrote a system to mange revision guides for a school. The pages that assign a book to a student works fine. When a student returns the book i simply want to change the status to "Returned" from "With Student". The code for return.php is shown below: <? include("../header.php"); $db = connectdb(); echo "<h1>Return Books</h1>"; echo "<p>Please enter book number</p>"; echo "<form action=\"$s\">"; echo "<input type=\"text\" name=\"data\" />"; echo "<input type=\"submit\" value=\"Submit\" />"; echo "<br />"; echo "<br />"; $search = $_REQUEST['data']; if ($data) { echo "<h1>Results</h1>"; $db = connectdb(); $b = mysql_query("SELECT bookno FROM revision WHERE bookno LIKE '%$data%'"); $r = mysql_query("SELECT * FROM revision WHERE bookno LIKE '%$data%'"); echo "<table class=\"report\">"; echo " <tr>"; echo " <th>Username</th>"; echo " <th>Forename</th>"; echo " <th>Surname</th>"; echo " <th>Teacher</th>"; echo " <th>Book Number</th>"; echo " <th>Status</th>"; while ($res = mysql_fetch_assoc($r)) { echo "<tr>"; echo " <td valign=top>{$res["username"]}</td>"; echo " <td valign=top>{$res["forename"]}</td>"; echo " <td valign=top>{$res["surname"]}</td>"; echo " <td valign=top>{$res["ictteacher"]}</td>"; echo " <td valign=top>{$res["bookno"]}</td>"; echo " <td valign=top>{$res["status"]}</td>"; } echo "</table>"; } else echo ""; echo "<br />"; echo "<br />"; echo "<input type='submit' name='Returned' value='Returned' />"; echo "<br />"; if(isset($_REQUEST['Returned'])) { mysql_query("UPDATE revision SET status ='Returned' WHERE bookno = $search"); echo mysql_error(); //echo "<meta http-equiv=\"refresh\" content=\"0;url=return.php\" />"; } else { echo ""; } ?> When data is typed into the text box "Data" and the Submit button is clicked, the results are shown below it. Then, when a user presses the "Returned" button, it should update the selected row. However, there is an error in the syntax, possibly because when the "Returned" button is pressed, there is no data in the text field. Any help on this would be greatly appreciated. Many thanks Karl Link to comment https://forums.phpfreaks.com/topic/41463-update-query/ Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 what is this about? echo " "; echo " "; } else echo ""; echo " "; echo " "; what are you trying to accomplish there? Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-200866 Share on other sites More sharing options...
skali Posted March 6, 2007 Share Posted March 6, 2007 if(isset($_REQUEST['Returned'])) { if(!empty($_POST['data'])){ mysql_query("UPDATE revision SET status ='Returned' WHERE bookno = '{$_POST['data']}'"); echo mysql_error(); }else echo 'book no missing'; } Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-200870 Share on other sites More sharing options...
monk.e.boy Posted March 6, 2007 Share Posted March 6, 2007 what is this about? echo " "; echo " "; } else echo ""; echo " "; echo " "; what are you trying to accomplish there? What do you mean? I thought you had to put these lines in to make the code faster? 90% of my code is: <?php if( true ){ echo " ";} echo " "; ?> monk.e.boy Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-200875 Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 what is this about? echo " "; echo " "; } else echo ""; echo " "; echo " "; what are you trying to accomplish there? What do you mean? I thought you had to put these lines in to make the code faster? 90% of my code is: <?php if( true ){ echo " ";} echo " "; ?> monk.e.boy dude, you're not launching a rocket. and the less number times you call functions the better. not the other way around. Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-200890 Share on other sites More sharing options...
karldenton Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, Sorry forthe confusion on the } else echo ""; echo " "; echo " "; In the code i copied from Dreamweaver there are break tags in the quotes but they must have got stripped out. Thanks Skali for your reply, gave it a go and providing there is text in the box it performs the query fine. Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-200966 Share on other sites More sharing options...
monk.e.boy Posted March 7, 2007 Share Posted March 7, 2007 what is this about? echo " "; echo " "; } else echo ""; echo " "; echo " "; what are you trying to accomplish there? What do you mean? I thought you had to put these lines in to make the code faster? 90% of my code is: <?php if( true ){ echo " ";} echo " "; ?> monk.e.boy dude, you're not launching a rocket. and the less number times you call functions the better. not the other way around. But yes I am. I work for NASA and quite often they run my PHP code on the shuttle and hubble space telescope (no IP address cos I don't want hax0rs breakin the hubble) and IIS, how did you think space men talk to ground control? Not through fukcing mobile phones"! They're using custom php modules: echo" "; >> the less number times you call functions the better. duh! haven't you heard of recursion!!!!!11!!!one!111 monk.e.boy Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-201549 Share on other sites More sharing options...
boo_lolly Posted March 7, 2007 Share Posted March 7, 2007 got some sand in yer vagina, monkey? Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-201743 Share on other sites More sharing options...
monk.e.boy Posted March 7, 2007 Share Posted March 7, 2007 ;D no sense of humor? monk.e.boy Link to comment https://forums.phpfreaks.com/topic/41463-update-query/#findComment-201814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.