Jump to content

header doesn't redirect me to main.php


Namtip

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.