Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2013
    Posts
    8

    Unanswered: PHP/html form to insert data into MySQL Databsase

    Hello all,

    I am working on an project that takes an html form, then with PHP code enters data into a MySQL database. At this point, I do not think my code is the issue. But I am confused on the aspect of after I click the
    Submit" button on the form, it should go through a database connection, entering the data - and display an error if unsuccessful. However, when I run it through my browser, after I "Submit" - it just pulls up a blank page stating the directory of the file on the address bar. (C:/Desktop/Folder... etc.)
    I don't know if this is a stupid question or not - but am I missing a step?
    Do I have to upload the php files somewhere to use them to enter MySQL data? (I have MySQL workbench installed).
    Looking for any help - thanks so much!

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Can you execute any PHP locally? Vanilla HTML files can be rendered by any browser but PHP requires software to work.

    This will probably help: Microsoft Web Platform - PHP on Windows
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2013
    Posts
    8
    I did make a "test" file just to see if I could run any PHP with a result, and it did return a value. I will try and download Microsoft Web Platform - PHP on Windows - thanks for the advice! I did have a feeling I was missing something to make it execute correctly... thanks again!

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Or download one of the 'apache and friends' packages such as xampp
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by JDA23 View Post
    I did make a "test" file just to see if I could run any PHP with a result, and it did return a value.
    Can you share your code for this?
    George
    Home | Blog

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Id suggest you run phpinfo to check the installation
    place the follwing in a file with php extension in your sites web folder and then run it.
    PHP Code:
    <PHP>
    echo 
    phpinfo();
    </
    php
    running phpinfo in a php script will prove if your PHP installation is working

    https://www.google.co.uk/webhp?sourc...q=echo+phpinfo

    ..mnd youif you instasll PHP and your server using XAMPP the phpinfo output is available from the XAMPP home page on your local server
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Dec 2013
    Posts
    8
    Thank you all for the suggestions - here is my code I have:
    HTML:
    Code:
    <html> 
     <head><title>title - removed for thread</title></head> 
     <body> 
     <h2>Entry Form</h2><p> 
     <form action="insert.php" method="post"> 
     <table> 
     <td>Name:</td><td><input type="text" name="name" /></td>
     <tr><td colspan="2" align="center"><input type="submit" /></td></tr> 
     </table> 
     </form> 
     </body> 
     </html>
    INSERT.PHP
    PHP Code:
    <?php
    $username 
    'root';
    $password 'root';
    $hostname 'localhost';
    $db_database 'removedforthread';

    //connection to the db
    $db_server mysql_connect($db_hostname$db_username$db_password)
       or die(
    "Unable to connect to MySQL: " mysql_error());

    mysql_select_db($db_database)
       or die(
    "Unable to select database: " mysql_error());

    //get values from form
    $name=$_POST['name'];

    //insert data into mysql
    $sql="INSERT INTO removedtablenameforthread(name)VALUES('$name')";
    $result mysql_query($sql);

    // if successfully insert data into database, displays message "Successful".
    if($result)
    {
    echo 
    "SUCCESSFULLY ENTERED";
    }
    else {
    echo 
    "ERROR";
    }

    // close mysql
    mysql_close();
    ?>
    Thank you! I may just have an issue with the sql connection - but I never see an error stating so...

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try php info to prove your php installation is working
    having proved that (it will also inform you anbout its db connectivity) then run your script

    however as to why your script isn't doing naything:-
    my money is on there being an error in your code and your error _rpeorting level is set fto default and thats too low for development purposes

    https://www.google.co.uk/webhp?sourc...rror+reporting
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Dec 2013
    Posts
    8
    I did test with:
    PHP Code:
    echo phpinfo(); 
    and the webpage displayed:
    echo phpinfo();


    Later this evening when I am using the computer with the SQL server installed, I will try the Microsoft Web Platform - PHP on Windows this evening. hopefully that will help me. Thanks again!

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    That suggests to me the php interpreter isnt installed. You should see a whole pile of information about the setup

    Are you using mysql or sql server for the db...

    if mysql then as said before I strongly recommend using xampp in place if the microsoft php install. Xampp installs various elements that will make development easier
    Last edited by healdem; 06-02-14 at 16:50.
    I'd rather be riding on the Tiger 800 or the Norton

  11. #11
    Join Date
    Dec 2013
    Posts
    8
    Hello all - I finially got this working, thought I would share.
    I watched the following YouTube video:
    http://www.youtube.com/watch?v=UKbEzmMliNM​ and downloaded PHP, Apache Server, (already had MySQL installed).
    For some reason, I could only get the code to work with sqli format, but I placed my two files (html and php) in the folder stated in the video. Then, to access the form I typed: localhost/filename.html
    Hope this helps anyone else with a similar issue!

Posting Permissions

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