php - How do I insert a row when MySQL database table is empty? -
i hope isn't repeat question. have searched on find answer no avail.
i want insert row of table. sounds simple enough, if table empty, not work. can't figure out why. long there 1 row in table, works fine. appreciated. thanks.
my code:
<?php $fname = $_post['fname']; $mi = $_post['mi']; $lname = $_post['lname']; $phone = $_post['phone']; $email = $_post['email']; $add1 = $_post['add1']; $add2 = $_post['add2']; $city = $_post['city']; $state = $_post['state']; $zip = $_post['zip']; $con = mysqli_connect("localhost","database_username","database_password","database"); $sql1 = "insert employee (fname, mi, lname, phone, email, add1, add2, city, state, zip) values ('$fname', '$mi', '$lname', '$phone', '$email', '$add1', '$add2', '$city', '$state', '$zip')"; mysqli_query($con,$sql1); mysqli_close($con); ?>
your code correct may times data have special characters such \ / ? etc. suggest change variable of code from
$fname = $_post['fname'];
to
$fname = addslashes($_post['fname']);
then try it done
Comments
Post a Comment