Question:

Php sessions question?!?!?

by  |  earlier

0 LIKES UnLike

if i could understand sessions more.. my site would probably be finished.

but alright,

aside from my css, and the main look of the site, i'll just tell you what my php coding is for each site.. and maybe someone can help me with my problem..

/register.php

-------------------

<?php include("signup.php");?>

/signup.php

-------------------

this page has my table with the register fields [name, lastname, email, password, etc...]

the form action goes to signup_ac.php

/signup_ac.php

-----------------------

this page has all php coding that sends an activation link to the persons email, they click the activation link, the data gets sent from 'temp_members' table, in which is in the members database, and it gets sent to the 'registered_members' table.

so my register ordeal works.

now for the login.

/login.php

--------------

this is another table asking for the users email and password only.

the form action goes to login2.php

/login2.php

-----------------

<?php

include("config.php");

$tbl_name1="registered_members";

$match = "select id from $tbl_name1 where email = '".$_POST['email']."'

and password = '".$_POST['password']."';";

$qry = mysql_query($match)

or die ("Could not match data because ".mysql_error());

$num_rows = mysql_num_rows($qry);

if ($num_rows <= 0) {

echo "Sorry, there is no email $email with the specified password.<br>";

echo "<a href=login.php>Try again</a>";

exit;

} else {

$query = "SELECT * FROM $tbl_name1 WHERE name = '$name'";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

session_start();

$_SESSION['email'] = $row['email'];

$_SESSION['name'] = $row['name'];

include("index2.php");

}

?>

index2.php is basically the members area page for now, it will change in the future.

in the above, the following code was never there, but i recently added it to try it out.

$query = "SELECT * FROM $tbl_name1 WHERE name = '$name'";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

session_start();

$_SESSION['email'] = $row['email'];

$_SESSION['name'] = $row['name'];

/index2.php

------------------

Welcome: <?php include("logged.php") ;?>

/logged.php

------------------

<?php

session_start();

echo $_SESSION['name']

?>

so basically, when they log in.. it should go to index2.php instead of echoing "login succesfull... and index2.php including logged, and the session starting in login2.php, the session should stay and it should grab 'name' from the members database, and from the registered_members table.. and it should print "Welcome 'users name'"

right?

what am i doing wrong?

what should i fix on what page and what will work for a fact.

i've been trying to fix this for weeks now and i can't get around it.

please help!

thanks!

 Tags:

   Report

1 ANSWERS


  1. ----------------------------

    UPDATE

    That line doesn&#039;t look like it has any problems. What probably happened is that either you or I missed a semicolon, single quote, or double-quote in the preceeding instruction (where $match was defined).

    Usually when it gives you an error on a line that doesn&#039;t have a problem, it&#039;s the line or two before where it tells you that&#039;s at fault

    ----------------------------

    From what you gave me, I think the problem is one of two things:

    - You don&#039;t need a semicolon in your SQL queries, and

    - You&#039;re calling session_start() more than once.

    Without having access to your code, though, it could be a lot of things. If it doesn&#039;t end up being one of those two, I would set things up like this for debugging purposes,

    /login2.php

    -----------------

    &lt;?php

    // delete this when you&#039;re satisfied e-mail and password

    // are coming across okay

    die(serialize($_POST));

    include(&quot;config.php&quot;);

    ...

    // you don&#039;t need a closing semicolon, php does this for you

    /**

    WAS

    $match = &quot;select id from $tbl_name1 where email = &#039;&quot;.$_POST[&#039;email&#039;].&quot;&#039;

    and password = &#039;&quot;.$_POST[&#039;password&#039;].&quot;&#039;;&quot;;

    **/

    $match = &quot;select id from $tbl_name1 where email = &#039;&quot;.$_POST[&#039;email&#039;].&quot;&#039;

    and password = &#039;&quot;.$_POST[&#039;password&#039;].&quot;&#039;&quot;;

    ...

    // Delete this when satisfied you&#039;re querying properly

    while($row = mysql_fetch_assoc($qry)) print_r($row);

    die();

    $num_rows = mysql_num_rows($qry);

    ...

    } else {

    // delete this when you&#039;re satisfied it&#039;s going in when it&#039;s supposed to

    die(&#039;Found &#039; . $num_rows . &#039; records&#039;);

    ...

    // I usually like calling session_start() this way, in case I accidentally

    // called it somewhere else

    if( ! session_id() ) session_start();

    $_SESSION[&#039;email&#039;] = $row[&#039;email&#039;];

    $_SESSION[&#039;name&#039;] = $row[&#039;name&#039;];

    // delete this when you&#039;re satisfied the session looks like it should

    die(serialize($_SESSION));

    ...

    /index2.php

    ------------------

    &lt;?php /* same deal as before */ die(&#039;index2 loaded&#039;); ?&gt;

    Welcome: &lt;?php include(&quot;logged.php&quot;) ;?&gt;

    /logged.php

    ------------------

    &lt;?php

    // Looks like you ARE calling session_start twice after all

    /**

    WAS

    session_start();

    **/

    if( ! session_id() ) session_start();

    echo $_SESSION[&#039;name&#039;]

    ?&gt;

    Good luck

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.