Go Back   CP Web Hosting - reseller hosting > Server Scripting > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007, 11:35 AM
Senior Member
 
Join Date: May 2007
Posts: 284
Unhappy Resource id #3 error

I'm trying to write a simple login script but I'm getting the resource id #3 error.
code is

Code:
<?php
$host="localhost";
$user="root";
$password="";
$db="admin";
$tableadmin="admin1";

$adminuser= $_POST["adminuser"];
$adminpass= $_POST["adminpass"];

$link = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($db,$link)
or die ("Couldn't select database");

 $result = "SELECT * FROM admin1 WHERE adminuser='$adminuser'  AND adminpass='$adminpass'";   
    $query = mysql_query($result)
    or die ("Couldn't execute query."); 
    echo "<br><br>$query<br><br>";
    //heres the problem
if (mysql_num_rows($result) > 0)   
{
$_SESSION["authenticatedUser"]= $adminuser;
header("Location: loggedon.php");
}
else
{
$_SESSION["message"]="could not connect to database as  $adminuser";
header("Location: loginform.php");
}
?>
Hope someone can help
Reply With Quote
  #2 (permalink)  
Old 06-28-2007, 11:40 AM
Senior Member
 
Join Date: Mar 2007
Posts: 193
Default

why wouldnt the SQL statement be called $query and
the mysql_query be stored as the result?
Reply With Quote
  #3 (permalink)  
Old 06-28-2007, 11:48 AM
Senior Member
 
Join Date: May 2007
Posts: 290
Default

try this

Code:
$query = "SELECT COUNT(*) as cnt FROM admin1 WHERE adminuser='$adminuser'  AND adminpass='$adminpass'";   

$result = mysql_query($query) or die ("Couldn't execute query."); 

$row = mysql_fetch_array($result);

if ($row['cnt'] > 0)   
{
$_SESSION["authenticatedUser"]= $adminuser;
header("Location: loggedon.php");
}
Reply With Quote
  #4 (permalink)  
Old 06-28-2007, 11:51 AM
Senior Member
 
Join Date: May 2007
Posts: 284
Default

thanks for your help but Still not working
Reply With Quote
  #5 (permalink)  
Old 06-28-2007, 11:54 AM
Senior Member
 
Join Date: Apr 2007
Posts: 347
Question

putt @ before mysql_query like this

Code:
$result = @mysql_query($query) or die ("Couldn't execute query.");
Reply With Quote
  #6 (permalink)  
Old 06-28-2007, 11:58 AM
Senior Member
 
Join Date: May 2007
Posts: 284
Default

still have a problem
Reply With Quote
  #7 (permalink)  
Old 06-28-2007, 12:05 PM
Senior Member
 
Join Date: May 2007
Posts: 345
Default

I think u Check your HTML for blank lines
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:42 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0