Hi i just did some codoing and heres the error i get when i try to use my register forum
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rpimager/public_html/RPImager/register.php on line 32
Account created.
Here's the docs that i use it for. why i getting this error
config.php
<?
//Configuration File
//Usually localhost
$host = "localhost";
//Database Username
$username = "";
//Database Password
$dbpass = "";
//Database Name
$dbname = "rpimager_test";
//----Do not edit below this line unless you know what you are doing.----
//Connect to DB.
$db=@mysql_connect ("$host", "$username", "$dbpass") or die ("<b>SQL Error</b><Br/>Please check your database connection settings.");
mysql_select_db ("$dbname");
function user_login ($username, $password)
{
//take the username and prevent SQL injections
$username = mysql_real_escape_string($username);
//begin the query
$sql = mysql_query("SELECT * FROM usersystem WHERE username = 'username' AND password = 'password' LIMIT 1");
//check to see how many rows were returned
$rows = mysql_num_rows($sql);
if ($rows<=0 )
{
echo "Incorrect username/password";
}
else
{
//have them logged in
$_SESSION['sername'] = $username;
}
}
//Get data from SQL DB.
$sql=mysql_query("SELECT `Value` FROM `general` WHERE `Name`='Title'") or die (mysql_error());
while($row=mysql_fetch_array($sql)) $title = "$row[Value]";
$sql=mysql_query("SELECT `Value` FROM `general` WHERE `Name`='Ad_Code'") or die (mysql_error());
while($row=mysql_fetch_array($sql)) $adcode = "$row[Value]";
$sql=mysql_query("SELECT `Value` FROM `general` WHERE `Name`='Ad_Code_Downloads'") or die (mysql_error());
while($row=mysql_fetch_array($sql)) $adcode1 = "$row[Value]";
//Steralize a few vars.
$search = stripslashes(strip_tags($_GET[search]));
$filetype = stripslashes(strip_tags($_GET[ext]));
$source = str_replace("|", "", stripslashes(strip_tags($_GET[source])));
if ($source == NULL) $source ="all";
$page = stripslashes(strip_tags($_GET[page]));
if (!is_numeric($page)) $page = "1";
if ($page <= 0) $page="1";
?>
register.php
<?php
include("config.php");
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))
{
//Prevent SQL injections
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
//Get MD5 hash of password
$password = md5($_POST['password']);
//Check to see if username exists
$sql = mysql_query("SELECT username FROM usersystem WHERE username = 'username'");
if (mysql_num_rows($s>0))
{
die ("Username taken.");
}
mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") or die (mysql_error()); echo "Account created.";
}
?>
<html></html>
<form action="register.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
<input type="submit" value="Submit" />
</form>
login.php
<?php
include("config.php");
if (isset($_POST['username']) && isset($_POST['password']))
{
user_login($_POST['username'], $_POST['password']);
}
?>
<html></html>
<form action="login.php" method="post">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
<input type="submit" value="Submit" />
</form>