...

View Full Version : Not Inserting



Webmonkey
08-30-2006, 01:35 PM
Hi,

Does anyone know why this isnt inserting?
All that happens is the form comes back and it inserts nothing.

Thanks

Steven


<title>Admin CP | Add new admin</title>
<style type="text/css">
.text {
font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
</style>
<div class="text">
<p>Please insert the details for the new admin below. The user will automatically be created once you have pressed the create button.</p><br />

<form name="addadmin" method="post" action="addadmin.php">
Username: <input type="text" name="username"><br />
Password: <input type="password" name="pass"><br />
<input type="submit" value="Create" name="submit">
<input type="reset" value="Clear" name="reset">
</form>

</div>
<?php
include('../connect.php');

if (!isset($_POST['submit'])) {
$username = $_POST['username'];
$pass = $_POST['pass'];
$mdpass = md5($pass);

if (!empty($username)) {
echo "Please fill in all fields";
}
$sql = mysql_query("SELECT * FROM `admins` WHERE username = $username");
$result = @mysql_num_rows($sql);
if (is_object($result)) {
echo "Sorry, Username already taken.";
die();
} else {
$ins = mysql_query("INSERT INTO `admins` (`username`, `password`) VALUES ('$username', '$mdpass')");
if ($ins == False) {
echo "Admin added successfully, Thanks.";
} else {

}
}
} else {

}

?>

Fumigator
08-30-2006, 04:06 PM
Your variable $result is going to be an integer returned from mysql_num_rows(), not an object. Try "if ($result > 0) {}". Also you should always check your calls to mysql_query() to make sure the query succeeded: "if (!$sql) {echo mysql_error();}".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum