rotten69 Posted April 26, 2011 Share Posted April 26, 2011 Hi there, I am experiencing a few errors in the php sections and can not really see any obvious problems with the php lines.. Please your help would be appreciated.. <?php session_start(); if($_REQUEST['username'] == "rotten" && $_REQUEST['password'] == "1212"){ $_SESSION['username'] = "rotten"; $_SESSION['password'] = "1212"; header("Location: home.php ".$_SESSION['pageredirect']); }else{ $_SESSION['displayerror'] = "0"; header("Location: "); // I want users to stay on the same page which is page3 I called it, so If I do specify the page in header("location":........) it will break the page for some reasons. } ?> This is the message that is coming up when I try executing the code --> Notice: Undefined index: username in C:\wamp\www\prac4\login.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/ Share on other sites More sharing options...
kenrbnsn Posted April 26, 2011 Share Posted April 26, 2011 How is this code being invoked? When posting code to this forum, please put it between tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206418 Share on other sites More sharing options...
Muddy_Funster Posted April 26, 2011 Share Posted April 26, 2011 $_REQUEST[] is not being assigned the values you think it is - trace back how you are assigning these values and you will find the problem. Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206424 Share on other sites More sharing options...
rotten69 Posted April 26, 2011 Author Share Posted April 26, 2011 @ ken, it's my first time to use this site. So, Excuse me! @ Muddy.. I declared $username="rotten" and $password="1212" just above $_REQUEST..the problem is still coming up on the same line that is 3.. Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206433 Share on other sites More sharing options...
Muddy_Funster Posted April 26, 2011 Share Posted April 26, 2011 you didn't do what I suggested Try changing the top of the page code to this: <?php SESSION_START(); echo '$_REQUEST username value = '.$_REQUEST['username'].'<br>'; echo '$_REQUEST password value = '.$_REQUEST['password'].'<br>'; die(); //rest of your page code here let us know what it sais is in the variables - or if you get the same error again. Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206436 Share on other sites More sharing options...
rotten69 Posted April 26, 2011 Author Share Posted April 26, 2011 Thanks mate for the help. But, I still get errors on the same lines 3 and 4 Notice: Undefined index: username in C:\wamp\www\folder\login.php on line 3 $_REQUEST username value = Notice: Undefined index: password in C:\wamp\www\folder\login.php on line 4 $_REQUEST password value = I wonder if there is a php debugger... And also, I'd really really appreciate your effort if you just explain what the lines you've just suggested are supposed to do. Please throw useful websites at me that are super-useful to learn php from other than php.net. Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206461 Share on other sites More sharing options...
Muddy_Funster Posted April 26, 2011 Share Posted April 26, 2011 What you just atempted was to put the contents of $_REQUEST['username'] and $_REQUEST['password'] to the screen as text. but as they have no given values PHP is telling you that it can't do what you are asking. How are you getting username and password values into the $_REQUEST array? Could you post the code for that part of the process? Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206467 Share on other sites More sharing options...
kenrbnsn Posted April 26, 2011 Share Posted April 26, 2011 The $_REQUEST array is populated via information on the URL or from a form. You really should use the $_GET array if the values are coming from the URL (or a form using the "get" method) or the $_POST array if the values come from a form with using the "post" method. At the top of your script, put: <?php if (isset($_POST)) { echo '<pre>$_POST: ' . print_r($_POST, true) . '</pre>'; echo '<pre>$_GET: ' . print_r($_GET,true) . '</pre>'; ?> This will dump to the screen these arrays in a readable way. To get around your problem, do something like: <?php if(isset($_REQUEST['username']) && $_REQUEST['username'] == "rotten" && isset($_REQUEST['password']) && $_REQUEST['password'] == "1212"){ $_SESSION['username'] = "rotten"; $_SESSION['password'] = "1212"; header("Location: home.php ".$_SESSION['pageredirect']); } ?> The isset function checks to see if the array entry is there before checking the value. Ken Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1206502 Share on other sites More sharing options...
rotten69 Posted April 28, 2011 Author Share Posted April 28, 2011 OK. What I'm trying to do is that to check if the entered username and password match the ones are specified then redirect to the home page. Otherwise, stay on the same page displaying a little message saying "You've encountered an error.." This is my initial code here <?php if($_REQUEST['username'] == "rotten" && $_REQUEST['password'] == "1212"){ $_SESSION['username'] = "rotten"; $_SESSION['password'] = "1212"; header("Location: home.php ".$_SESSION['pageredirect']); // With this line, Would that be Okay to just use Header("Location: home.php" without the .$_SESSION pageredirect?? }else{ $_SESSION['displayerror'] = "0"; // I don't understand what this does.. Why is it ZERO? ?? header("Location: page3.php "); } ?> And also, I have got a question.. Is it possible to make a simple functional shopping cart without using my SQL? Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1207349 Share on other sites More sharing options...
rotten69 Posted April 29, 2011 Author Share Posted April 29, 2011 Any help please???? I'm really desparate for some help at the moment Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1207989 Share on other sites More sharing options...
Muddy_Funster Posted April 29, 2011 Share Posted April 29, 2011 Are you passing your variables from a form or through the URL? Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1208047 Share on other sites More sharing options...
rotten69 Posted April 30, 2011 Author Share Posted April 30, 2011 Getting the username and password information from a form.. Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1208553 Share on other sites More sharing options...
Muddy_Funster Posted May 2, 2011 Share Posted May 2, 2011 Change all $_REQUEST variables to $_POST and make sure that the form method is also post. Quote Link to comment https://forums.phpfreaks.com/topic/234757-i-have-a-few-errors-with-my-php-coding/#findComment-1209344 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.