guitar idiot Posted November 22, 2007 Share Posted November 22, 2007 Ok, I'm completely new at this whole parameter thing like this http://www.dfsdfBlah.com?id=453454Like thatNow to access it i just use a $_GET, right?but the only i see how i can do that is to right it like thisheader('Location: next.php?id=4');I can't seem to do this ('Location: next.php?id=' .$id);When I do i get (in the location bar) http://localhost/my/next.php?id= Theres nothing therehow can do it with a variable value or whatever? without having to spell it out completely And the reason for parameters is to pass a variable onto another page right? Link to comment Share on other sites More sharing options...
Ingolme Posted November 22, 2007 Share Posted November 22, 2007 Most likely you haven't defined $id before so it appears empty. Link to comment Share on other sites More sharing options...
guitar idiot Posted November 22, 2007 Author Share Posted November 22, 2007 Most likely you haven't defined $id before so it appears empty.<?phpsession_start(); $db_host = 'localhost'; $db_user = 'root'; $db_pass ='greencar'; $db_db = 'user'; if (isset($_POST['username'])) { $db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySQL Connection Error:' .mysql_error()); mysql_select_db($db_db) or die('Error'); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $result = mysql_query("SELECT username, password FROM user WHERE username = '$username' AND password = '$password ' "); $query_row=mysql_fetch_array($result);$user = $query_row['username'];$pass = $query_row['password'];$id = $query_row['ID'];if($username!='' and $password!='') {if($username===$user and $password===$pass) {$_SESSION['username'] = $username;header("Location: next.php?id=' + $id);echo 'Login Successful';} else {header( 'Location: start.php' );<?phpsession_start(); $db_host = 'localhost'; $db_user = 'root'; $db_pass ='greencar'; $db_db = 'user'; if (isset($_POST['username'])) { $db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySQL Connection Error:' .mysql_error()); mysql_select_db($db_db) or die('Error'); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $result = mysql_query("SELECT username, password FROM user WHERE username = '$username' AND password = '$password ' "); $query_row=mysql_fetch_array($result);$user = $query_row['username'];$pass = $query_row['password'];$id = $query_row['ID'];if($username!='' and $password!='') {if($username===$user and $password===$pass) {$_SESSION['username'] = $username;header("Location: next.php?id=' + $id);echo 'Login Successful';} else {header( 'Location: start.php' );$bob = '<p class="error"> Invalid, Usernames and Passwords ARE case sensitive.</p>';}}else {header('Location: start.php');$_SESSION['error'] = '<p id="error">Invalid, Usernames and Passwords ARE case sensitive.</p> ';}mysql_close($db_link);}else {header( 'Location: start.php' ) ;$_SESSION['error'] = '<p id="error">Invalid, Usernames and Passwords ARE case sensitive.</p> ';}?><html><head><link rel="stylesheet" type="text/css"href="main.css" /></head><body></body></html> = '<p class="error"> Invalid, Usernames and Passwords ARE case sensitive.</p>';}}else {header('Location: start.php');$_SESSION['error'] = '<p id="error">Invalid, Usernames and Passwords ARE case sensitive.</p> ';}mysql_close($db_link);}else {header( 'Location: start.php' ) ;$_SESSION['error'] = '<p id="error">Invalid, Usernames and Passwords ARE case sensitive.</p> ';}?><html><head><link rel="stylesheet" type="text/css"href="main.css" /></head><body></body></html>I already defined $id, i know because when you get to the next.php page it prints $id Link to comment Share on other sites More sharing options...
Ingolme Posted November 22, 2007 Share Posted November 22, 2007 Oh! now I get it!You don't use the + operator for concatenation in PHP, you use a . .header("Location: next.php?id=' + $id); //wrongheader("Location: next.php?id=' . $id); //right Link to comment Share on other sites More sharing options...
guitar idiot Posted November 22, 2007 Author Share Posted November 22, 2007 Oh! now I get it!You don't use the + operator for concatenation in PHP, you use a . .header("Location: next.php?id=' + $id); //wrongheader("Location: next.php?id=' . $id); //right I tried that, same thing id= Link to comment Share on other sites More sharing options...
Ingolme Posted November 22, 2007 Share Posted November 22, 2007 I don't know if this will help but I notice you have a single quote instead of a double quote at the end of the string.Try header("Location: next.php?id=" . $id);And if not, then the problem must be with the $id variable. Link to comment Share on other sites More sharing options...
guitar idiot Posted November 22, 2007 Author Share Posted November 22, 2007 I don't know if this will help but I notice you have a single quote instead of a double quote at the end of the string.Try header("Location: next.php?id=" . $id);And if not, then the problem must be with the $id variable.I did a test, and yeah its the id var. Link to comment Share on other sites More sharing options...
guitar idiot Posted November 22, 2007 Author Share Posted November 22, 2007 I did a test, and yeah its the id var.I fixed it $result = mysql_query("SELECT * FROM user WHERE username = '$username' AND password = '$password ' "); $query_row=mysql_fetch_array($result);$user = $query_row['username'];$pass = $query_row['password'];$id = $query_row['ID']; <------Right here, the column was called "Id" not "ID"Thanks for the help Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.