Sql Error

Started on the old forum in June 2008 · view the original in the archive · old links redirect here

10 replies · 794 views · started 18 years ago · 1 min read

6 participants
SpiderWap Lead · 622 posts #1

Ok, I'm coding a new script, but experiencing a problem with sql.

<?
include("../config.php");
include("../style.php");
$site = $_POST['site'];
$site=strtolower($site);
$query = "SELECT * FROM `users` WHERE `site` = '".$site."'";
$result = mysql_query($query);
$otvet = mysql_fetch_array($result);
if($otvet['site']){
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

<?
echo "<head>\n";
echo "<title>Login@".$site."</title>\n";
echo $style;
echo "<meta name=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";  
echo "<meta http-equiv=\"Cache-Control\" content=\"must-revalidate\" />\n";
echo "<meta http-equiv=\"Cache-Control\" content=\"no-cache\" />\n";
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
echo "</head>\n";
echo "<body>\n";
$userquery = "SELECT * FROM `users` WHERE site='".$site."', `name` = '".$name."' AND pass = LIKE '".$pass."'";
$userresult = mysql_query($userquery);
$userotvet = mysql_fetch_array($userresult);
if($userotvet['name']){
echo "Hi ".$name.", welcome to ".$site." :)
\n";
echo "<a href=\"enter.php?site=$site&name=$name&pass=$pass\">Enter ".$site."</a>\n";
echo "<div class=\"foot\">\n";
echo "© WapX ".date ("Y")."";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
exit();
}
else
{
echo "Not Logged in.
\n";
echo "Please register or try loging in again.
\n";
echo "<a href=\"index.php?site=$site\">Home</a>\n";
echo "<div class=\"foot\">\n";
echo "© WapX ".date ("Y")."";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
exit();
}
}
else
{
header("location: error/notfound.php");
exit();
}
?>

SQL

CREATE TABLE `users` (
  `id` int(4) NOT NULL auto_increment,
  `site` varchar(15) NOT NULL default '',
  `name` varchar(15) NOT NULL default '',
  `pass` varchar(30) NOT NULL default '',
  `birthday` varchar(15) NOT NULL default '',
  `sex` varchar(8) NOT NULL default '',
  `country` varchar(20) NOT NULL default '',
  `province` varchar(20) NOT NULL default '',
  `level` char(1) NOT NULL default '0',
  `rtime` varchar(30) NOT NULL default '',
  `ip` text,
  `soft` text,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

Error I'm getting

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/user/public_html/script/sites/login.php on line 61

So theres something wrong with this peace of coding $userquery = "SELECT * FROM users WHERE site='".$site."', name = '".$name."' AND pass = LIKE '".$pass."'"; $userresult = mysql_query($userquery); $userotvet = mysql_fetch_array($userresult);

Someone please correct me on fixing this error?

metulj Super moderator Principal · 1,726 posts #2

maybe instead this

$userquery = "SELECT * FROM `users` WHERE site='".$site."', `name` = '".$name."' AND pass = LIKE '".$pass."'";

this would work

$userquery = "SELECT * FROM `users` WHERE site='".$site."', `name` = '".$name."' AND pass = '".$pass."'";

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

SpiderWap Lead · 622 posts #3

I'm getting

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/spiderw/public_html/wapx/sites/login.php on line 61
Not Logged in.
Please register or try loging in again.
crazybrumi Super moderator Principal · 1,064 posts #4
$userquery = "mysql_fetch_array(mysql_query("SELECT (*) FROM `users` WHERE site='".$site."', `name` = '".$name."' AND pass = LIKE '".$pass."'"));

try this prob wont work nowin mu luck

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

rukiya Lead · 569 posts #5

Ok, I'm coding a new script, but experiencing a problem with sql.

<?
include("../config.php");
include("../style.php");
$site = $_POST['site'];
$site=strtolower($site);
$query = "SELECT * FROM `users` WHERE `site` = '".$site."'";
$result = mysql_query($query);
$otvet = mysql_fetch_array($result);
if($otvet['site']){
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

<?
echo "<head>\n";
echo "<title>Login@".$site."</title>\n";
echo $style;
echo "<meta name=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";  
echo "<meta http-equiv=\"Cache-Control\" content=\"must-revalidate\" />\n";
echo "<meta http-equiv=\"Cache-Control\" content=\"no-cache\" />\n";
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n";
echo "</head>\n";
echo "<body>\n";
$userquery = "SELECT * FROM `users` WHERE site='".$site."', `name` = '".$name."' AND pass = LIKE '".$pass."'";
$userresult = mysql_query($userquery);
$userotvet = mysql_fetch_array($userresult);
if($userotvet['name']){
echo "Hi ".$name.", welcome to ".$site." :)
\n";
echo "<a href=\"enter.php?site=$site&name=$name&pass=$pass\">Enter ".$site."</a>\n";
echo "<div class=\"foot\">\n";
echo "© WapX ".date ("Y")."";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
exit();
}
else
{
echo "Not Logged in.
\n";
echo "Please register or try loging in again.
\n";
echo "<a href=\"index.php?site=$site\">Home</a>\n";
echo "<div class=\"foot\">\n";
echo "© WapX ".date ("Y")."";
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
exit();
}
}
else
{
header("location: error/notfound.php");
exit();
}
?>

SQL

CREATE TABLE `users` (
  `id` int(4) NOT NULL auto_increment,
  `site` varchar(15) NOT NULL default '',
  `name` varchar(15) NOT NULL default '',
  `pass` varchar(30) NOT NULL default '',
  `birthday` varchar(15) NOT NULL default '',
  `sex` varchar(8) NOT NULL default '',
  `country` varchar(20) NOT NULL default '',
  `province` varchar(20) NOT NULL default '',
  `level` char(1) NOT NULL default '0',
  `rtime` varchar(30) NOT NULL default '',
  `ip` text,
  `soft` text,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

Error I'm getting

So theres something wrong with this peace of coding $userquery = "SELECT * FROM users WHERE site='".$site."', name = '".$name."' AND pass = LIKE '".$pass."'"; $userresult = mysql_query($userquery); $userotvet = mysql_fetch_array($userresult);

Someone please correct me on fixing this error?

$userquery = "SELECT * FROM users WHERE site='".$site."', name = '".$name."' AND pass = LIKE '".$pass."'";

1.You cant use comma , after WHERE clause in mysql query,thatsy the you are getting error

2.declare the $name and $pass variables first then they are allowed to be used like

$name = $_POST['name'];
$pass = $_POST['pass'];

its not good to use LIKE mysql operation in case of password as input password need to be same to the saved password in the database this query is good

$a = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM `users` WHERE site='".$site."' AND`name` = '".$name."' AND pass = '".$pass."'"));
if($a[0]=="1")
{}
else
{}
SpiderWap Lead · 622 posts #6

Ah, don't worry, i think i managed.

$name= strtolower($name);
$loginquery = "SELECT * FROM `users` WHERE `site` = '".$site."' AND `name` = '".$name."' AND `pass` LIKE '".$pass."' ";
$loginresult = mysql_query($loginquery);
$loginotvet = mysql_fetch_array($loginresult);
if($loginotvet['name']){

And i forgot to $name=$_POST["name"]; $pass=$_POST["pass"]; Think I'm sorted now. Thank you.

djlee Developer · 224 posts #7

u might wanna secure user posted variables with mysql_real_escape_string() before you use them in a query

djlee Developer · 224 posts #9

dunno who ur on about so no im guessing not

Guest #10

wtf..sm1 playn again

subzero Super moderator Fellow · 3,954 posts #11

= huh why them in there ?

$clogin = mysql_fetch_array(mysql_query("SELECT (*) FROM usersed WHERE id='".$sit_id."'"));

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close