Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Not Inserting

  1. #1
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Not Inserting

    Hi,

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

    Thanks

    Steven

    PHP Code:
    <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 {

    }

    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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();}".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •