#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    The script on the preceding page set a cookie containing a $username and $password variable.

    The following script will check to see if the cookie is present and //do some stuff// if $isset(username).

    The problem is mysql is returning an error stating:

    Unknown column 'mike2' in 'where clause'

    'mike2' is a test username.

    Why is the query interpreting the column in the where clause as a variable?

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    if (isset($username)) {
    require ("connect.inc.php3");
    $namecheck = mysql_query("select * FROM users WHERE username = $username",$db);

    if (!$namecheck) {
    print mysql_error();
    }

    $myrow = mysql_fetch_array($namecheck);
    // do some stuff
    [/code]

    [This message has been edited by mstembri (edited October 25, 2000).]
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0
    Looks good but just to seperate it some more you my want to do this:
    Note: make sure the conect.inc.php3 has a mysql_select_db($db); statement in it.


    if (isset($username)) {
    require ("connect.inc.php3");
    $sql = "SELECT * FROM users WHERE username='$un'";
    $namecheck = mysql_query($sql);
    if (!$namecheck) {
    print mysql_error();
    }

    $myrow = mysql_fetch_array($namecheck);
    // do some stuff
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    Haven't you only changed the style of the code?

    The flow remains the same, therefore will produce the same result (right?)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Don't forget single quotes around your variable
    $namecheck = mysql_query("select * FROM users WHERE username = '$username'",$db);
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    yep, that took care of the error - but the script still isn't working.

    Even though the variable $username is defined, the query isn't finding anything when it is executed.

    When I query at the command line the appropriate data is returned. I'm starting to pull my hair out on this - the syntax looks perfect but still no results.

    Here's the full script, with updated query:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    require ("connect.inc.php3");
    $namecheck = mysql_query("SELECT * FROM users WHERE username = '$username'",$db);
    if (!$namecheck) {
    print mysql_error();
    die;
    }

    $myrow = mysql_fetch_array($namecheck);

    $namedisplay = $myrow['$namedisplay'];
    $nick = $myrow['$nick'];
    $namefirst = $myrow['$namefirst'];
    $namelast = $myrow['$namelast'];

    if ($namedisplay == '1'){
    echo "Welcome, $username";
    } else if ($namedisplay == '2') {
    echo "Welcome, $nick";
    } else if ($namedisplay == '3') {
    echo "Welcome, $namefirst $namelast";
    } else {
    echo "&nbsp;";
    }

    [/code]

  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    remove the $ from in front of the field names in your array indices.

    e.g.:

    $namedisplay = $myrow['$namedisplay'];

    should be:

    $namedisplay = $myrow[namedisplay];

    (you don't need the single quotes either).
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    Much appreciated, rod k. And thanks for the tip on single quotes.

    - Mike

Similar Threads

  1. A variable $_POST variable?
    By CLuver in forum PHP Development
    Replies: 0
    Last Post: February 11th, 2004, 01:55 AM
  2. Table variable column widths
    By coredumped in forum HTML Programming
    Replies: 2
    Last Post: February 2nd, 2004, 11:31 PM
  3. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 01:26 PM
  4. Replies: 1
    Last Post: January 15th, 2004, 09:00 AM
  5. Replies: 0
    Last Post: January 3rd, 2004, 09:33 AM

IMN logo majestic logo threadwatch logo seochat tools logo