samedi 25 juin 2016

Form entry inserts a blank into database

I created an attendance form and when I submit the form it redirects me to submit.php. However, when I check in phpmyadmin I get a blank row except for the timestamp. I asked Stackoverflow about entering multi-row queries . Also I looked at Submitting Form Returns Blank info Submit.php <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "root", "passowrd", "database"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $FName = mysqli_real_escape_string($link, $_POST['FName']); $LName = mysqli_real_escape_string($link, $_POST['LName']); $Mark = mysqli_real_escape_string($link, $_POST['Mark']); // attempt insert query execution $sql = "INSERT INTO database (FName,LName,Mark) VALUES ('$FName','$LName','$Mark')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not take attendence " . mysqli_error($link); } // close connection mysqli_close($link); ?> tester.php(form) <html> <head> </head> <body> <?php if(isset($_POST[ 'search'])) { $valueToSearch=$ _POST[ 'valueToSearch']; // search in all table columns // using concat mysql function $query="SELECT * FROM `students` WHERE CONCAT(`FName`, `LName`) LIKE '%" .$valueToSearch. "%'"; $search_result=f ilterTable($query); } else { $query="SELECT * FROM `students`" ; $search_result=f ilterTable($query); } // function to connect and execute the query function filterTable($query) { $connect=mysqli_connect( "host", "username", "password", "database"); $filter_Result=m ysqli_query($connect, $query); return $filter_Result; } ?> <form action="submit.php" method="post"> <table border="1" align="center"> <tr> <th>First Name</th> <th>Last Name</th> <th>Mark</th> </tr> <?php while($row=mysqli_fetch_array($search_result)):?> <tr> <!---<tdphp echo $row['FName'];></td>---> <td> <input type="text" name="FName" value="<?php echo $row['FName']?>" /> </td> <!---<td><php echo $row['LName'];?></td>---> <td> <input type="text" name="LName" value="<?php echo $row['LName']?>" /> </td> <td> <select name="Mark" id="Mark"> <option value="Present">Present</option> <option value="Tardy">Tardy</option> <option value="Absent">Absent</option> </select> </td> <?php endwhile;?> </tr> <table align="center"> <tr> <td> <input type="submit" value="Submit"> </td> </tr> </table> </table> </table> </form> </body> </html> This is The Database Structure, I thought it would help.

Aucun commentaire:

Enregistrer un commentaire