jeppers Posted September 5, 2007 Share Posted September 5, 2007 hi peeps i am having so much trouble.. i have created a form which takes values from the reg users database and the values are passed from a view users script. the scrip i am working on is designed so the user can change there details and then update there account... but my problem is that when i submit the form nothing happens and it just appiers as a blank screen. i have checked that the database is working. and that is... please help out a newbie as i am only learning.. thanks <?php # Script 8.4 - edit_user.php // This page edits a user. // This page is accessed through view_users.php. $page_title = 'Edit a User'; include ('includes/header_inc.php'); // Check for a valid user ID, through GET or POST. if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_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.</p><p><br /><br /></p>'; include ('includes/footer_inc.php'); exit(); } require_once ('includes/mysql_connect.php'); // Connect to the db. // Check if the form has been submitted. if (isset($_POST['submitted'])) { $errors = array(); // Initialize error array. // Check for a first name. if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = escape_data($_POST['first_name']); } // Check for a last name. if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = escape_data($_POST['last_name']); } // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } if (empty($errors)) { // If everything's OK. // Test for unique email address. $query = "SELECT user_id FROM users WHERE email='$e' AND user_id != $id"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // Make the query. $query = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Edit a User</h1> <p>The user 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 user 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. include ('includes/footer_inc.php'); exit(); } } else { // Already registered. echo '<h1 id="mainhead">Error!</h1> <p class="error">The email address 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 first_name, last_name, email FROM users WHERE user_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 User</h2> <form action="edit_user.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="' . $row[0] . '" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="' . $row[1] . '" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" 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>'; } else { // Not a valid user ID. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; } mysql_close(); // Close the database connection. include ('includes/footer_inc.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68127-have-you-ever-thought-about-banging-your-head/ Share on other sites More sharing options...
trq Posted September 5, 2007 Share Posted September 5, 2007 Theres a fair bit of code in your post but straight away I see this section as a problem. <?php // added to get the boards syntax highlight working. $query = "SELECT user_id FROM users WHERE email='$e' AND user_id != $id"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // Make the query. $query = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. ?> Here you check if the user exists, if not you try and UPDATE there record. If they don't exist, you can't very well UPDATE the record because it doesn't exist. Quote Link to comment https://forums.phpfreaks.com/topic/68127-have-you-ever-thought-about-banging-your-head/#findComment-342455 Share on other sites More sharing options...
jeppers Posted September 5, 2007 Author Share Posted September 5, 2007 i have another form which has all the details of the reg memeber with a edit and a delete option. when i delete an reg user works fine. when i click on the edit option it goes to the page. i change some details and then when i submit it nothing.. i am just not sure where to look Quote Link to comment https://forums.phpfreaks.com/topic/68127-have-you-ever-thought-about-banging-your-head/#findComment-342462 Share on other sites More sharing options...
Jessica Posted September 5, 2007 Share Posted September 5, 2007 lol. Edit: Hey genius, I was "lol"ing at your inability to read. No need to PM me and think we're friends now. Thorpe found your problem and you are still clueless. Quote Link to comment https://forums.phpfreaks.com/topic/68127-have-you-ever-thought-about-banging-your-head/#findComment-342465 Share on other sites More sharing options...
jeppers Posted September 6, 2007 Author Share Posted September 6, 2007 can someone please help Quote Link to comment https://forums.phpfreaks.com/topic/68127-have-you-ever-thought-about-banging-your-head/#findComment-342736 Share on other sites More sharing options...
jeppers Posted September 6, 2007 Author Share Posted September 6, 2007 well as you can see i am not seeing what i should do hear i need someone to spell it out for me. i just don't see what to do Quote Link to comment https://forums.phpfreaks.com/topic/68127-have-you-ever-thought-about-banging-your-head/#findComment-342796 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.