/    Sign up×
Community /Pin to ProfileBookmark

Simply query problem

Anyone have any ideas why this isnt working?

[code]
function checkUsername($username){
$connect = mysql_connect(‘localhost’, $serverUsername, $serverPassword);
mysql_select_db($database, $connect);
$query = “SELECT * FROM ‘usertable'”;
$result = mysql_query($query, $connect);
mysql_close($connect);
return $result;
}

$test = checkUsername(“god”);
echo “$test”;

[/code]

All I want it to do is echo the result of the query but it wont even do that. it just displays a blank screen. Whhhyyy.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@Suhas_DhokeJan 07.2008 — First of all, the connection was not established, because, you are using the variables

for connecting to the database, but they are not defined.

Therefore it displays the blank page.

Actually, PHP will display all the notices, if you turn on the "error_reporting()"

Here is the modified code.. and let me know.. is it working as expected or not.

[code=php]error_reporting(E_ALL);
function checkUsername($username)
{
$serverUsername = 'server_username';
$serverPassword = 'server_password';
$database = 'database_table_name';
$connect = mysql_connect('localhost', $serverUsername, $serverPassword);
mysql_select_db($database, $connect);
$query = "SELECT * FROM table_name where username = '$username' ";
$result = mysql_query($query, $connect);
$userDetails = mysql_fetch_array($result);
mysql_close($connect);
return $userDetails;
}

$test = checkUsername("god");
print_r($test);[/code]


It will return all the details of the user, "god".
Copy linkTweet thisAlerts:
@slevenJan 07.2008 — expected
Copy linkTweet thisAlerts:
@aatwoauthorJan 07.2008 — It still does not print anything! It doesn't even show any errors.

[code=php]
error_reporting(E_ALL);

//function to return 1 if the argument $username is available and 0 if unavailable
function checkUsername($username){
$serverUsername = "serverpassword";
$serverPassword = "serverusername";
$database = "mydatabase"; //name of the database

$connect = mysql_connect('localhost', $serverUsername, $serverPassword);
mysql_select_db($database, $connect);
$query = "SELECT * FROM 'usertable' WHERE 'username'=$username";
$result = mysql_query($query, $connect);
$userDetails = mysql_fetch_array($result);
mysql_close($connect);
return $userDetails;
}
[/code]





[code=php]
<?php
$test = checkUsername("god");
print_r($test);
?>
[/code]
Copy linkTweet thisAlerts:
@Suhas_DhokeJan 07.2008 — Ok.

Give me the code, what u write.. .
Copy linkTweet thisAlerts:
@aatwoauthorJan 07.2008 — This is it...

[code=php]

<html>
<head>
<title>TEST Page</title>
<LINK REL=stylesheet HREF="http://www.aatwo.com/programming/php/rsscw/style.css" TYPE="text/css">
</head>
<body>

<?php

$serverUsername = "serverusername";
$serverPassword = "serverpassword";
$database = "RSSdatabase"; //name of the database
$username = "god";

$connect = mysql_connect("localhost", "$serverUsername", "$serverPassword");
mysql_select_db("$database", $connect);
$query = "SELECT * FROM 'usertable' WHERE 'username'=$username";
$result = mysql_query($query, $connect);
$row = mysql_fetch_array($result);
echo "Username: " . $row['username'] . "rn.";
echo "password: " . $row['password'] . ".";
mysql_close($connect);

?>


</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@Suhas_DhokeJan 07.2008 — And, one more thing.. Do u passing the valid *username* as argument in checkUsername() function ?
Copy linkTweet thisAlerts:
@aatwoauthorJan 07.2008 — Yeh i was passing a valid username into the function.
Copy linkTweet thisAlerts:
@Suhas_DhokeJan 07.2008 — just for the confirmation.. .

Are u passing the correct *server_username* and *server_password* and

there is no need to add single quote ( ' ) around the Table_Name.

Remove it, if it is there, and try again..

All The Best.
Copy linkTweet thisAlerts:
@aatwoauthorJan 07.2008 — Thanks for your help. I still do not know why the code was not originally working however I have rewritten the code from the ground up and it works now. The code essentially ended up being the same and so I can only assume there is a VERY discrete mistake somewhere in the code I have posted!

Thanks again for your help.
×

Success!

Help @aatwo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...