Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Check if variable exisist in db

    Hello,

    i got some problem with my code there i wanna check if a variable exsist and if it does it should do a function and if not it should just send back an echo that the variable din't exisist.

    Code:
    $search = "SELECT code FROM pw WHERE code='".$code."'";
    $result = mysql_query($search) or die ('SQL Error: '. mysql_error());
    if (mysql_num_rows($result) > 0)
    {
     //Do the function
    }
    else
    {
     echo "Code was wrong";
    }
    i get error on the $search row and i don't know, the database is named "eric" the table is "pw" and the codes row name is "code" and the name on the $_POST code they send in on the form page is code also.

    //Zubat

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,300
    Thanks
    23
    Thanked 612 Times in 611 Posts
    You should give us the error.
    your 'looks' OK to me. Maybe your not connected to the DB. Don't know without the error message.

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    You should give us the error.
    your 'looks' OK to me. Maybe your not connected to the DB. Don't know without the error message.
    I get the error

    Code:
    Notice: Undefined variable: code in /home/eric/public_html/vip/check.php on line 11 Din kod var felaktig
    On the page when i send the nick and code from the form page.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,300
    Thanks
    23
    Thanked 612 Times in 611 Posts
    The error says "Undefined variable:" And the line
    $search = "SELECT code FROM pw WHERE code='".$code."'";
    has only one variable,
    $code
    . So I'm guessing the code prior to what you gave us is not getting $code equal to anything. Fast check would be to A) run an echo on the 'search' string
    Code:
    echo $code;die;
    just before the above 'search =' line or put
    Code:
    $code = 'put something here'
    just before the above 'search =' line.


  •  

    Posting Permissions

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