Jump to content

form not submitting/sql query not working


trilbyfish

Recommended Posts

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

Link to comment
Share on other sites

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']) {

 

 

 

 

 

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.