0

any help here will be greatly appreciated. I am a newbie in the world of databases. Ok I have created my form for new users sign up, after the person enters all the details assuming they are right they will receive a message stating welcome to the site and the info will be put into the database.

however I am receiving this: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\office\index.php on line 31

And also the users entries are not going into the data base. please help :(

index.php is below but i also have my connect file as below (the connect to SQL file and index are different files):

<?php
mysql_connect("127.0.0.1","root","") or die(mysql_error());
mysql_select_db("office");
?>


<?php include ("./inc/header.inc.php"); ?>
<?php 

$reg = @$_POST['reg'];
//declaring variables to prevent errors
$fn = ""; //First Name
$ln = ""; //Last Name
$un = ""; //Username
$em = ""; //Email
$em2 = ""; //Email 2
$pswd = ""; //Password
$pswd2 = ""; // Password 2
$d = ""; // Sign up Date
$u_check = ""; // Check if username exists
//registration form
$fn = strip_tags(@$_POST['fname']);
$ln = strip_tags(@$_POST['lname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 = strip_tags(@$_POST['password2']);
$d = date("Y-m-d"); // Year - Month - Day
error_reporting(E_ALL ^ E_DEPRECATED);

if ($reg) {
if ($em==$em2) {
// Check if user already exists
$u_check = mysql_query("SELECT username FROM users WHERE username='$un'");
// Count the amount of rows where username = $un
$check = mysql_num_rows($u_check);
if ($check == 0) {  
    //check all of the fields have been filed in
if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) {
    // check that passwords match
if ($pswd==$pswd2) {

// check the maximum length of username/first name/last name does not exceed 25 characters
if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
echo "The maximum limit for username/first name/last name is 25 characters!";
}   
else
{
// check the maximum length of password does not exceed 25 characters and is not less than 5 characters
if (strlen($pswd)>30||strlen($pswd)<5) {
echo "Your password must be between 5 and 30 characters long!";
}
else
{
//encrypt password and password 2 using md5 before sending to database
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO users VALUES ('', '$un', '$fn', '$ln', '$em', '$pswd', '$d', '0','','','')");
die("<h2>Welcome to OfficeSpace</h2>Login to your account to get started ...");
}
}
}
else {
echo "Your passwords don't match!";
}
}
else
{
echo "Please fill in all of the fields";

}
}
else
{
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
?>
<?
//User Login Code
if (isset($_POST["user_login"]) && isset($_POST["password_login"])) {
    $user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]); // filter everything but numbers and letters
    $password_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password_login"]); // filter everything but numbers and letters
    $md5password_login = md5($password_login);
    $sql = mysql_query("SELECT id FROM users WHERE username='$user_login' AND password='$md5password_login' AND closed='no' LIMIT 1"); // query the person
    //Check for their existance
    $userCount = mysql_num_rows($sql); //Count the number of rows returned
    if ($userCount == 1) {
        while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
    }

         $_SESSION["user_login"] = $user_login;
         header("location: home.php");
exit();
    } else {
        echo "Your usernmae or password is incorrect, please try again";
        exit();
    }
?>



    <div style="width: 890px: margin: 0px auto 0px auto;">
    <table>
        <tr>    
            <td width="60%" valign="top">
    <div style="float: left;">
            <h2>Already a Memeber? Login below ...</h2>
            <form action="index.php" method="post" name="form1" id="form1">
                <input type="text" size="40" name="user_login" id="user_login" class="auto-clear" title="Username ..." /><p />
                <input type="text" size="40" name="password_login" id="password_login" value="Password ..." /><p />
                <input type="submit" name="button" id="button" value="Login to your account">
            </form>
            </td></div>
            <td width="40% valign="top">
                <h2> Sign up below! </h2>
                <form action="#" method="POST">
                    <input type="text" name="fname" size="25" placeholder="First Name" /><br /><br />
                    <input type="text" name="lname" size="25" placeholder="Second Name" /><br /><br />
                    <input type="text" name="username" size="25" placeholder="Select Username" /><br /><br />
                    <input type="text" name="email" size="25" placeholder="Email Address" /><br /><br />
                    <input type="text" name="email2" size="25" placeholder="Confirm Email" /><br /><br />
                    <input type="text" name="password" size="25" placeholder="Password" /><br /><br />
                    <input type="text" name="password2" size="25" placeholder="Confirm Password" /><br /><br />
                    <input type="submit" name="reg" value="Sign Up!" />
            </form>
            </td>
            </tr>
            </table>
    <?php include ("./inc/footer.inc.php"); ?>

    </body>
    </html>
Ketih Carpenter
  • 93
  • 1
  • 2
  • 9
  • Read this: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Davide Pastore Dec 08 '15 at 11:09
  • @ketih Carpenter first of all use `mysqli_*` instead `mysql_*` – Nagendra Prasad Balaka Dec 08 '15 at 11:28
  • hey guys thanks for replying so fast you rock :) ok as suggested I have replaces all mysql_* with mysqli_* but all that has done is throw up some new errors and the info is still not going to the database :( – Ketih Carpenter Dec 08 '15 at 11:35
  • "Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\office\index.php on line 29 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\office\index.php on line 31" – Ketih Carpenter Dec 08 '15 at 11:35
  • @KetihCarpenter you are not reaching to insert query statement,check all your `if-else` conditions. – Nagendra Prasad Balaka Dec 08 '15 at 11:47

0 Answers0