tabatsoy Posted May 4, 2008 Share Posted May 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/ Share on other sites More sharing options...
lokie538 Posted May 4, 2008 Share Posted May 4, 2008 try changing all your mysql parts to functions to mysqli ..... dunno if this will help but yeah im new to this Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-532619 Share on other sites More sharing options...
Barand Posted May 4, 2008 Share Posted May 4, 2008 Ask mysql why. $result = mysql_query("SELECT * FROM admin WHERE username = '".$var1."' AND password = '".$var2."'") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-532637 Share on other sites More sharing options...
tabatsoy Posted May 5, 2008 Author Share Posted May 5, 2008 i asked sql why and he says that there is no database selected ??? Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533238 Share on other sites More sharing options...
DyslexicDog Posted May 5, 2008 Share Posted May 5, 2008 What does your database connection setup look like? Please post code with no server / user information. Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533241 Share on other sites More sharing options...
tabatsoy Posted May 5, 2008 Author Share Posted May 5, 2008 i'm using wamp4 in my laptop but then i transfer my codes in a desktop and used the latest version of wamp Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533245 Share on other sites More sharing options...
trq Posted May 5, 2008 Share Posted May 5, 2008 Its likely your connection is failing. Your not passing any username/password combination to mysql_connect. Place this at the top of your script and post the exact error messages you receive if any. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533247 Share on other sites More sharing options...
tabatsoy Posted May 5, 2008 Author Share Posted May 5, 2008 there's a notice: Notice: Undefined index: uname in C:\wamp\www\exam\login.php on line 33 Notice: Undefined index: pword in C:\wamp\www\exam\login.php on line 34 and still "No Database selected" ??? Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533249 Share on other sites More sharing options...
trq Posted May 5, 2008 Share Posted May 5, 2008 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. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533250 Share on other sites More sharing options...
tabatsoy Posted May 5, 2008 Author Share Posted May 5, 2008 another error occured: Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\wamp\www\exam\login.php on line 33 Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533255 Share on other sites More sharing options...
wildteen88 Posted May 5, 2008 Share Posted May 5, 2008 thorpe missed of a closing brace, try: <?php if (isset($_POST["uname"]) && isset($_POST["pword"])) { $var1 = $_POST["uname"]; $var2 = $_POST["pword"]; // rest of your code here. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104046-help-in-php5/#findComment-533310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.