NYCPHP Meetup

[nycphp-talk] MySQL Monitor V PHP & MySQL

Rick Retzko rick at click-rick.net
Sat Sep 22 10:57:20 EDT 2007


Two errors that I can find:

1. You're missing the 'WHERE' key word in your SQL: $sql = "SELECT
access_code
        FROM authorised_users
        user_id = '$userid' AND
        user_password = '$password' AND
        account = '$account'"; 
	should be:
$sql = "SELECT access_code
        FROM authorised_users
        WHERE user_id = '$userid' AND
        user_password = '$password' AND
        account = '$account'";

2. Your mysql_num_rows is misspelled (Yours is mysql_numrows) making the
subsequent 'if' statement FALSE.

Hope this helps 

 
Rick

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of PaulCheung
Sent: Friday, September 21, 2007 3:47 PM
To: talk at lists.nyphp.org
Subject: [nycphp-talk] MySQL Monitor V PHP & MySQL 

 I have researched, checked and tried everything I can think of and still
cannot get it to work.

when using MySQL monitor  the following works
=================================

SELECT access_code FROM authorised_users WHEN user_id  =  'Nancy' AND
user_password = 'qwerty' AND account = '48572998';

Access_code is displayed = 11966552

When using PHP & MySQL ($userid='Nancy',  $user_password='qwerty',
$account='48572998')
====================
<?PHP session_start(); ob_start(); PHP?>
<HTML><HEAD><TITLE>auth</TITLE></HEAD>
<FORM action="X.php" id="primary" method="post"> <BODY> <?PHP
$userid   = $_POST['user'];
$password = $_POST['passcode'];
$account  = $_POST['account'];
$self     = $_SERVER['PHP_SELF'];
$referer  = $_SERVER['HTTP_REFERER'];
$access_code = $access_code - $access_code;

/* FOR TEST ONLY */
echo ("user id = " . $userid . "<br>");
echo ("password = " . $password .  "<br>"); echo ("account = " . $account .
"<br>"); echo ("self = " . $self . "<br>");

/* VALIDATE FOR BLANK INPUT FIELD */
if( ( !$userid ) or ( !$password ) or (!$account) ) { header(
"Location:$referer" ); exit(); } /*CONNECT TO MYSQL  */
$conn=@mysql_connect( "localhost", "paul", "enter" )
   or die( "Could not connect" );
/* CONNECT TO DATABASE */
$rs = @mysql_select_db( "test_db", $conn )
  or die( "Could not select database" );

$rs = @mysql_select_db( "test_db", $conn ) or die( "Could not select
database" );

$sql = "SELECT access_code
        FROM authorised_users
        user_id = '$userid' AND
        user_password = '$password' AND
        account = '$account'";

$rs = mysql_query( $sql, $conn )  or die( "Could not execute query" );

$num = mysql_numrows( $rs );

if( $num != 0 )
{ $access_code = access_code;
   echo ("testcheckpoint - Welcome - your log-in succeeded!" . "<br>");
   echo ("testcheckpoint - accesscode = " . access_code . "<BR>");
   echo ('testcheckpoint - $accesscode = ' . $access_code . "<BR>"); } else
{ echo (" test checkpoint statement 55 " . "<br>");
   header( "Location:$referer" );
   exit(); }

===========================================
this is what is returned from the test

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
Welcome - your log-in succeeded!
testcheckpoint - accesscode = access_code testcheckpoint - $accesscode =
access_code

I am trying to get the Access_code and cannot see what I am doing wrong

P






_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php




More information about the talk mailing list