need help with inserting data into a my database table
Results 1 to 3 of 3

Thread: need help with inserting data into a my database table

  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    31

    Question need help with inserting data into a my database table

    when i put info into form fields nothing happens

    PHP Code:
    <?php
                    
    //connect to server and select database
            
    $con mysql_connect("localhost""******""******",);
                if(!
    $con)
                    {
            die (
    'Could not connect: ' mysql_error());
            
            
            
    mysql_select_db("registration"$con);
            
            
            
            
    //retrieve posted info.
            
    $username $_POST['username'];
            
    $password $_POST['password'];
            
    $email    $_POST['email'];
            
            
            
            
    //insert into database.
            
    $sql "INSERT INTO newusers SET username='$username' , 
                    password='
    $password' , email='$email' ";
            
            
            
            
    //display message.
            
    if (!mysql_query($sql,$con) )
            {
            die(
    'ERROR:' mysql_error() );
            }
            echo 
    "Info successfully added!";
            
            
            
    mysql_close($con)
            
            
    ?>
            
            
            <html>
    <body>
    <!-- Tutorial Description: PHP Forms -->
     
    <form action="form_success.php" method="post">
    username: <input type="text" name="username" /><br>
    password: <input type="text" name="password" /><br>
    email: <input type="text" name="email" /><br>
    <input type="submit" value="login" />
    </form>
     
    </body>
    </html>
    Last edited by bradgrafelman; 04-13-2012 at 10:57 AM. Reason: PHP bbcode tags added

  2. #2
    Senior Member
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    753
    You're opening a brace ({) on line 5 which isn't closed. You can remove it completely, as you're only trying to execute one thing if the connection isn't made, and the script will exit if it hits the die() anyway. As you don't see any output from your die() statements, you can safeul assume that you have a connection.
    Ashley Sheridan
    www.ashleysheridan.co.uk

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    You've also got another parse error on this line:
    PHP Code:
            $con mysql_connect("localhost""******""******",); 
    caused by an extra comma at the end of the function parameter list.

    However, the fact that you claim "nothing happens" suggests an even bigger problem - your environment isn't set up for debugging/developing. For example, in the development environment, you should probably have error_reporting set to E_ALL and display_errors set to On. Otherwise, you'll probably miss helpful error messages PHP is trying to give you, such as:
    Code:
    Parse error: syntax error, unexpected ')' in <file> on line 3
    (the error message I got when I ran a lint check on your code snippet above).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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