www.webdeveloper.com
Results 1 to 5 of 5

Thread: PHP not working with database

  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Unhappy PHP not working with database

    Hi All,

    I have a problem with a PHP script I wrote. The problem is, it does not insert the information gathered into a database. Below is the code and a few more details.

    Code:
    <?php
    
    require("config.php");
    
    // Retrieve our data from POST
    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $dateOB = $_POST['dateOB'];
    $telNumber = $_POST['telNumber'];
    $mobNumber = $_POST['mobNumber'];
    $email = $_POST['email'];
    $addressLine1 = $_POST['addressLine1'];
    $postcode = $_POST['postcode'];
    $docName = $_POST['docName'];
    $docAddressLine1 = $_POST['docAddressLine1'];
    $docPostcode = $_POST['docPostcode'];
    $docContact = $_POST['docContact'];
    
    
    // Insert into table
    $query = "INSERT INTO people ( firstName, lastName, dateOB, telNumber, mobNumber, email, addressLine1, postcode, docName, docAddressLine1, docPostcode, docContact )
            VALUES ( '$firstName' , '$lastName' , '$dateOB', '$telNumber' , '$mobNumber', '$email' , '$addressLine1', '$postcode' , '$docName', '$docAddressLine1' , '$docPostcode', '$docContact' );";
    mysql_query($query);
    mysql_close();
    
    ?>
    Above is my code, the config.php file contains the database details and connection. Whenever I run this, the data never gets stored into the table "people". I have tried echoing all values and they are correct, I have echoed the actual query, and that comes up fine.

    Please if anyone knows what's going on with this could you help out?

  2. #2
    Join Date
    Mar 2011
    Posts
    1,145
    Try:
    [code]
    $result = mysql_query($query) or die($query . "<br><br>" . mysql_error());
    [code]
    to make sure the query is being processed without errors and, if not, what the error is.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Is the config.php actually opening the connection to the database? I do not see an "open database connection" code in your sample.
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  4. #4
    Join Date
    Apr 2010
    Posts
    227
    Hmmm

    MySQL table name always requires ``

    In your case $query = "INSERT INTO `people` ...

    I dont think your helping us to help you by leaving off your db connection script AND not having SQL errors displayed.

  5. #5
    Join Date
    Mar 2012
    Location
    bangalore,india
    Posts
    27
    Always remember to throw an error message...
    For ex: $result=mysql_query($query);
    if(!$result)
    printf("cannot insert data");
    This will let you know where the probem is !

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
  •  
HTML5 Development Center



Recent Articles