PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
corbo950
Forum Newbie
Posts: 13 Joined: Wed May 07, 2008 1:59 am
Post
by corbo950 » Wed May 07, 2008 2:03 am
I have a adobe AIR application and I wanted to add a login script to it. So this is what I came up with and I can't figure out why it wouldn't return anything(blank no errors). Help would be much appreciated.
Code: Select all
<?php
$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = '1111';
$dbname = 'flex';
$conn = sprintf("mysql_pconnect('%s', '%s', '%s')", $dbhost, $dbuser, $dbpass);
if (!$conn)
{
exit("Unable to connect to DB: " . mysql_error());
}
if (!sprintf("mysql_select_db('%s')", $dbname))
{
exit("Unable to select mydbname: " . mysql_error());
}
$users = cw_sql_query('SELECT * FROM volunteer_users');
while(list($pos, $user)=each($users))
{
if($_REQUEST["username"]=$user["username"])
{
if($_REQUEST["password"]=$user["password"])
{
echo("1");
}
else
{
echo("0");
}
}
else
{
echo("0")
}
}
function cw_sql_query($info)
{
global $conn;
$query = mysql_query($info);
dump($query);
$results = array();
while ($result = mysql_fetch_assoc($query))
{
array_push($results, $result);
}
mysql_free_result($query);
Return($results);
}
?>
Jade
Forum Regular
Posts: 908 Joined: Sun Dec 29, 2002 5:40 pm
Location: VA
Post
by Jade » Wed May 07, 2008 5:47 pm
Okay, your first mistake is including your login and password to your server in a public forum. Shame on you! Even if you are running it on localhost.
Second I have no idea why you're doing some kind of query within a function thing. Try something like this:
Code: Select all
<?php
$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = 'nope';
$dbname = 'blah';
$conn = sprintf("mysql_pconnect('%s', '%s', '%s')", $dbhost, $dbuser, $dbpass);
if (!$conn)
{
exit("Unable to connect to DB: " . mysql_error());
}
if (!sprintf("mysql_select_db('%s')", $dbname))
{
exit("Unable to select mydbname: " . mysql_error());
}
$result = mysql_query('SELECT * FROM volunteer_users')
or die ('there was an error: ' . mysql_error());
while($user = mysql_fetch_array($result))
{
if($_REQUEST["username"]=$user["username"])
{
if($_REQUEST["password"]=$user["password"])
echo("1");
else
echo("0");
}
else
echo("0")
} //end while
mysql_free_result($result);
?>
corbo950
Forum Newbie
Posts: 13 Joined: Wed May 07, 2008 1:59 am
Post
by corbo950 » Thu May 08, 2008 1:58 pm
1. it is a testing server and i have the default mysql username and password in there.
2. the function is copyied from my framework since i use querys all the time i just didnt want to post both separatly on here
3. i fixed it thanks anyway though