rdkd1970 Posted May 6, 2011 Share Posted May 6, 2011 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. 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> Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/ Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 session_start() needs to be the very first thing on your page. Move it about session_id() and see what happens.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211504 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 I get the same message. Could it be my form. I see it is downloaded to my phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211508 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211512 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 I pasted this over the one I have and it just states in the codes there is a syntax error on that line. Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211515 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211518 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 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, Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211526 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 you should have done $id = $_SESSION['id']; Then put $id in the query.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211528 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 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, Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211536 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211541 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 Same result with error message. :'( Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211553 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 Please post your whole php file so I can look through it. Also, be sure to post them between the php tags, by doing: [ p h p ] //your code goes here [ / p h p ] (without any of the spaces) Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211554 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211555 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211561 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 I had the id in my db. I will try fix this to your suggestions and get back to you. Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211568 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211576 Share on other sites More sharing options...
denno020 Posted May 6, 2011 Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211582 Share on other sites More sharing options...
rdkd1970 Posted May 6, 2011 Author Share Posted May 6, 2011 I am getting the same error message with the row=results. Quote Link to comment https://forums.phpfreaks.com/topic/235709-fixing-error-message-for-session-id/#findComment-1211614 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.