trilbyfish Posted March 10, 2008 Share Posted March 10, 2008 i havea a form with a submit button, which when clicked should update a mysql table. When i hit the submit button, all it seems to do is refresh the page with the original data in the text boxes, and no error is printed on the page. the code is here <?php session_name('visit'); session_start(); //check for session value if(!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']))){ // Redirect the user to the loggedin.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/members.php'; header("Location: $url"); exit(); // Quit the script. } // This script retrieves all the records from the users table. // This new version allows the results to be sorted in different ways. $page_title = 'View the booking table'; require_once ('../project/connect.php'); // Connect to the db. // Make sure the id that was on the bookingtable page was set, and select the relevent bay record from the sql 'bookingtable' table // Check for $_GET id if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM bookingtable WHERE id = $id"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // Table header. echo '<table align="center" cellspacing="0" cellpadding="5" border ="1"> <tr> <td align="left"><b>Bay Number</b></td> <td align="left"><b>08:00 - 09:00 </b></td> <td align="left"><b>09:00 - 10:00 </b></td> <td align="left"><b>10:00 - 11:00 </b></td> <td align="left"><b>11:00 - 12:00 </b></td> <td align="left"><b>12:00 - 13:00 </b></td> <td align="left"><b>13:00 - 14:00 </b></td> <td align="left"><b>14:00 - 15:00 </b></td> <td align="left"><b>15:00 - 16:00 </b></td> <td align="left"><b>16:00 - 17:00 </b></td> </tr> '; // Fetch and print the record whice corresponds to the bay id from the 'edit' link that was clicked on the bookingtable page if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <tr> <td align="left">' . $row['baynumber'] . '</td> <input type="hidden" name="submitted" value="TRUE" /> <form action="editbay.php?id=' . $row['id'] . '" method="post"> <td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" value="' . $row['08:00 - 09:00'] . '" /></td> <td align="left"><input type="text" name="09:00 - 10:00" size="12" maxlength="30" value="' . $row['09:00 - 10:00'] . '" /></td> <td align="left"><input type="text" name="10:00 - 11:00" size="12" maxlength="30" value="' . $row['10:00 - 11:00'] . '" /></td> <td align="left"><input type="text" name="11:00 - 12:00" size="12" maxlength="30" value="' . $row['11:00 - 12:00'] . '" /></td> <td align="left"><input type="text" name="12:00 - 13:00" size="12" maxlength="30" value="' . $row['12:00 - 13:00'] . '" /></td> <td align="left"><input type="text" name="13:00 - 14:00" size="12" maxlength="30" value="' . $row['13:00 - 14:00'] . '" /></td> <td align="left"><input type="text" name="14:00 - 15:00" size="12" maxlength="30" value="' . $row['14:00 - 15:00'] . '" /></td> <td align="left"><input type="text" name="15:00 - 16:00" size="12" maxlength="30" value="' . $row['15:00 - 16:00'] . '" /></td> <td align="left"><input type="text" name="16:00 - 17:00" size="12" maxlength="30" value="' . $row['16:00 - 17:00'] . '" /></td> </tr> <tr ><td colspan="11" td align="middle"><input type="submit" name="submit" value="Submit" </td></tr> </table> '; } echo '</table>'; // Check if the form has been submitted. if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. // Check for a 08:00 - 09:00 time slot. if (empty($_POST['08:00 - 09:00'])) { $errors[] = 'You forgot to enter something in 08:00 - 09:00.'; } else { $eight = escape_data($_POST['08:00 - 09:00']); } if (empty($errors)) { // If everything's OK. { // Make the query. $query = "UPDATE bookingtable SET 08:00 - 09:00='$eight' WHERE id=$id"; $result = mysql_query ($query) or die(mysql_error(). " -- $query"); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Edit a Bay</h1> <p>A time slot has been edited.</p><p><br /><br /></p>'; } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The time slot could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } mysql_free_result ($result); // Free up the resources. } } } } } } }else{ echo '<p>'. mysql_error() . '<br/> <br/>Query: ' . $query . '</p>'; } mysql_close(); // Close the database connection. echo "<p>If you wish to go back and view the bookingtable click <a href = bookingtable.php>here</a></p>"; ?> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/ Share on other sites More sharing options...
trilbyfish Posted March 10, 2008 Author Share Posted March 10, 2008 im still stumped, please help Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488583 Share on other sites More sharing options...
bpops Posted March 10, 2008 Share Posted March 10, 2008 Forgot to close your form </form> Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488620 Share on other sites More sharing options...
trilbyfish Posted March 10, 2008 Author Share Posted March 10, 2008 mmm, ive put </form> after </table>, but still the same thing is happening. Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488630 Share on other sites More sharing options...
nadeemshafi9 Posted March 10, 2008 Share Posted March 10, 2008 <input type="submit" name="submit" value="Submit" is missing > you should do your code like this echo "". "". "". ""; Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488638 Share on other sites More sharing options...
trilbyfish Posted March 10, 2008 Author Share Posted March 10, 2008 <input type="submit" name="submit" value="Submit" is missing > you should do your code like this echo "". "". "". ""; I've put in the > but still the same problem. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488663 Share on other sites More sharing options...
l0ve2hat3 Posted March 10, 2008 Share Posted March 10, 2008 REPLACE THIS: <tr ><td colspan="11" td align="middle"><input type="submit" name="submit" value="Submit" </td></tr> </table> '; } echo '</table>'; // Check if the form has been submitted. if (isset($_POST['submitted'])) { WITH THIS: <tr ><td colspan="11" td align="middle"><input type="submit" name="submit" value="Submit"></td></tr> </form> </table> '; } echo '</table>'; // Check if the form has been submitted. if ($_REQUEST['submit']) { Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488714 Share on other sites More sharing options...
MadTechie Posted March 10, 2008 Share Posted March 10, 2008 is "08:00 - 09:00" a value field!!! surely your need some back tick! ie `08:00 - 09:00` also you have <?php if (isset($_GET['id'])) { //snip }else{ echo '<p>'. mysql_error() . '<br/> <br/>Query: ' . $query . '</p>'; } ?> which i assume is not what you expected! Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488722 Share on other sites More sharing options...
trilbyfish Posted March 10, 2008 Author Share Posted March 10, 2008 REPLACE THIS: <tr ><td colspan="11" td align="middle"><input type="submit" name="submit" value="Submit" </td></tr> </table> '; } echo '</table>'; // Check if the form has been submitted. if (isset($_POST['submitted'])) { WITH THIS: <tr ><td colspan="11" td align="middle"><input type="submit" name="submit" value="Submit"></td></tr> </form> </table> '; } echo '</table>'; // Check if the form has been submitted. if ($_REQUEST['submit']) { Thanks for the help, but it still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488839 Share on other sites More sharing options...
trilbyfish Posted March 10, 2008 Author Share Posted March 10, 2008 is "08:00 - 09:00" a value field!!! surely your need some back tick! ie `08:00 - 09:00` also you have <?php if (isset($_GET['id'])) { //snip }else{ echo '<p>'. mysql_error() . '<br/> <br/>Query: ' . $query . '</p>'; } ?> which i assume is not what you expected! i'm not sure what you mean. The <td align="left"><input type="text" name="08:00 - 09:00" size="12" maxlength="30" value="' . $row['08:00 - 09:00'] . '" /></td> part is just echoing some values from an sql table, whcih works fine, its just the updating of the table which doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488841 Share on other sites More sharing options...
raydawg Posted March 10, 2008 Share Posted March 10, 2008 you shouldn't initialize your form INSIDE a table....then end your form OUTSIDE the table. that makes no sense at all ??? infact your not even really initializing your form inside of anything. you initialize it in the abyss of nothingness which are TR's. then your creating a hidden field thats not even inside your form, its above it. I think the PHP issues are the least of your worries........im not sure how scope friendly HTML really is....but that is a nightmare Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488842 Share on other sites More sharing options...
trilbyfish Posted March 10, 2008 Author Share Posted March 10, 2008 what do you suggest i should do? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-488861 Share on other sites More sharing options...
trilbyfish Posted March 12, 2008 Author Share Posted March 12, 2008 still stumped Quote Link to comment https://forums.phpfreaks.com/topic/95358-form-not-submittingsql-query-not-working/#findComment-490723 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.