Jump to content

Recommended Posts

my code in php 4 runs smoothly but when i transfer it in php5 this prints out in the browser:

          Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\exam\login.php on line 40

 

            here is my code:

 

                     

<?php 
session_start();
$db = mysql_connect("localhost");
	mysql_select_db("examination",$db);
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Login</title>
<link href="Layout.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style></head>

<body>
<table width="800" border="0" align="center">
  <tr>
    <td colspan="2"><div align="center"><img src="images/logo.jpg" width="800" height="200" />
    </div></td>
  </tr>
  <tr>
    <td colspan="2"><div align="center"> <span class="session"><br />Log in as an Administrator <br /></span><br />
    </div></td>
  </tr>
  <tr></tr>
  <tr>
    <td colspan="2"><div align="center">
      <?php
$var1 = $_POST["uname"];
$var2 = $_POST["pword"];	
if($var1 && $var2){

	$result = mysql_query("SELECT *
							FROM admin
							WHERE username = '".$var1."'
							AND password = '".$var2."'");
	if(mysql_num_rows($result) > 0){
		$_SESSION['loggedin'] = $var1;			
		echo '<span class = "style1"><strong>Welcome, </strong></span><font color="#003399" face="verdana" size="3" style="text-transform: capitalize"><strong>'.$var1 .".</strong></font><br><br>";
		echo "<a href ='admin.php'><div align = 'center' class = 'session'><font size = '1'>Click here to go to Administrator's Main Page</font></div></a><br>";
		echo "<a href='logout.php'><div align = 'center' class = 'session'><font size = '1'>click here to logout</font></div></a><br><br>";
		exit;	
	}
	else{
		echo '<font face = "verdana" size = "2" color = "red">Invalid username or password</font><br>';
	}
}
else if($var1 || $var2){
	echo '<font face = "verdana" size = "2" color = "red">Please Fill in all fields.</font><br>';
}
?>
    </div></td>
  </tr>
  <tr>
    <td width="221"> </td>
    <td width="569"><form id="form1" name="form1" method="post" action="login.php">
      <p><span class="style1">username:</span>
        <input name="uname" type="text" id="username" maxlength="20" />
      </p>
      <p><span class="style1">password:</span>
        <input name="pword" type="password" id="password" maxlength="10" />
      </p>
      <p>
        <input type="submit" name="Submit" value="login" />
      </p>
    </form></td>
  </tr>
</table>
<p> </p>
</body>
</html>

 

please help

Link to comment
https://forums.phpfreaks.com/topic/104046-help-in-php5/
Share on other sites

Means exactly what it says. $_POST["uname"] and $_POST["pword"] are not set, hence your query is failing.

 

You need to test they are set prior to executing your query. eg;

 

<?php

  if (isset($_POST["uname"] && isset($_POST["pword"])) {
    $var1 = $_POST["uname"];
    $var2 = $_POST["pword"];

    // rest of your code here.
  
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533250
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.