+ Reply to Thread
Results 1 to 4 of 4

Thread: Writing to MySQL Database please help

  1. #1
    lw2472 is offline x10Hosting Member lw2472 is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    1

    Writing to MySQL Database please help

    Can someone tell me why this isnt working? i am receiving a database not updated error, it should be showing the database updated, id, first name, last name, phone.

    please thank you in advance..

    // <?php
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $phone = $_POST['phone'];

    mysql_connect ("localhost", "lddenter_xxx", "xxx") or die (' Error: ' .mysql_error());
    mysql_select_db ("lddenter_test");

    $query="INSERT INTO commentTable (ID, firstname, lastname, phone)
    VALUES ('NULL','".$firstname."','".$lastname."','".phone. "')";

    mysql_query($query) or die ('Error Updating Database');

    $result = mysql_query ($query);

    echo('Database Updated With: ' . $firstname . ' ' .$lastname . ' ' . $phone);

    ?> //

    the html


    // <body>
    <form id="form1" name="form1" method="post" action="test.php">
    <p>First Name:<br >
    <input name="firstname" type="text" id="firstname" />
    <br >
    <br > Last Name:<br >
    <label>
    <input type="text" name="lastname" id="lastname" >
    </label>
    <br ><br >
    Phone Number:<br >
    <label>
    <input type="text" name="phone" id="phone">
    </label>
    <br ><br >
    <label>
    <input type="submit" name="Submit" id="Submit" value="Submit Customer Information" >
    </label>
    <br >
    </form>
    </body> //
    Last edited by lw2472; 01-14-2010 at 10:43 AM.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Writing to MySQL Database please help

    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    guimar is offline x10Hosting Member guimar is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    13

    Re: Writing to MySQL Database please help

    Quote Originally Posted by lw2472 View Post
    Can someone tell me why this isnt working? i am receiving a database not updated error, it should be showing the database updated, id, first name, last name, phone.

    please thank you in advance..

    // <?php
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $phone = $_POST['phone'];

    mysql_connect ("localhost", "lddenter_xxx", "xxx") or die (' Error: ' .mysql_error());
    mysql_select_db ("lddenter_test");

    $query="INSERT INTO commentTable (ID, firstname, lastname, phone)
    VALUES ('NULL','".$firstname."','".$lastname."','".phone. "')";

    mysql_query($query) or die ('Error Updating Database');

    $result = mysql_query ($query);

    echo('Database Updated With: ' . $firstname . ' ' .$lastname . ' ' . $phone);

    ?> //

    the html


    // <body>
    <form id="form1" name="form1" method="post" action="test.php">
    <p>First Name:<br >
    <input name="firstname" type="text" id="firstname" />
    <br >
    <br > Last Name:<br >
    <label>
    <input type="text" name="lastname" id="lastname" >
    </label>
    <br ><br >
    Phone Number:<br >
    <label>
    <input type="text" name="phone" id="phone">
    </label>
    <br ><br >
    <label>
    <input type="submit" name="Submit" id="Submit" value="Submit Customer Information" >
    </label>
    <br >
    </form>
    </body> //

    you are running the sql iinsert twice, if any of the columns have a unique attribute the second insert fails.

    mysql_query($query) or die ('Error Updating Database');

    $result = mysql_query ($query);
    should be
    $result =mysql_query($query) or die ('Error Updating Database');
    or even more helpful
    $result =mysql_query($query) or die('Error Updating Database:'.mysql_error());
    Last edited by guimar; 01-14-2010 at 02:43 PM. Reason: elaboration

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Writing to MySQL Database please help

    $query="INSERT INTO commentTable (ID, firstname, lastname, phone)
    VALUES ('NULL','".$firstname."','".$lastname."','".phone. "')";


    Don't you mean $phone
    Nothing is always absolutely so.

+ Reply to Thread

Similar Threads

  1. Which is better postgresql or MySQL?
    By Kurai Kumo in forum Scripts & 3rd Party Apps
    Replies: 11
    Last Post: 12-10-2009, 08:17 AM
  2. WP mysql error : Error establishing a database connection
    By orangpelupa in forum Free Hosting
    Replies: 2
    Last Post: 12-19-2007, 05:08 AM
  3. Selecting MySQL database error
    By Nemcon in forum Free Hosting
    Replies: 0
    Last Post: 11-08-2007, 10:28 PM
  4. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers