how can I fix the error "mysql_num_rows(): supplied argument is not a valid MySQL result resource in register2.php on line 27 & 35"
<p>This my register.php codes where a user register. As i click my 'Register' submit button ive got those sql errors and i cant proceed to where my header location is which is voting2.php... pls help.   </p>

<pre><code>&lt;?php session_start(); ?&gt;
&lt;?php  
require('connect/connect.php');
if(isset($_POST['submit'])){
$password1=$_POST['password1'];
$password2=$_POST['password2'];

if ($password1 == $password2) {
    $studid = mysql_escape_string ($_POST['studid']);
    $password1= mysql_escape_string ($password1);
    $password2= mysql_escape_string ($password2);
    $fname= mysql_escape_string($_POST['fname']);
    $lname= mysql_escape_string ($_POST['lname']);
    $mname= mysql_escape_string ($_POST['mname']);
    $dob= mysql_escape_string ($_POST['dob']);
    $address= mysql_escape_string ($_POST['address']);
    $f_fname= mysql_escape_string($_POST['f_fname']);
    $f_lname= mysql_escape_string($_POST['f_lname']);
    $f_mname= mysql_escape_string($_POST['f_mname']);
    $m_fname= mysql_escape_string($_POST['m_fname']);
    $m_lname= mysql_escape_string($_POST['m_lname']);
    $m_mname= mysql_escape_string ($_POST['m_mname']);

    $sql1 = "SELECT * FROM `new_reg_student` WHERE `password` = '". $password1 ."' AND `studid` = '". $studid ."'";

            //this is my line 27 error
    if (mysql_num_rows ($sql1) == 1) {
        echo "Password &amp; Student ID already exists.";
    exit();
    } 

    $sql3 = "INSERT INTO `new_reg_student` (`id`, `studid`, `password`, `fname`, `lname`, `mname`, `dob`, `address`, `f_fname`, `f_mname`, `f_lname`, `m_fname`, `m_mname`, `m_lname`) VALUES (NULL, '$studid', '$password1', '$fname', '$lname', '$mname', '$dob', '$address', '$f_fname', '$f_mname', '$f_lname', '$m_fname', '$m_mname', '$m_lname')" ;
    $result = mysql_query($sql3) or die (mysql_error()) ;

        //this is my line 35 error
        if(mysql_num_rows($result) &gt; 0) {
    header("Location: voting2.php");
    exit();
    } else {
        echo " ";
        exit();
        }
    }
    else {
        echo " Sorry password do not match";
        exit(); 
        }
        }
    ?&gt;
</code></pre>

<p>this the body content of my register.php</p>

<pre><code>     &lt;h2&gt;Please Register Using The Form Below&lt;/h2&gt;
&lt;fieldset&gt;&lt;legend&gt;&lt;h1&gt;Student Info&lt;/h1&gt;&lt;/legend&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td height="500"&gt;
&lt;form id="regform" method="post" action="register2.php"&gt; 
&lt;ul&gt;
&lt;li&gt;&lt;label&gt;Student ID:&lt;/label&gt;&lt;br /&gt;
    &lt;div id="txtbox"&gt;&lt;input type="text" id="" name="studid" readonly="readonly" value="&lt;?php echo $_SESSION['username']; ?&gt;" /&gt;&lt;/div&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;label&gt;Password:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;&lt;input type="password" id="password1" name="password1" /&gt;&lt;/div&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;label&gt;Confirm Password:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;&lt;input  type="password" id="password2" name="password2" /&gt;&lt;/div&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;label&gt;Name:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;&lt;input value="Fist Name" type="text" name="fname"/&gt; - &lt;input value="Middle Name"  type="text" name="mname"/&gt; - &lt;input value="Last Name" type="text" name="lname"/&gt;&lt;/div&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;label&gt;Date of Birth:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;&lt;input  type="text" name="dob" value="Year-Month-Day" /&gt; - ex. 2013-12-01&lt;/div&gt;
        &lt;/li&gt;   
        &lt;/li&gt;&lt;li&gt;&lt;label&gt;Address:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;
          &lt;input  type="text" name="address" /&gt;
        &lt;/div&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;label&gt;Your Father's Name:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;&lt;input value="Fist Name" type="text" name="f_fname"/&gt; - &lt;input value="Middle Name"  type="text" name="f_mname"/&gt; - &lt;input value="Last Name" type="text" name="f_lname"/&gt;&lt;/div&gt;
        &lt;/li&gt;

        &lt;li&gt;&lt;label&gt;Your Mother's Name:&lt;/label&gt;&lt;br /&gt;
        &lt;div id="txtbox"&gt;&lt;input value="Fist Name" type="text" name="m_fname"/&gt; - &lt;input value="Middle Name"  type="text" name="m_mname"/&gt; - &lt;input value="Last Name" type="text" name="m_lname"/&gt;&lt;/div&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;p id="wa"&gt;&lt;input type="submit" id="submit" value="Register" name="submit"/&gt;&lt;/p&gt;
    &lt;/form&gt; 
    &lt;/table&gt;
    &lt;p id="helper"&gt;&lt;/p&gt;
    &lt;/td&gt;&lt;/fielset&gt; 
    &lt;/div&gt;
</code></pre>
