SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select statement not keeping the variable

    I have a select function that looks like this:

    PHP Code:
    <? 
    $db_host 
    "1234";
    $db_user "1234";
    $db_pwd "1234";
    $db_name "1234"

    mysql_connect($db_host$db_user$db_pwd); 

    mysql_select_db($db_name); 

    $sql "SELECT username, firstname, lastname FROM authorize "
    $result mysql_query($sql); 
    ?> 
    <form action="mod2.php" method="post"> 
    <select name="username"> 
    <? 
    while($row=mysql_fetch_assoc($result)) 

    $username $row['username']; 
    $name $row['firstname']." ".$row['lastname']; 

    echo 
    "<option value=\"$username\">$name</option>"

    ?> 
    </select> 
    <input type="submit" value="Submit" name="submit" /> 
    </form>
    It goes into a page that looks like this:

    PHP Code:
     <?php
    $userid 
    $_POST['username'];
    ?>

    <?php
    $con 
    mysql_connect("1234","1234","1234");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db('1234''$con');

    $result mysql_query("SELECT firstname FROM authorize
    WHERE username='
    $userid'");

    while(
    $row mysql_fetch_array($result))
      {
      echo 
    $row['firstname'];
      }

    ?>
    It shows the userid when you echo it, but when you use it in the mysql statement it completely bombs out the entire page. What is wrong?

  2. #2
    SitePoint Member nabil_kadimi's Avatar
    Join Date
    Nov 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result = mysql_query("SELECT firstname FROM authorize
    WHERE username='$userid'
    LIMIT 1
    ");

    ...

    while($row = mysql_fetch_assoc($result))
    {
    echo $row['firstname'];
    }

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still showing a blank page after making the changes above.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Do you remember from the last thread about doing debugging through the script?
    PHP Code:
    $userid $_POST['username'];

    // debug variable, does it show?
    echo $userid;

    $sql "SELECT firstname FROM authorize 
    WHERE username='
    $userid'";

    echo 
    $sql// does it look right?

    $result mysql_query($sql) or die(mysql_error()); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem was here

    PHP Code:
    mysql_select_db('1234''$con'); 
    it should have been

    PHP Code:
    mysql_select_db('1234'$con); 

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •