Jump to content

I have a few errors with my php coding


rotten69

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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