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
    Join Date
    Mar 2012

    Question need help with inserting data into a my database table

    when i put info into form fields nothing happens

    PHP Code:
    //connect to server and select database
    $con mysql_connect("localhost""******""******",);
            die (
    'Could not connect: ' mysql_error());
    //retrieve posted info.
    $username $_POST['username'];
    $password $_POST['password'];
    $email    $_POST['email'];
    //insert into database.
    $sql "INSERT INTO newusers SET username='$username' , 
    $password' , email='$email' ";
    //display message.
    if (!mysql_query($sql,$con) )
    'ERROR:' mysql_error() );
    "Info successfully added!";
    <!-- 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" />
    Last edited by bradgrafelman; 04-13-2012 at 09:57 AM. Reason: PHP bbcode tags added

  2. #2
    Senior Member
    Join Date
    Aug 2008
    London, UK
    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

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Kansas City area
    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:
    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