Jump to content

Can not get results of query into a variable


p.diddle

Recommended Posts

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';
?>

Link to comment
Share on other sites

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
}    
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.