Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    Hi,
    It's been way to long since I've done php and I've been called on to dust off my brain and make a website (with high usage of php code). Sadly, I've forgot a lot of what I once I knew.

    What I need to do Is have a large table of people and ID numbers. I need them to enter in their name and ID number and have it checked against a database. I got the form but I just can't get my sad attempt for code right. How would be the best way of doing this???
    Thanks,
    Mikael

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Not sure fully what you mean.

    The user enters their name and their ID number, and this is checked against names and ID numbers in a table?

    It would be more user friendly just for the user to enter their name.

    However, something like this..

    PHP Code:
    // forms submitted, get variables
    $fullname $_POST['fullname']; // assuming fullname is the form element name/id
    $id $_POST['id'];

    $query "SELECT username, id FROM table WHERE username = '$fullname' AND id = '$id'";
    $res mysql_query($query) or die("Error in SELECT - " mysql_error(); 

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Remember to escape any user data that goes into a query: [phpfunction]mysql_real_escape_string[/phpfunction].
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    thanks a lot. It is for voting for student council at my school. I need their ID also because it needs to be verified against their name so no one can (easily) cheat.
    Thanks again,
    mikael

    P.S. I cant get the mysql_real_escape_string in the right place in this line.
    Code:
    $res = mysql_query($query) or die("Error in SELECT - " . mysql_error();
    Sorry, its been at least a year since I've done any php.

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Use the function after you assign the value to a variable. Try this.
    PHP Code:
    $fullname $_POST['fullname']; // assuming fullname is the form element name/id
    $id $_POST['id'];
    $fullname mysql_real_escape_string($fullname);
    $id mysql_real_escape_string($id);
    // rest of script as normal 

  7. #6
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    Hmmm, I ain't getting something right on this line:
    Code:
    $res = mysql_query($query) or die("Error in SELECT - " . mysql_error());
    It doesn't verify and when I echo "$res", I get "Resource id #3" no matter what I put into the boxes. Any ideas???

  8. #7
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    You need to get a row from the result a la [phpfunction]mysql_fetch_assoc[/phpfunction]. All mysql_query does is execute a query and give you a handle to the result, not the actual result.

    And if you're just starting out with database, please for the love of whatever deity you may or may not believe in, use PostgreSQL instead and not piece of *** MySQL.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  9. #8
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    to echo the result you would need to use the mysql_fetch_array function like this.

    PHP Code:
    // forms submitted, get variables 
    $fullname $_POST['fullname']; // assuming fullname is the form element name/id 
    $id $_POST['id']; 

    $query "SELECT username, id FROM table WHERE username = '$fullname' AND id = '$id'"
    $res mysql_query($query) or die("Error in SELECT - " mysql_error(); 

    $row mysql_fetch_array($res);
    echo 
    $row
    that will echo correct result
    Regards Phil,



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:25 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com