Jump to content

fixing error message for session id


rdkd1970

Recommended Posts

I am so glad someone told me about putting in the error_reporting ALL because I was not sure why my id for members was not picking up on the next pages. Can someone let me know how I can fix this I thought it automatically picks it up and sets it to private pages for each member.

:o

Notice: Undefined index: id in /home/ebermy5/public_html/login.php on line 25

 

<?php

session_id();

session_start();

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Welcome</title>

</head>

 

<body>

<?php

/* Program: New_member.php

* Desc: Displays the new member welcome page. Greets

* member by name and gives a choice to enter

* restricted section or go back to main page.

*/

error_reporting(E_ALL);

ini_set("display_errors", 1);

$firstname = '';

 

include('Connections/connect_to_mysql.php');

$result = mysql_query("SELECT firstname FROM `Members` WHERE id='{$_SESSION['id']}'");

$row = mysql_fetch_array($result);

 

if ($firstname == ''){ //condition, is name equal to lower case firstname notice we use == and not =

echo "Welcome, $firstname";

} else { //so incase the condition is not as expected

echo "Sorry you are not $firstname";

}

 

?>

<p>Your new Member accounts lets you enter the members only section

of our web site. You'll find special discounts, a profile of matches,

live advise from experts, and much more.</p>

<p>Your new Member ID and password were emailed to you. Store them

carefully for future use.</p>

<div style="text-align: center">

<p style="margin-top: .5in; font-weight: bold">

Glad you could join us!</p>

<form action="profile.php" method="post">

<input type="submit"

value="Enter the Members Only Section">

</form>

<form action="index.php" method="post">

<input type="submit" value="Go to eBermylove Main Page">

</form>

</div>

</body>

</html>

 

Link to comment
Share on other sites

I'm not familiar with the use of the curly braces around $_SESSION['id'].. do you have a specific reason for this? This is the line that the error is appearing on, so I would try removing the curly braces, leave the line reading like this:

$result = mysql_query("SELECT firstname FROM `Members` WHERE id=$_SESSION['id']");

 

Denno

Link to comment
Share on other sites

What you could try doing is assigning $_SESSION['id'] to a variable and then using that variable in the where clause. I have a feeling there is issues when it comes to accessing the session variable directly in the where clause of SQL... I think I've heard of this before..

 

Denno

Link to comment
Share on other sites

Okay I tried it as follows

 

$_SESSION='id';

 

and in the $result = $query i put where $_SESSION='id'

 

it added to db and it does not show error message but it is not echoing the Welcome, firstname. It shows Welcome,

 

Link to comment
Share on other sites

I know it is something so easy that we are missing but me being new to this I would not have a clue. Here is my codes and then the message I got this time

 

error_reporting(E_ALL);

ini_set("display_errors", 1);

$firstname = '';

$id = $_SESSION['id'];

 

include('Connections/connect_to_mysql.php');

$result = mysql_query("SELECT firstname FROM `Members` WHERE $id=$_SESSION");

$row = mysql_fetch_array($result);

 

Notice: Undefined index: id in /home/ebermy5/public_html/login.php on line 23

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ebermy5/public_html/login.php on line 27

Welcome,

Link to comment
Share on other sites

This is how your SQL statement should read

SELECT firstname FROM `Members` WHERE database_id=$id

 

database_id will be the id inside your database, obviously.. So you're checking those values for the value contained inside the session id variable, which you have saved into it's very own variable called $id. the $ sign before the name indicates it's a php variable also.. In case you didn't know :).

 

Try that and let me know how you go.

 

Denno

Link to comment
Share on other sites

form

 

<?php

@include_once ("Connections/connect_to_mysql.php");

 

  $err='';

 

  if($_POST["submit"]){

 

    // Validate form data

 

    if($_POST["firstname"]=='') $err.='Please enter First Name<br>';

    if($_POST["email"]=='') $err.='Please enter Email<br>';

 

 

 

    if($err==''){

 

      // Check if there are duplicate entries in the 'contacts' table

 

      $results = mysql_query("SELECT id FROM `Members` WHERE firstname='".addslashes($_POST["firstname"])."' and Email='".addslashes($_POST["email"])."'");

      if($row = mysql_fetch_array($results)){

        $err.='Can not add duplicate entry<br>';

      }

      else{

 

        // adding new record to 'contacts' table

 

        mysql_query("INSERT INTO Members (firstname,lastname,country,Email)

                    values ('".addslashes($_POST["firstname"])."','".addslashes($_POST["lastname"])."','".addslashes($_POST["country"])."','".addslashes($_POST["email"])."')");

 

      // redirecting to success screen

  if($results){

        header("Location: login.php");

}else

die(mysql_error());

 

      }

    }

  }

 

?>

<html>

<head>

<title>Add New Contact</title>

</head>

 

<body>

 

<h2>Register with us</h2>

 

<?php echo $err==''?'':('<p style="color:red;">'.$err.'</p>') ?>

 

<form method="post" action="form.php">

 

<table border="0">

<tr>

<td valign="middle">First Name:</td>

<td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td>

</tr>

<tr>

<td valign="middle">Last Name:</td>

<td><input type="text" name="lastname" size="30" value="<?php echo htmlspecialchars($lastname) ?>"></td>

</tr>

<tr>

<td valign="middle">Country:</td>

<td><input type="text" name="country" size="30" value="<?php echo htmlspecialchars($country) ?>"></td>

</tr>

<tr>

<td valign="middle">Email:</td>

<td><input type="text" name="email" size="30" value="<?php echo htmlspecialchars($email) ?>"></td>

</tr>

</table><br>

 

<input type="submit" name="submit" value=" Submit! ">

 

</form>

 

</body>

</html>

 

Welcome page (login.php)

 

<?php

session_start();

session_id();

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Welcome</title>

</head>

 

<body>

<?php

/* Program: New_member.php

* Desc: Displays the new member welcome page. Greets

* member by name and gives a choice to enter

* restricted section or go back to main page.

*/

error_reporting(E_ALL);

ini_set("display_errors", 1);

$firstname = '';

$database_id = '';

 

include('Connections/connect_to_mysql.php');

$result = mysql_query("SELECT firstname FROM `Members` WHERE database_id=$id");

$row = mysql_fetch_array($result);

 

if ($firstname == ''){ //condition, is name equal to lower case firstname notice we use == and not =

echo "Welcome, $firstname";

} else { //so incase the condition is not as expected

echo "Sorry you are not $firstname";

}

 

?>

<p>Your new Member accounts lets you enter the members only section

of our web site. You'll find special discounts, a profile of matches,

live advise from experts, and much more.</p>

<p>Your new Member ID and password were emailed to you. Store them

carefully for future use.</p>

<div style="text-align: center">

<p style="margin-top: .5in; font-weight: bold">

Glad you could join us!</p>

<form action="profile.php" method="post">

<input type="submit"

value="Enter the Members Only Section">

</form>

<form action="index.php" method="post">

<input type="submit" value="Go to eBermylove Main Page">

</form>

</div>

</body>

</html>

 

Link to comment
Share on other sites

Ok... So when I put 'database_id', I was kinda hoping you'd get the drift of what I was suggesting, and change the name to match whatever it is in your database. What is the name of the id field in your database? This is what you need to put where I suggested 'database_id'..

 

You also didn't assign anything to the php variable $id... You need to have $id = $_SESSION['id']; somewhere before your query.. Put it just below where you've got $firstname = ' ';

 

Once you have made those changes, let me know how it works.

 

Denno

Link to comment
Share on other sites

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ebermy5/public_html/login.php on line 27

Welcome,

 

This is the corrections I made $id=''; and in the select firstname from members.... line so I think it is now the $row not getting the results or I did the result wrong.

 

error_reporting(E_ALL);

ini_set("display_errors", 1);

$firstname = '';

$id = '';

 

include('Connections/connect_to_mysql.php');

$result = mysql_query("SELECT firstname FROM `Members` WHERE firstname=$id");

$row = mysql_fetch_array($result);

Link to comment
Share on other sites

I just have to let you know that it's past 4am here, and I'm going to bed.. When I wake tomorrow, I will look at your problem some more and offer some more suggestions (of which I already have a few, but I want sleep). From the looks of it, its homework of some sort, so I'll let you continue to work on it and see if you can't fix it yourself. I would suggest youtube videos and Google.

 

Some things to think about: where does the information come from the user that is then used to query the database? (so where does the user put in their username and password?)

 

That's all for tonight. I should post back tomorrow at some point, if not then the day after..

 

Denno

Link to comment
Share on other sites

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.