this server acknowledges php connection, values entered in form not stored empty table rows.
the php code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>aliens abducted me - report abduction</title> </head> <body> <h2>aliens abducted me - report abduction</h2> <?php $name = $_post'firstname'; $last_name =$_post'lastname'; $when_it_happened = $_post'whenithappened'; $how_long = $_post'howlong'; $how_many = $_post'howmany'; $alien_description = $_post'aliendescription'; $what_they_did = $_post'whattheydid'; $fang_spotted = $_post'fangspotted'; $email = $_post'email'; $other = $_post'other'; $dbc = mysqli_connect('localhost', 'root', 'password', 'aliendatabase') or die('error connecting mysql server'); $query = "insert 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 = mysqli_query($dbc, $query) or die('error querying database'); mysqli_close($dbc); echo 'thanks submitting form.<br />'; echo 'you abducted ' . $when_it_happened; echo ' , gone ' . $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 ' . $email; ?> </body> </html>
here's form/html code
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>aliens abducted me - report abduction</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>aliens abducted me - report abduction</h2> <p>share 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 email address?</label> <input type="text" id="email" name="email" /><br /> <label for="whenithappened">when did happen?</label> <input type="text" id="whenithappened" name="whenithappened" /><br /> <label for="howlong">how long gone?</label> <input type="text" id="howlong" name="howlong" /><br /> <label for="howmany">how many did 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 you?</label> <input type="text" id="whattheydid" name="whattheydid" size="32" /><br /> <label for="fangspotted">have seen 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 want add?</label> <textarea id="other" name="other"></textarea><br /> <input type="submit" value="report abduction" name="submit" /> </form> </body> </html>
the code straight book. php v5.6.22 , latest apache , mysql. can tell me might wrong or i'm doing wrong
see => $_post'firstname';
, other post arrays?
they missing brackets []
them.
so change $_post['firstname'];
, same others also.
error reporting have helped here, reading manual on forms.
plus, should use conditional !empty()
against post arrays going in database.
this trigger errors if of left empty, should database not accept null values.
you have missing quote ('$first_name,
, concatenates in query.
this needed rewritten such:
$query = "insert 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')";
footnotes:
your present code open sql injection. use prepared statements, or pdo prepared statements.