Results 1 to 9 of 9
-
31st Dec 2011, 06:36 AM #1OPMemberWebsite's:
SourceParadise.com MobileMaster.orgHelp With PHP Error
Hi guys,
I`m learning PHP with MySQL and have some problem.
I`m just creating a simple script to accept login details from index.php and transfer them to login.php via POST. 1st part went smooth. For 2nd part, login.php I`m having some problem.
I tried google and change the variable names too but the result was same. I kept getting error:
Code:Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\login.php on line 10
PHP Code:<?php
$con= mysql_connect("localhost","usermaster","") or die (mysql_error());
$cName= $_POST["boxuser"];
$cPass=$_POST["boxpass"];
mysql_select_db("mynewdb");
//$data = "select * from mytable where uname=".$cName."and upass=".$cPass;
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ((strlen($row))>0)
{
echo "Login successful.";
}
else
{
echo "Login failed.";
}
mysql_close();
?>nEw_boY Reviewed by nEw_boY on . Help With PHP Error Hi guys, I`m learning PHP with MySQL and have some problem. I`m just creating a simple script to accept login details from index.php and transfer them to login.php via POST. 1st part went smooth. For 2nd part, login.php I`m having some problem. I tried google and change the variable names too but the result was same. I kept getting error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\login.php on line 10 My login.php is here: <?php Rating: 5
-
31st Dec 2011, 06:42 AM #2Respected MemberWebsite's:
DL4Everything.com Soft2050.inmysql_fetch_array - Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
http://php.net/manual/en/function.mysql-fetch-array.php
Use mysql_num_rows to check whether the query returned any results or not:
http://php.net/manual/en/function.mysql-num-rows.php
PHP Code:<?php
if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access
$con= mysql_connect("localhost","usermaster","") or die (mysql_error());
$cName= mysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
$cPass= mysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
mysql_select_db("mynewdb");
//$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
$query = "SELECT * FROM mytable WHERE uname=$cName and upass=$cPass";
$result = mysql_query($query);
$row = mysql_num_rows($result);
if ($row > 0)
{
echo "Login successful.";
}
else
{
echo "Login failed.";
}
mysql_close();
} else {
die('RETRY AGAIN FROM THE LOGIN PAGE');
}
?>
-
31st Dec 2011, 07:07 AM #3OPMemberWebsite's:
SourceParadise.com MobileMaster.org
Its the same error as before. Is there any problem with my config ?
Anything you can guess ?
-
31st Dec 2011, 07:16 AM #4Respected MemberWebsite's:
DL4Everything.com Soft2050.inAhh f**k! Yeah its similar
You need to also specify the connection in mysql query
Try this! Should work:
PHP Code:<?php
if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access
$con= mysql_connect("localhost","usermaster","") or die (mysql_error());
$cName= mysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
$cPass= mysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
mysql_select_db("mynewdb", $con);
//$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
$query = "SELECT * FROM mytable WHERE uname=$cName and upass=$cPass";
$result = mysql_query($query, $con);
$row = mysql_num_rows($result);
if ($row > 0)
{
echo "Login successful.";
}
else
{
echo "Login failed.";
}
mysql_close();
} else {
die('RETRY AGAIN FROM THE LOGIN PAGE');
}
?>
-
31st Dec 2011, 07:29 AM #5OPMemberWebsite's:
SourceParadise.com MobileMaster.orgNope, its the same.
I tried to fix it for almost 12 hrs yesterday but it aint worked.
Let me grab some tutorial script and confirm that my config is okay.
Fix it meanwhile, if anything seems wrong.
Edit:
My connection is doing good, tried pre-made script, can someone point out the error please ?
-
31st Dec 2011, 09:00 AM #6Respected MemberWebsite's:
DL4Everything.com Soft2050.inFound it and tested too! it does works now
PHP Code:<?php
if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access
$con= mysql_connect("localhost","usermaster","") or die (mysql_error());
$cName= mysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
$cPass= mysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
mysql_select_db("mynewdb", $con);
//$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
$query = "SELECT * FROM mytable WHERE uname='$cName' and upass='$cPass'";
$result = mysql_query($query, $con);
$row = mysql_num_rows($result);
if ($row > 0)
{
echo "Login successful.";
}
else
{
echo "Login failed.";
}
mysql_close();
} else {
die('RETRY AGAIN FROM THE LOGIN PAGE');
}
?>
-
31st Dec 2011, 09:38 AM #7OPMemberWebsite's:
SourceParadise.com MobileMaster.orgI still have the same problem.
I even tried just plain SELECT * from mytable but it isnt working. fetch_array or num_rows, none of them are working.
Are you sure that you tried it ? Can anyone else confirm it ?
-
31st Dec 2011, 11:06 AM #8Respected MemberWebsite's:
DL4Everything.com Soft2050.inYes i tried it. Here's my try code:
PHP Code:<?php
//if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access
$con= mysql_connect("localhost","username", "") or die (mysql_error());
$cName= 'admin'; //mysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
$cPass= 'mymd5hashedtestpass'; //mysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
mysql_select_db("dle", $con);
//$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
$query = "SELECT * FROM dle_users WHERE name='$cName' and password='$cPass'";
$result = mysql_query($query, $con) or die (mysql_error());
$row = mysql_num_rows($result);
if ($row > 0)
{
echo "Login successful.";
}
else
{
echo "Login failed.";
}
mysql_close();
//} else {
// die('RETRY AGAIN FROM THE LOGIN PAGE');
//}
?>
Edit: I am pretty much sure that the problem is in your query so make it output the error:
PHP Code:<?php
if (isset($_POST["boxuser"]) and isset($_POST["boxpass"])) { // use checks to prevent from direct page access
$con= mysql_connect("localhost","usermaster","") or die (mysql_error());
$cName= mysql_real_escape_string($_POST["boxuser"]); // prevent mysql injections
$cPass= mysql_real_escape_string($_POST["boxpass"]); // prevent mysql injections
mysql_select_db("mynewdb", $con);
//$query = "select * from mytable where uname=".$cName."and upass=".$cPass;
$query = "SELECT * FROM mytable WHERE uname='$cName' and upass='$cPass'";
$result = mysql_query($query, $con) or die (mysql_error());
$row = mysql_num_rows($result);
if ($row > 0)
{
echo "Login successful.";
}
else
{
echo "Login failed.";
}
mysql_close();
} else {
die('RETRY AGAIN FROM THE LOGIN PAGE');
}
?>
-
31st Dec 2011, 11:31 AM #9OPMemberWebsite's:
SourceParadise.com MobileMaster.orgOh man, I cant thank you in words...
You really solved it.
The query returned false error that PHP considered as Boolean, your last code was right but I forgot to update the column names of my database. Its done, solved.
Tons of love to you, brother.
Solved.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Error Detected in sitemap XML. How to remove error?
By Bobby3711 in forum Web Application/Script SupportReplies: 1Last Post: 21st Mar 2012, 03:51 PM -
Rapidleech error: Error openning rar process
By tractor3231 in forum Server ManagementReplies: 13Last Post: 14th Dec 2011, 04:35 AM -
HTTP Error 500 (Internal Server Error):
By joshmoore in forum Technical Help Desk SupportReplies: 4Last Post: 25th Nov 2011, 03:59 AM -
wtf happened? (ipb 3.23 skin error causes fatal error)
By mrHunt in forum Technical Help Desk SupportReplies: 1Last Post: 25th Nov 2011, 03:55 AM -
Adding Domain Error in cPanel (Error from park wrapper:)
By Ryza in forum General DiscussionReplies: 0Last Post: 20th Feb 2011, 01:57 AM
themaCreator - create posts from...
Version 3.48 released. Open older version (or...