Jump to content

Script not working?


Drewdle

Recommended Posts

The following script doesn't seem to work?

 

I re-used a registration script that I have which works fine, just changing the details where necessary but it doesn't work and shows no errors, when I fill out the form and click submit it just displays the form again, no success message, no error message and it doesn't add the info into the database, however when I run the same query through phpmyadmin it works...

 

<?php 
include ('header.php');
?></center>
<div class=content>
<?php  
if(!empty($_POST['username']) && !empty($_POST['password']))  
{  
    $fname = mysql_real_escape_string($_POST['first']);
    $lname = mysql_real_escape_string($_POST['last']);    
    $email = mysql_real_escape_string($_POST['email']);
    $sia = mysql_real_escape_string($_POST['sia']);
    $no = mysql_real_escape_string($_POST['number']);
  
     $checknumber = mysql_query("SELECT * FROM staff WHERE no = '".$no."'");  
  
     if(mysql_num_rows($checknumber) == 1)  
     {  
        echo "<b>Error</b>";  
        echo "Mobile number in use by another employee!";  
     }  
     else  
     {  
        $addstaff = mysql_query("INSERT INTO staff (fname, lname, email, no, sia) VALUES('".$fname."', '".$lname."', '".$email."', '".$no."', '".$sia."')");  
        if($addstaff)  
        {  
            echo "<b>Success!</b>";  
            echo "Employee added to the database, click <span class=1><a href=stafflist.php>here</a></span> to view employee's";  
        }  
        else  
        {  
            echo "<b>Error</b>";  
            echo "<p>There was a problem adding the employee, please try again.</p>";                
} 
     }  
}  
else  
{  
    ?>  
   <b>Add an Employee</b>  
  <br><br>
   Please enter the details below to add an employee to the database.  
  <br><br>
    <form method="post" action="addstaff.php" name="addstaffform" id="addstaffform"> 
    <table width=700px border=0 cellspacing=10><tr><td valign=top><table border=0>
<b>Required Information:</b><br><br>
<tr><td>  
        <b>First Name:</b>
</td><td>
        <input type="text" name="first" id="first" />
</td></tr><tr><td>
        <b>Last Name:</b>
</td><td>
        <input type="text" name="last" id="last" />
</td></tr><tr><td>  
        <b>Email Address:</b>
</td><td>
        <input type="text" name="email" id="email" />
</td></tr></table></td><td valign=top>
<table border=0>
<b>More Information:</b><br><br>
<tr><td>
     <b>SIA License Number:</b>
</td><td>
     <input type="text" name="sia" id="sia">
</td></tr><tr><td>
     <b>Contact Number:</b>
</td><td>
     <input type="text" name="no" id="no">
</tr></td></td>
</table> </td></tr> </table>
        <input type="submit" name="add" id="add" value="Add Employee" class=btn />  
    </form>  
  
    <?php  
}  
?>  </div>
<?php
include ('footer.php'); 
?>

 

I don't understand it? Whats wrong with it?

Link to comment
https://forums.phpfreaks.com/topic/225043-script-not-working/
Share on other sites

I may have overlooked them on this tiny screen I'm using, but I don't see a input field in that form named either 'username' or 'password'. If that's correct, the first conditional will never evaluate to TRUE.

Link to comment
https://forums.phpfreaks.com/topic/225043-script-not-working/#findComment-1162312
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.