Namtip Posted September 20, 2010 Share Posted September 20, 2010 Problem: The page does not redirect the end user to main.php. Notice: Use of undefined constant name_id - assumed 'name_id' in C:\x\xampp\htdocs\pages\form_process.php on line 48 Warning: Cannot modify header information - headers already sent by (output started at C:\x\xampp\htdocs\pages\form_process.php:48) in C:\x\xampp\htdocs\pages\form_process.php on line 87 The error messages displayed above make it seem like they are connected to the problem, but I don't understand why 'name_id' is undefined as its auto increments in mysql. I also think my .htaccess might be preventing me from redirecting, is that possible? " header('Refresh: 5; URL=http://localhost/pages/main.php'); " Goal: redirect user to main.php without error messages being displayed. form_process.php <?php //let's start our session, so we have access to stored datasession_start();if (isset($_POST['terms_and_conditions']) == 0) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('You must agree to the terms and conditions to create a profile. Go back and try again.');}include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';$securimage = new Securimage();if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('The code you entered was incorrect. Go back and try again.');}else {include 'db.inc.php';$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Check your connection parameters.');mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); $error = array(); $query = 'SELECT name FROM user WHERE ' . 'name = "' . mysql_real_escape_string($_SESSION['values']['name'], $db) . '"' ; $result = mysql_query($query, $db) or die(mysql_error($db));if(mysql_num_rows($result) > 0) {$error['uname'] = '<p class="errText">Username is taken.</p>'; header('Refresh: 5; URL=form1.php');}//let's create the queryelse{$query = sprintf("INSERT INTO user ( name_id, name, password) VALUES ('%s','%s','%s')",name_id,mysql_real_escape_string($_SESSION['values']['name']),mysql_real_escape_string(md5(SALTY . $_SESSION['values']['password'])));//let's run the query$result = mysql_query($query, $db) or die(mysql_error($db));$name_id = mysql_insert_id();$query = sprintf("INSERT INTO contact ( name_id, first_name, last_name, email, address, city, county, post, home, mobile) VALUES (LAST_INSERT_ID(),'%s','%s','%s','%s','%s','%s','%s','%s','%s')",mysql_real_escape_string($_SESSION['values']['first_name']),mysql_real_escape_string($_SESSION['values']['last_name']),mysql_real_escape_string($_SESSION['values']['email']),mysql_real_escape_string($_SESSION['values']['address']),mysql_real_escape_string($_SESSION['values']['city']),mysql_real_escape_string($_SESSION['values']['county']),mysql_real_escape_string($_SESSION['values']['post']),mysql_real_escape_string($_SESSION['values']['home']),mysql_real_escape_string($_SESSION['values']['mobile']));//let's run the query$result = mysql_query($query, $db) or die(mysql_error($db));$name_id = mysql_insert_id();$query = sprintf("INSERT INTO profile ( name_id, bi, ex) VALUES (LAST_INSERT_ID(),'%s','%s')",mysql_real_escape_string($_SESSION['pro']['bi']),mysql_real_escape_string($_SESSION['pro']['ex']));$result = mysql_query($query, $db) or die(mysql_error($db)); $_SESSION['logged'] = 1; header('Refresh: 5; URL=http://localhost/pages/main.php'); }?><html><head> <title>Register</title></head><body> <p><strong>Thank you <?php echo $_SESSION['values']['name']; ?> for registering!</strong></p> <p>Your registration is complete! You are being sent to the page yourequested. If your browser doesn't redirect properly after 5 seconds,<a href="main.php">click here</a>.</p></body></html><?phpsession_destroy(); die(); }?> Link to comment https://forums.phpfreaks.com/topic/213938-header-doesnt-redirect-me-to-mainphp/ Share on other sites More sharing options...
KevinM1 Posted September 20, 2010 Share Posted September 20, 2010 We have a stickied topic describing 'headers already sent' errors: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Also name_id is not the same as $name_id. Link to comment https://forums.phpfreaks.com/topic/213938-header-doesnt-redirect-me-to-mainphp/#findComment-1113461 Share on other sites More sharing options...
Namtip Posted September 21, 2010 Author Share Posted September 21, 2010 I changed this code to remove the "Notice: Use of undefined constant name_id - assumed 'name_id' in C:\x\xampp\htdocs\pages\form_process.php on line 48" error. This in turn solved the knock on error. I also later looked for any whitespaces as recommended in the other linked post $query = sprintf("INSERT INTO user ( name, password) VALUES ('%s','%s')", mysql_real_escape_string($_SESSION['values']['name']), mysql_real_escape_string(md5(SALTY . $_SESSION['values']['password']))); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); Thanks guys. Link to comment https://forums.phpfreaks.com/topic/213938-header-doesnt-redirect-me-to-mainphp/#findComment-1113519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.