php - Empty SQL after form submission -
i've searched , searched cannot find answer i've made form here it's basic. somehow it's not submitting final data. code is
<form class="form" action="submit.php" method="post"> <table> <tr> <td>team name: </td> <td><input type="text" name="team"></td> </tr> <tr> <td>captains xbox tag: </td> <td><input type="text" name="cap"></td> <tr> <td>captains e-mail:</td> <td><input type="text" name="email"></td> </tr> <tr> <td>team mates: </td> <td><textarea name="teammates" rows="6" cols="50"> please place each team member on new line </textarea><br></td> </tr> <tr> <td>sub team mates: </td> <td><textarea name="subs" rows="2" cols="50"></textarea></td> </tr> </table> <p><input type="submit"></p> </form>
that's form
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "dbname"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "insert tournament1 (team, teammates, cap, email, subs) values ('$_post[team]','$_post[cap]','$_post[email]','$_post[teammates]','$_post[subs]')"; if ($conn->query($sql) === true) { echo "your team has been submitted thankyou. redirected tournaments page shortly"; } else { echo "error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
what doing wrong? connect , because id fills because of autoincremented. else gets lost. in advance guys kyle
so switched around little should work fine..
firstly form, have added isset in you:
<form class="form" action="submit.php" method="post"> <table> <tr> <td>team name: </td> <td><input type="text" name="team"></td> </tr> <tr> <td>captains xbox tag: </td> <td><input type="text" name="cap"></td> <tr> <td>captains e-mail:</td> <td><input type="text" name="email"></td> </tr> <tr> <td>team mates: </td> <td><textarea name="teammates" rows="6" cols="50"> please place each team member on new line </textarea><br></td> </tr> <tr> <td>sub team mates: </td> <td><textarea name="subs" rows="2" cols="50"></textarea></td> </tr> </table> <p><input type="submit" name="sendit"></p> </form>
you'll notice have changed action action="" runs under own page.
followed next php of have added conditions you.
add php submit.php
please note: can add required
@ end of each input field.
if (isset($_post['sendit'])) { $team = $_post['team']; $captain = $_post['cap']; $email = $_post['email']; $mates = $_post['teammates']; $sub = $_post['subs']; if (!empty($team)) { if (!empty($captain)) { if (!empty($email)) { if (!empty($mates)) { if (!empty($sub)) { $sql = "insert `tournament1` (team, teammates, cap, email, subs) values ('$team', '$mates', '$captain', '$email', '$sub')"; if ($conn->query($sql) === true) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . $conn->error; } } else { echo "please add subs.."; } } else { echo "please add mates.."; } } else { echo "please add captains email.."; } } else { echo "please add captains name.."; } } else { echo "please add team name.."; } }
Comments
Post a Comment