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
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL and GoDaddy - inserting data using PHP problems

    I have been having trouble inserting data into my GoDaddy mysql database using a simple php interface (see code below). (I have a more complex php and MySQL that a webmaster friend of mine setup for my website too). The code seems fine, no error comes up when submitting the data, no login error, etc. but when we check the MySQL database it always stays empty. No data is entered.

    You can check out the more detailed php my friend made

    www.ahs1997.com/alumni.php
    www.ahs1197.com/submit.php

    Any ideas of what might be going on? GoDaddy offered no help whatsever, they said it was beyond theire technical expertise!

    Thanks for any help!

    (www.ahs1997.com/enter-data.com)

    <?php
    $hostname = "h50mysql7.secureserver.net";
    $db_user = "atwaterhigh";
    $db_password = omitted;
    $db_table = "rsvp";


    $db = mysql_connect($hostname, $db_user, $db_password);
    mysql_select_db($db_table,$db);
    ?>
    <html>
    <head>
    <title>How To Insert Data Into MySQL db using form in php</title>
    </head>
    <body>
    How To Insert Data Into MySQL db using form in php<hr>
    <?php
    if (isset($_REQUEST['Submit']))
    {
    # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE
    $sql = "INSERT INTO $db_table(user_name,user_email) values ('$user_name','$user_email')";
    $result = mysql_query($sql ,$db);
    echo "Thank you, Your information has been entered into our database";
    }
    else
    {
    ?>
    <form method="post" action="">
    Name:<br>
    <input type="text" name="user_name">
    <br>
    Email: <br>
    <input type="text" name="user_email">
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    <?php
    }
    ?>
    <body>

    </body>
    </html>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,039
    Thanks
    2
    Thanked 316 Times in 308 Posts
    The code has no error checking and reporting to tell you what it might or might not be doing. The following code is taken from an example in the mysql section of the PHP manual, note the or die('Some message' . mysql_error()) that is used with each mysql function call to give information should the function call fail -

    PHP Code:
    // Connecting, selecting database
    $link mysql_connect('mysql_host''mysql_user''mysql_password') or die('Could not connect: ' mysql_error());
    echo 
    'Connected successfully';
    mysql_select_db('my_database') or die('Could not select database');

    // Performing SQL query
    $query 'SELECT * FROM my_table';
    $result mysql_query($query) or die('Query failed: ' mysql_error()); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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