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

    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0

    Question Help with searching a sql database


    Ok, Maybe one of you guys can give me a hand, I Am trying to query a database in my PHP site to search for an authentication code that is in its own table. Before I started messing around with having the validation code, I had the code adding the users to the db working just fine. Now that I have the Validation code in there, It says it is authenticated and failes the update on the database for the useres, no matter what number You put in. I've scowered the net and talked to a couple of friends, I can't figure out what I am doing wrong, My code is attached, Thankks in advance.

    $dbconn = @mysqli_connect(localhost, admin, admin4588,admin);
    if (!$dbconn) {
    echo "<p> The user Database is temporarily unavailiable, if this problem continues, please contact your systems administrator, or development managment team</p>";
    }
    elseif ($dbconn) {
    $sqlstr = ('SELECT * FROM auth WHERE code= ' .$auth);
    if($authresult = @mysqli_query($dbconn,$sqlstr)){
    echo "Authentication Complete";
    }
    else{
    die("Unable to find that authentication code, please retrieve a valid code from your Supervisor or your Development Managment Team");
    }

    }

    if ($authresult) {
    $sqlstring = 'INSERT INTO employees(fname, lname, email, phone, auth, password) VALUES("'.$fname.'","'.$lname.'","'.$email.'","'.$phone.'", "'.$auth.'" "'.$pass.'")';
    if($result = @mysqli_query($dbconn,$sqlstring)) {
    echo "<p> You have successfully created a user, please login to monitor your website </p>";
    }
    else {
    die("<p> Unable to process your request, please contact your network administrator");
    }
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,502
    Rep Power
    594
    1) Please enclose your code in PHP tags. See the sticky at the top of this forum that says READ THIS BEFORE POSTING.
    2) Get rid of all the error suppression ('@') and try again. If an error is causing the problem, you will never know with your code.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0
    There isn't any errors. I removed the error surpression and yeilding no good information
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    If PHP isn't throwing errors, maybe MySQL is. you're not checking the status of any of these queries and you don't print the error messages from the database.

    You also have no security on this page whatsoever and your variables come from nowhere, so it's difficult for us to help.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0
    <?php
    ini_set('display_errors', 'On');

    $fname = $_REQUEST['fname'];
    $lname = $_REQUEST['lname'];
    $email = $_REQUEST['email'];
    $phone = $_REQUEST['phone'];
    $auth = $_REQUEST['auth'];
    $pass = $_REQUEST['pass'];

    echo "<html>";
    echo "<head>";
    echo "<title> Add User </title>";
    echo "</head>";
    echo "<body>";

    //database connection strings
    $dbconn = @mysqli_connect(localhost, admin, admin4588,admin);
    if (!$dbconn) {
    echo "<p> The user Database is temporarily unavailiable, if this problem continues, please contact your systems administrator, or development managment team</p>";
    }
    elseif ($dbconn) {
    $sqlstr = "SELECT code FROM auth WHERE code =" .$auth;
    if($authresult = mysqli_query($dbconn,$sqlstr)){
    echo "Authentication Complete";
    }
    else{
    die("Unable to find that authentication code, please retrieve a valid code from your Supervisor or your Development Managment Team");
    }

    }

    if ($authresult) {
    $sqlstring = 'INSERT INTO employees(fname, lname, email, phone, auth, password) VALUES("'.$fname.'","'.$lname.'","'.$email.'","'.$phone.'", "'.$auth.'" "'.$pass.'")';
    if($result = mysqli_query($dbconn,$sqlstring)) {
    echo "<p> You have successfully created a user, please login to monitor your website </p>";
    }
    else {
    die("<p> Unable to process your request, please contact your network administrator");
    }
    }


    //verify the authtication code


    echo "</body>";
    echo "</html>";

    ?>
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,502
    Rep Power
    594
    Again, enclose your code in PHP tags. It is easier to read with the proper formatter.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    There are two different stickies telling you how to format your code. At least attempt it. You're asking a group of experts to help you for free, why would you not make it as easy for them as you possibly can?

    Also, you did absolutely nothing to this code aside from copy and paste MORE of it. I asked you to print the mysql errors and...you didn't. You just did what you already had, plus the 20 lines before it.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,998
    Rep Power
    375
    basic debugging techniques:

    1. echo out your query on the page
    2. try this in mysql to see what happens

    this will eliminate MySQL or PHP so you know which one has the problem
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    6
    Rep Power
    0
    1. I don't see this 'stickies' gimmick
    2. I figured it out on my own while you guys were stuck on stupid with this formatting issue. Your full of yourselves, if you have a problem reading 20 lines of code, get glasses.

    Thank you, and have a wonderful day.

    @paulh1983 Thanks for the tips man, appreciate ya. take care.

    Comments on this post

    • ManiacDan disagrees : You win the d-bag of the day award. Don't come back.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,998
    Rep Power
    375
    Originally Posted by 870magnum
    1. I don't see this 'stickies' gimmick
    2. I figured it out on my own while you guys were stuck on stupid with this formatting issue. Your full of yourselves, if you have a problem reading 20 lines of code, get glasses.

    Thank you, and have a wonderful day.

    @paulh1983 Thanks for the tips man, appreciate ya. take care.
    i guess we wont be seeing you in a while BUT if you see this,

    formatting the code is simple (just wrap your code around [php ] and [/ php] tags and it HELPS us visualise the code more easily, it also helps with ERROR checking i.e. if you miss a ' or ", the colour of the text will change...

    it is 100% more easier to read a formatted code than a non formatted one..
  20. #11
  21. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    1. I don't see this 'stickies' gimmick
    It's in the new user guide, visible in my signature as "HEY YOU! READ THE NEW USER GUIDE!" It's also the first post in the forum, the one that says "READ THIS BEFORE POSTING."

    Closing this thread as OP is just going to keep making a fool of himself.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo