Why doesn't this Work?

Eric600Eric600 San Diego

I wrote a PHP script to place 12 items into a MYSQL database on a web site, it didn't work! A software engineer re-wrote it. It still doesn't work. Does anyone know what's wrong? Here's the code:

<?php
// Your database info
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '""';
$db_name = 'employees';
if (!empty($_POST))
{
$con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if ($con‐>connect_error)
die('Connect Error (' . mysqli_connect_errno() . ') '.
mysqli_connect_error());
$sql = "INSERT INTO table1 (first, last, mi, address, city, state, zip, phone, email, ss, dob, security) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
if (!$stmt = $con‐>prepare($sql))
die('Query failed: (' . $con‐>errno . ') ' . $con‐>error);
if (!$stmt‐>bind_param('ssi',$_POST['fist'],$_POST['last'],$_POST['mi'],$_POST['address'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['phone'],$_POST['email'],$_POST['ss'],$_POST['dob'],$_POST['security']))
die('Bind Param failed: (' . $con‐>errno . ') ' . $con‐>error);
if (!$stmt‐>execute())
die('Insert Error ' . $con‐>error);
echo "Record added";
$stmt‐>close();
$con‐>close();

Comments

  • Next time include error messages.

  • Are you sending the form with POST or with GET method? As your if statement seems to imply that only POST messages would be added

  • Eric600Eric600 San Diego

    I'm sending the form with POST method. As of now, there are no error messages. This php is actually included on the top of the html form.

  • You need to give a little more data, like, are you sure that you are running on a php server, and is the file of your html form also named like .php? can you see the message "Record added" inside your html after you submitted the request?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories