0

I'm working on a project and I'm having a bit of trouble getting my form data to post to my SQL database. At first the auto inc ID values were working any time I'd submit the form, but no other data would post... now nothing at all happens... I'm very rusty with php... anyways here is what I have so far.

insert.php

<?php
include ("connect.php");
$sql = "INSERT INTO 'tc_db'.'teamchiefs' ('lastname',  'firstname','unit','datecert','initial')
VALUES ('$_POST[lastname]','$_POST[firstname]','$_POST[unit]','$_POST[datecert]')";
if (!mysqli_query($con,$sql))
{
die('Error:' . mysqli_error(@con));
}
echo "Record Added";
mysqli_close($con);
?>

And my form.html file... clipped down to save space.

<body>
<ul>

<form action="insert.php" method="post">
"sprytextfield1">
<label>Last Name:
  <input type="text" name="lastname" id="lastname" />
</label>
<label>First Name:
    <input type="text" name="firstname" id="firstname" />
  </label>
<label>Middle Initial
  <input name="initial" type="text" id="initial" size="5" maxlength="1" />
</label>

...etc

//spry widget javascript stuff here

</form>
</ul>
</div>
</body>

My sql tables are

ID - BIGINT(20) - A_I
lastname - VARCHAR(60)
firstname - VARCHAR(60)
unit - VARCHAR(6)
datecert - YEAR(4)
initial - VARCHAR(1)

I appreciate any help.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Adam Sauer
  • 13
  • 3

2 Answers2

1
INSERT INTO 'tc_db'.'teamchiefs'

Use backticks for table and column names

INSERT INTO `tc_db`.`teamchiefs` 
Mihai
  • 26,325
  • 7
  • 66
  • 81
0

You have declared that you're inserting into five columns ('lastname', 'firstname','unit','datecert','initial') but you're only providing four values ('$_POST[lastname]','$_POST[firstname]','$_POST[unit]','$_POST[datecert]'). Looks like you're missing a value for initial. That's will cause your query to fail.

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Ok, I added that in, still not posting though... $sql = "SELECT * FROM `teamchiefs` LIMIT 0, 30 "; No results :( – Adam Sauer Oct 16 '13 at 20:07