+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: passing variable's value from php to others

  1. #1
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Question passing variable's value from php to others

    Hello all. I've a problem in php.

    On a php page, I get the user's informations (user, password, etc...). On another php page, the user can change his password or his profile, but I don't want have to ask him again his user name.

    I've tried with session_start(); on the top of the first page, and then $_SESSION['userid']=user_value; but when I retrieve the $_SESSION value in the next php page, there is nothing !

    How do I do that ?

    1st PHP:

    <?php
    session_start();
    ?>
    ...
    <link rel=stylesheet href="the.css" type="text/css">
    </head>
    <body>
    <?php
    $con = mysql_connect("localhost", "ident_name", "ident_pw");
    $db = "db_ayantdroit";
    if (!$con) {die('Connection impossible : ' . mysql_error());}
    mysql_select_db($db, $con);
    $ut = $_POST['utilisateur'];
    $pa = $_POST['upass'];
    $sql = "SELECT * FROM ayant_droit WHERE utilisateur = '" . $ut . "'";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) > 0) { // l'utilisateur existe dans la base
    while($row = mysql_fetch_array($result)) {
    if ($row['upass'] == $pa) { // password valide, on charge le menu correspondant au niveau de service
    $_SESSION['util']=$ut;
    ...


    2nd PHP :

    <html><head><title>Gestion du mot de passe</title>
    <link rel=stylesheet href="the.css" type="text/css">
    </head>
    <body>

    <div class="flot"><center>
    <form action="thePass.php" method="post">
    Mot de Passe actuel :<br /><input type="password" name="upass" /><br />
    Nouveau Mot de Passe :<br /><input type="password" name="nupass1" /><br />
    V&eacute;rification du Nouveau Mot de Passe :<br /><input type="password" name="nupass2" /><br />
    <input type="submit" name="submit" />
    </form></center>
    </div>
    <?php
    $ut=$_SESSION['util'];
    echo 'début du php de gesPass.php<br />';
    echo "nom d'utilisateur = /".$_POST['utilisateur']."/<br />";
    echo 'suite du php de gesPass.php';
    ...


    and this is the result of the echoes :

    début du php de gesPass.php
    nom d'utilisateur = //
    suite du php de gesPass.php

    Thanks for your help.

  2. #2
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: passing variable's value from php to others

    Your problem is around here :
    PHP Code:
    $ut=$_SESSION['util'];
    echo 
    'début du php de gesPass.php<br />';
    echo 
    "nom d'utilisateur = /".$_POST['utilisateur']."/<br />";
    echo 
    'suite du php de gesPass.php';
    ... 
    It should be more like this :
    PHP Code:
    $ut=@$_SESSION['util'];
    echo 
    'début du php de gesPass.php<br />';
    echo 
    "nom d'utilisateur = /".$_SESSION['util']."/<br />";
    echo 
    'suite du php de gesPass.php';
    ... 
    better yet do this :
    PHP Code:
    if($ut=$_SESSION['util']) {
    echo 
    'début du php de gesPass.php<br />';
    echo 
    "nom d'utilisateur = /".$ut."/<br />";
    echo 
    'suite du php de gesPass.php';
    } else {
    ... 
    // maybe return a error code, not sure what error checking you got going ?
    }
    ... 
    Last edited by DefecTalisman; 10-07-2009 at 09:17 AM. Reason: added error supression on $_SESSION['util']

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



  3. #3
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: passing variable's value from php to others

    @fomalhaut: Use the [ PHP] [ /PHP], [ CODE] [ /CODE] or [ HTML] [ /HTML] (without the space) when you post code on the forums. It's easier to read, understand and looks better.

    Make sure that you added session_start(); to the beginning of both files (very first line)
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  4. #4
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: passing variable's value from php to others

    I'm not really following how the 2 pages are connected...

    you're trying to call $_POST['utilisateur'], but you're not showing how.


    if you could, try posting the whole script and not just snipets, cause it could be something that you wouldn't even think it was ;)


    ps, remember [ php ] and [ /php ]

  5. #5
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: passing variable's value from php to others

    For those using [ php ] ... [ /php ], try [noparse][php] ... [/php][/noparse] ;)

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



  6. #6
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: passing variable's value from php to others

    Quote Originally Posted by DefecTalisman View Post
    For those using [ php ] ... [ /php ], try [noparse][php] ... [/php][/noparse] ;)
    I didn't know about the [noparse] tag, but it seems that the tag is working so well that even the noparse is not parse! :laugh:

    On the other side, the full page code will be more helpful in determining errors.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  7. #7
    a94060 is offline x10Hosting Member a94060 is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    16

    Re: passing variable's value from php to others

    Make sure both files are in the same directoy. I ran into this problem. If its a syntax error, sorry

  8. #8
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: passing variable's value from php to others

    Quote Originally Posted by xav0989 View Post
    I didn't know about the [ noparse] tag, but it seems that the tag is working so well that even the noparse is not parse! :laugh: .
    Thats because I used the noparse tag within itself
    Edit:
    Try this link -> http://forums.x10hosting.com/misc.php?do=bbcode#thread The ones towards the end are custome to x10
    Last edited by DefecTalisman; 10-08-2009 at 01:49 AM. Reason: Automerged Doublepost

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



  9. #9
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: passing variable's value from php to others

    Thanks for the link! Can I close threads?

    formalhaut, make sure that each page starts with:
    PHP Code:
    <?php
    session_start
    ();
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  10. #10
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: passing variable's value from php to others

    I think you can because he replied to me when he gave +rep

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. My 2cents on Ruby vs PHP.
    By jwillia in forum Programming Help
    Replies: 0
    Last Post: 03-15-2008, 11:18 PM
  4. PHP Easter Eggs
    By dragoneye_xp in forum Off Topic
    Replies: 3
    Last Post: 06-14-2006, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers