PDA

View Full Version : database not responding?



Therian
October 10th, 2006, 01:33 AM
Hi guys...new to the forum, and also pretty new to mysql and php (not new to AS or flash though)

I'm having a problem with the login tutorial from this site. It seems as though mysql isn't taking the queries that php sends to it. php is able to connect to mysql though (I have confirmed this through running a test php file to check connect)

here's the php


<?
$user=$_POST['user'];
$pass=$_POST['pass'];

if ($user && $pass){
mysql_pconnect("mysql.substratemedia.com","dmcdowell","xxxxxx") or die ("didn't connect to mysql");
mysql_select_db("dmcdowell") or die ("no database");
//make query

$query = "SELECT * FROM `auth` WHERE `username` = '$user' AND `userpassword` = '$pass'";

$result = mysql_query( $query ) or die ("didn't connect to mysql");

$num = mysql_num_rows( $result );
if ($num == 1){
print "checklog=1&status=you're in";
} else {
print "checklog=2&status=failure";
}
}
?>

I do not think the problem lies in flash, as the actionscript is passing the user and pass variables to the php script (I have confirmed this by printing the $pass and $user variables in the dynamic status box in flash)

here's the address of the swf

www.substratemedia.com/phptest (http://www.substratemedia.com/phptest)

I have created a row in phpmyadmin with the values of (0001,tester,entrykey)
even though these records exist in the database (and they display when I run the equivilent to $query in phpmyadmin) mysql_num_rows is always coming up with a value of 0. even if tester and entrykey are supplied as a username and password in flash.

what the hell is going on?

bwh2
October 10th, 2006, 10:32 AM
try this for your connection:

$link = mysql_connect('mysql.substratemedia.com','dmcdowel l','xxxxxx') or die ('did not connect to mysql');
mysql_select_db('dmcdowell', $link) or die ('no database');if that doesn't work, try this:


$link = mysql_connect('localhost','dmcdowell','xxxxxx') or die ('did not connect to mysql');
mysql_select_db('dmcdowell', $link) or die ('no database');

Therian
October 10th, 2006, 11:47 PM
still responding the same way...

when I set the dynamic text box (var: status)to equal $query the output I received was

SELECT * FROM `auth` WHERE `username` = 'tester
' AND `userpassword` = 'entrykey
'

(when typing tester as the user and entrykey as the pass in the swf)

does this indicate that the php script and flash are working correctly?

Therian
October 10th, 2006, 11:57 PM
and if if pass the $result variable to the status variable I get the result of

"Resource id #2"

what does that mean?

Therian
October 12th, 2006, 11:34 AM
ok this is VERY strange

When I set

$user = "tester"
$pass = "entrykey"

everything works fine

so the mysql/php side seems to be working fine

but flash also seems to be communicating well

when I set status equal to $query I get

SELECT * FROM `auth` WHERE `username` = 'tester' AND `userpassword` = 'entrykey'

EXACTLY the same response as if I artificially set $user and $pass like I did above

there's no reason it shouldn't be working

but it's not

bwh2
October 12th, 2006, 12:07 PM
hmm...

the "Resource id #2" just indicates an array. so you can't echo it as normal, you need to use [d-php]print_r[/d-php] or just loop through it.

what happens when you access the php page directly (not via flash):


<?
/* temp disable post vars */
//$user=$_POST['user'];
//$pass=$_POST['pass'];

$user = 'tester';
$pass = 'entrykey';

if ($user && $pass){
mysql_pconnect("mysql.substratemedia.com","dmcdowell","xxxxxx") or die ("didn't connect to mysql");
mysql_select_db("dmcdowell") or die ("no database");
//make query

$query = "SELECT * FROM `auth` WHERE `username` = '$user' AND `userpassword` = '$pass'";

$result = mysql_query( $query ) or die ("didn't connect to mysql");

$num = mysql_num_rows( $result );
if ($num == 1){
print "checklog=1&status=you're in";
} else {
print "checklog=2&status=failure";
}
}
?>
btw, that login message is hilarious.

Therian
October 12th, 2006, 12:40 PM
haha yeah...I've been watching too much dave chapelle recently.

anyway I fixed the problem!

I told php to email me the var $query and through doing so it turned out that flash was throwing out the user and pass vars at a font size of around 28 (as well as some other curious formatting).

I appended the the top of the script as follows:

$user=trim(strip_tags($_REQUEST['user']));
$pass=trim(strip_tags($_REQUEST['pass']));

and all is well in the world now.

thanks for the assistance, I appreciate your time

bwh2
October 12th, 2006, 12:47 PM
no problem, glad to hear you got it worked out.