mysql - PHP Form with required fields -
i want creat form can connect mysql , can insert records have done. want make fields mandatory, username , car example. showing error field required or "name cannot have numbers". stuff that. unable figure out.
some please:
i have index.html
<form action="insert.php" method="post"> nume: <input type="text" name="name"><span class="error">* <?php echo $error;?></span><br> prenume: <input type="text" name="prenume"><br> masina: <input type="radio" name="masina" value="vito"> (vito) <input type="radio" name="masina" value="skoda"> (skoda) <input type="radio" name="masina" value="skoda2"> (skoda) <input type="radio" name="masina" value="audi"> (audi)<br><br> data: <input type="date" name="data"/><br> ora: <input type="time" name="ora"/><br> destinatie:<input type="text" name="destinatie"><br> km la iesire: <input type="text" name="kmiesire"><br> km la intrare: <input type="text" name="kmintrare"><br> <input type="submit">
and insert.php
<?php include "connect.php"; $order = "insert data_employees (name, prenume, masina, data, ora, destinatie, kmiesire, kmintrare) values ('$_post[name]', '$_post[prenume]', '$_post[masina]','$_post[data]','$_post[ora]','$_post[destinatie]', '$_post[kmiesire]','$_post[kmintrare]' )"; if (mysqli_query($con,$order)){ header('location: index.html'); }else{ echo("input data fail"); } ?>
you have check rules before query...
if(empty($_post['name'])){ echo "name required"; } elseif(bla bla){ echo "something" } else { // query.... }
Comments
Post a Comment