Question Locked

MySQL and MySQL SELECT

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

does anybody know why this works in MySQL monitor and not with PHP& MySQL??

mysql> use test_db;

Database changed

mysql> select * from authorised_users;
+--------------+------------------+--------------+---------------+----------+-------------+
| user_name | company | user_id | user_password | account | access_code |
+--------------+------------------+--------------+---------------+----------+-------------+
| | | Nancy | qwerty | 48572998 | 11966552 |
+--------------+------------------+--------------+---------------+----------+-------------+

mysql> use test_db;
Database changed
mysql> desc authorised_users;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| user_name | varchar(35) | YES | | NULL | |
| company | varchar(50) | YES | | NULL | |
| user_id | varchar(16) | NO | PRI | | |
| user_password | varchar(16) | NO | PRI | |
| account | varchar(8) | NO | PRI | | |
| access_code | varchar(8) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
6 rows in set (0.58 sec)

mysql> select access_code from authorised_users where user_id = 'Nancy' and user_password = 'qwerty' and account = '48572998';
+-------------+
| access_code |
+-------------+
| 11966552 |
+-------------+
1 row in set (0.19 sec)

mysql>
===============================================
and this (using PHP & MySQL) does not work

/* EXECUTE DATABASE SEARCH */
$sql = "SELECT access_code into $access_code
FROM authorised_users
WHERE user_id = '$userid'
AND user_password = '$password'
AND account = '$account'";
/* TESTING CHECKPOINT */
echo ("conn = " . $conn . "
");
echo ("sql = " . $sql . "
");
echo ("access = " . $access_code . "
");

#execute the query
$rs = mysql_query( $sql, $conn )
or die( "Could not execute query" );
#get number of rows that match username and password
$num = mysql_numrows( $rs );

#if there is a match the log-in is authenticated

if( $num != 0 )
{
echo ( "Welcome - your log-in succeeded!" . "
");
//$access_code = access_code;
echo ("testcheckpoint - accesscode = " . access_code . "
");

echo ('testcheckpoint - $accesscode = ' . $access_code . "
");
}
else
{
/* INVALID USER - RETURN TO OUTERGUARD */

echo (" test checkpoint statement 55 " . "
");
header( "Location:$referer" ); exit();
}
========================================
This is what was returned ..............

user id = Nancy
password = qwerty
account = 48572998
self = /tp_orth.php
conn = Resource id #2
sql = SELECT access_code FROM authorised_users WHERE user_id = 'Nancy' AND user_password = 'qwerty' AND account = '48572998'

access = 0
Could not execute query

1 reply

This discussion is closed to new replies.