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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.