p.diddle Posted March 23, 2008 Share Posted March 23, 2008 Hi. I'm new to php and mysql. I appreciate any help getting this result into a variable... I wrote the INSERT code on another page, and it works fine. I can see it work in phpMyAdmin. Now that I'm able to create an account for someone to then login, why can't I get that result back out? I know it's probably something simple, but I can't find a tutorial that addresses mysql_result() clearly. By clearly, I mean break it down like you're talking to a 'tarded third grader. Once I can get these results to display by echoing them out on the page, I can go back to trying to compare them. <?php session_start(); include 'config.php'; include 'opendb.php'; $user = $_POST['user']; $pass = $_POST['pass']; $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $getuser =("SELECT user FROM users WHERE user=\'$user\'"); $getpass =("SELECT pass FROM users WHERE pass=\'$pass\'"); if (!$getuser) { die('Could not query getuser:' . mysql_error()); } if (!$getpass) { die('Could not query getpass:' . mysql_error()); } //I think my problem is here I tried $user_result = mysql_result($getuser, 0); //which should return the first record, right? It didn't work either... //I have also tried several variations of these //none of which have worked... $user_result = mysql_result($getuser); $pass_result = mysql_result($getpass); if (!user_result) { die('No user result'); }//if this does not stop it... if (!pass_result) { die('No pass result'); }//and this does not stop it... echo $user_result; echo $pass_result; //why don't these echo out? include 'closedb.php'; ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted March 24, 2008 Share Posted March 24, 2008 You didn't submit a query. <?php $getuser = "SELECT user FROM users WHERE user='$user' AND pass = '$pass' "; // define the query $result = mysql_query ($getuser) or die (mysql_error()); // submit the query and get results if (mysql_num_rows($result) > 0) // check if any rows found { $user_result = mysql_result($result, 0, 0); // get value in the 1st col from the returned row } ?> Quote Link to comment Share on other sites More sharing options...
Edgewalker81 Posted March 25, 2008 Share Posted March 25, 2008 You never actually performed your query. At some point you will have to do something like $result_set=mysql_query("SELECT user FROM users WHERE user=\'$user\'"); Then get the information you're trying to test for from the result set. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 25, 2008 Share Posted March 25, 2008 Seems to be an echo in here ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.