View Full Version : Mysql SELECT issue

03-11-2007, 04:44 PM
I'm creating a simple login-and-fetch-data site without much security or finesse. What I wan't is to type a string of numbers in one textbox and a password in a second textbox. When submit it will search a database for a record containing both values.

All I get is Resourse id #4 which indicates that I typed something wrong; Here is the code I use and a picture of phpmyadmin.

Picture of phpmyadmin and how my database looks

http://bloggliv.se/misc/a002s.jpg (http://bloggliv.se/misc/a002.jpg)

This is the login page

<div id="formcontainer">
<h3>Logga in här</h3>
<h4>Fyll i auktionsnr och lösenord</h4>
<form method="post" action="data.php">

<div class="clearfix">
<label>String of numbers: </label>
<input name="aukt" type="text" size="35" />
<div class="clearfix">
<input name="los" type="password" size="35" />

<div class="clearfix">
<input name="submit "type="submit" value="Logga in" />

This code gets the string of numbers and a password to check against a database.

$auktions_nr = $_POST['aukt']; // Get textbox value 1
$auktions_losen = $_POST['los']; // Get textbox value 2

print $auktions_nr; // I want to know what I get when debugging so I just print it for now
print $auktions_losen; // Same here

checkaukpwd($auktionsnr, $auktionslosen); // Function I use for checking textboxes

@mysql_connect("localhost","root","") // My host (Yeah I dont use password here)
or die("Hittade inte databasen.");

@mysql_select_db("tradera"); // The database I use

// This is where things gets weired, I get Resourse id #4 all the time
$query = "SELECT *
FROM varor
WHERE auktionsnr = '$auktions_nr'
AND losenord = '$auktions_losen'

$result = mysql_query($query);

if ($result && mysql_num_rows($result) > 0) // Checking for a record that exists with both requirements ($auktions_nr and $auktions_losen).
print "Felaktigt auktionsnr eller lösenord."; // If doesn't exist, just stop everything.
} else
print "Woho"; // Record found with both requirements. Continue.... (not completed).


03-11-2007, 06:05 PM
you're problem is that you are trying to use the resource of the result instead of the result itself.

after this block:

$result = mysql_query($query); you want to use mysql_fetch_row and step through your result and compare it to your database.

03-11-2007, 09:30 PM
Perhaps a quick example could be in place? Im not interested in getting everything done for me, I just need code to learn from.

03-11-2007, 10:35 PM
http://www.php.net/manual/en/function.mysql-fetch-assoc.php <-- Check the examples and comments.