patelp7 Posted March 20, 2007 Share Posted March 20, 2007 Im trying to update a a table and I am getting 2 error messages. 1) The varibles have not been defined. 2) that the query is wrong. Can someone please help? <? session_start(); require ("db.php.inc"); // Check for a valid user ID, through GET or POST. First time round $_GET[‘id’] is set if ( (isset($_GET['id'])) ) { // Accessed through $id = $_GET['id']; } elseif ( (isset($_POST['id'])) ) { // Form has been submitted. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error. - not passing 1st stage</p><p><br /><br /></p>'; exit(); } // Check if the form has been submitted. if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. // Check to see if Subject has been entered. if (empty($_POST['Subject'])) { $errors[] = 'You forgot to enter the subject.'; } else { //$Subject = ($_POST['Subject']); } if (empty($errors)) { // If everything's OK. // Test for unique bulletin ID. However if email field in the database is unique this is not necessary. $query = "SELECT Bulletin_ID FROM Bulletin WHERE Bulletin_ID ='$id' "; $result = mysql_query($query); //should be equal to 1 as 1 bulletin has been entered. if (mysql_num_rows($result) == 1) { // Make the query. $query = "UPDATE Bulletin SET Subject ='$Subject', Description ='$Description', DrComments ='$DrComments' WHERE Bulletin_ID =$id AND Adminusername = '".$_SESSION['Username']."' "; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Edit Bulletin</h1> <p>The Bulletin 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 Bulletin could not be edited due to a system error. We apologise for any inconvenience. - line 48</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } } else { // Already registered. echo '<h1 id="mainhead">Error!</h1> <p class="error">The Bulletin ID has already been registered.</p>'; } } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. } // End of submit conditional. // Always show the form. // Retrieve the user's information. $query = "SELECT Subject, Description, DrComments FROM Bulletin WHERE Bulletin_ID = $id"; $result = @mysql_query ($query); // Run the query. if (mysql_num_rows($result) == 1) { // Valid user ID, show the form. // Get the user's information. $row = mysql_fetch_array ($result, MYSQL_NUM); // Create the form. echo '<h2>Edit a Bulletin</h2> <form action="editspecificbull.php" method="post"> <p>Subject: <input type="text" name="Subject" value="' . $row[0] . '" /></p> <p>Description: <input type="text" name="Description" value="' . $row[1] . '" ></textarea></p> <p>Dr Comments: <input type="text" name="DrComments" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } ?> Link to comment https://forums.phpfreaks.com/topic/43504-updating-a-field/ Share on other sites More sharing options...
kenrbnsn Posted March 20, 2007 Share Posted March 20, 2007 Please give us the exact error messages and wrap your code in tags. Ken Link to comment https://forums.phpfreaks.com/topic/43504-updating-a-field/#findComment-211259 Share on other sites More sharing options...
patelp7 Posted March 20, 2007 Author Share Posted March 20, 2007 Notice: Undefined variable: Subject in h:\Project\HTDOCS\new patient database\editspecificbull.php on line 37 Notice: Undefined variable: Description in h:\Project\HTDOCS\new patient database\editspecificbull.php on line 37 Notice: Undefined variable: DrComments in h:\Project\HTDOCS\new patient database\editspecificbull.php on line 37 Query: UPDATE Bulletin SET Subject = '', Description ='', DrComments = '' WHERE Bulletin_ID =35 AND Adminusername = 'shakeys' Im trying to update a a table and I am getting 2 error messages. 1) The varibles have not been defined. 2) that the query is wrong. Can someone please help? <? session_start(); require ("db.php.inc"); // Check for a valid user ID, through GET or POST. First time round $_GET[id] is set if ( (isset($_GET['id'])) ) { // Accessed through $id = $_GET['id']; } elseif ( (isset($_POST['id'])) ) { // Form has been submitted. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error. - not passing 1st stage</p><p><br /><br /></p>'; exit(); } // Check if the form has been submitted. if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. // Check to see if Subject has been entered. if (empty($_POST['Subject'])) { $errors[] = 'You forgot to enter the subject.'; } else { //$Subject = ($_POST['Subject']); } if (empty($errors)) { // If everything's OK. // Test for unique bulletin ID. However if email field in the database is unique this is not necessary. $query = "SELECT Bulletin_ID FROM Bulletin WHERE Bulletin_ID ='$id' "; $result = mysql_query($query); //should be equal to 1 as 1 bulletin has been entered. if (mysql_num_rows($result) == 1) { // Make the query. $query = "UPDATE Bulletin SET Subject ='$Subject', Description ='$Description', DrComments ='$DrComments' WHERE Bulletin_ID =$id AND Adminusername = '".$_SESSION['Username']."' "; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Edit Bulletin</h1> <p>The Bulletin 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 Bulletin could not be edited due to a system error. We apologise for any inconvenience. - line 48</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. exit(); } } else { // Already registered. echo '<h1 id="mainhead">Error!</h1> <p class="error">The Bulletin ID has already been registered.</p>'; } } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. } // End of submit conditional. // Always show the form. // Retrieve the user's information. $query = "SELECT Subject, Description, DrComments FROM Bulletin WHERE Bulletin_ID = $id"; $result = @mysql_query ($query); // Run the query. if (mysql_num_rows($result) == 1) { // Valid user ID, show the form. // Get the user's information. $row = mysql_fetch_array ($result, MYSQL_NUM); // Create the form. echo '<h2>Edit a Bulletin</h2> <form action="editspecificbull.php" method="post"> <p>Subject: <input type="text" name="Subject" value="' . $row[0] . '" /></p> <p>Description: <input type="text" name="Description" value="' . $row[1] . '" ></textarea></p> <p>Dr Comments: <input type="text" name="DrComments" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } ?> Link to comment https://forums.phpfreaks.com/topic/43504-updating-a-field/#findComment-211282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.