- Code: Select all
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/jharvard/public_html/pset7/register2.php on line 23
Call Stack
# Time Memory Function Location
1 0.0004 326808 {main}( ) ../register2.php:0
2 0.0220 356268 mysql_num_rows ( ) ../register2.php:23
this is my code for register2.php
- Code: Select all
<?
// require common code
require_once("includes/common.php");
// escape username to avoid SQL injection attacks
$username = mysql_real_escape_string($_POST["username"]);
// encrypted password
$password = crypt($_POST["password"]);
// prepare SQL
$sql = "INSERT INTO users (username, hash, cash)
VALUES ($username, $password, 10000)";
// TESTING
// die($sql."<br/><br/>".mysql_error());
// execute query
$result = mysql_query($sql);
// if we found user, check password
if (mysql_num_rows($result) == 1)
{
// grab row
$row = mysql_fetch_array($result);
// compare hash of user's input against hash that's in database
if (crypt($_POST["password"], $row["hash"]) == $row["hash"])
{
// remember that user's now logged in by caching user's ID in session
$_SESSION["id"] = $row["id"];
// redirect to portfolio
redirect("index.php");
}
}
// else report error
apologize("Invalid username and/or password!");
?>
this is my code for register.php
- Code: Select all
<?
// require common code
require_once("includes/common.php");
?>
<!DOCTYPE html>
<html>
<head>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<title>C$50 Finance: Log In</title>
</head>
<body>
<div id="top">
<a href="index.php"><img alt="C$50 Finance" src="images/logo.gif"></a>
</div>
<div id="middle">
<form action="register2.php" method="post">
<table>
<tr>
<td>Username:</td>
<td><input name="username" type="text"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password"></td>
</tr>
<tr>
<td>Repeat Password:</td>
<td><input name="password" type="password2"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
</form>
</div>
<div id="bottom">
or <a href="login.php">log in</a>
</div>
</body>
</html>

