The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Help with setting up a MySQL database

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #27510

    I am learning PHP with a book I bought and I need to setup a database to collect information from a form. I created a database through phpmyadmin and then I created the tables. I have added the code to the PHP script to send the info from the form to the database, however, when I fill out the form and click send, nothing gets added to the database. I have no idea what I am doing wrong. Thanks!

    Here is the code:

    <h2>Aliens Abducted Me – Report an Abduction</h2>

    <p>Share your story of alien abduction:</p>
    <form method="post" action="report.php">
    <label for="firstname">First name:</label>
    <input type="text" id="firstname" name="firstname" /><br />
    <label for="lastname">Last name:</label>
    <input type="text" id="lastname" name="lastname" /><br />
    <label for="email">What is your email address?</label>
    <input type="text" id="email" name="email" /><br />
    <label for="whenithappened">When did it happen?</label>
    <input type="text" id="whenithappened" name="whenithappened" /><br />
    <label for="howlong">How long were you gone?</label>
    <input type="text" id="howlong" name="howlong" /><br />
    <label for="howmany">How many did you see?</label>
    <input type="text" id="howmany" name="howmany" /><br />
    <label for="aliendescription">Describe them:</label>
    <input type="text" id="aliendescription" name="aliendescription" size="32" /><br />
    <label for="whattheydid">What did they do to you?</label>
    <input type="text" id="whattheydid" name="whattheydid" size="32" /><br />
    <label for="fangspotted">Have you seen my dog Fang?</label>
    Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" />
    No <input id="fangspotted" name="fangspotted" type="radio" value="no" /><br />
    <img src="fang.jpg" width="100" height="175"
    alt="My abducted dog Fang." /><br />
    <label for="other">Anything else you want to add?</label>
    <textarea id="other" name="other"></textarea><br />
    <input type="submit" value="Report Abduction" name="submit" />


    $name = $_POST . ‘ ‘ . $_POST;
    $when_it_happened = $_POST;
    $how_long = $_POST;
    $how_many = $_POST;
    $alien_description = $_POST;
    $what_they_did = $_POST;
    $fang_spotted = $_POST;
    $email = $_POST;
    $other = $_POST;

    $dbc = mysql_connect(‘localhost’, ‘name’, ‘password’, ‘database’)
    or die(‘Error connecting to MySQL server’);

    $query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
    "how_many, alien_description, what_they_did, fang_spotted, other, email) " .
    "VALUES (‘$first_name’, ‘$last_name’, ‘$when_it_happened’, ‘$how_long’, ‘$how_many’, " .
    "’$alien_description’, ‘$what_they_did’, ‘$fang_spotted’, ‘$other’, ‘$email’)";

    $result = mysql_query($dbc, $query)
    or die(‘Error querying database.’);


    echo ‘Thanks for submitting the form.<br />’;
    echo ‘You were abducted ‘ . $when_it_happened;
    echo ‘ and were gone for ‘ . $how_long . ‘<br />’;
    echo ‘Number of aliens: ‘ . $how_many . ‘<br />’;
    echo ‘Describe them: ‘ . $alien_description . ‘<br />’;
    echo ‘The aliens did this: ‘ . $what_they_did . ‘<br />’;
    echo ‘Was Fang there? ‘ . $fang_spotted . ‘<br />’;
    echo ‘Other comments: ‘ . $other . ‘<br />’;
    echo ‘Your email address is ‘ . $email;



    i presume you have blanked all the user name and password fields for the mysql database?

    "deadlow" wrote:
    $dbc = mysql_connect(‘localhost’, ‘name’, ‘password’, ‘database’)
    or die(‘Error connecting to MySQL server’);

    otherwise the default user-name is "root" password is nothing

    hope this helps


    ps you might want to try something simpler first

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.