Empty rows I guess you would say- (sorry, I am a rookie)
For example, I get...
id:1 name: (blank)
id:2 name: (blank)
and so on.
No errors running the code I posted- in fact I have tried other error handling and confirmations such as affected_rows() which all return positive numbers. (example below).
Perhaps the syntax issue you describe is the trouble- although, I am not familiar with the curly braces and the "| DEFAULT" part... My end goal, in fact, is to insert a record(with 5 defined fields) into a table with 15 or so possible fields.
Here's a related, more complex piece of my code that started this problem:
(please excuse the mess)
$mysqli= new mysqli('localhost',$user,$password,$database);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
else {
echo "connected to $database<br>";
}
if ($stmt = $mysqli->stmt_init()){
$sql= "INSERT INTO customers (name, street, city, state) VALUES (?,?,?,?)";
}
else {
echo "Init problem".$mysqli->error;
exit;
}
if ($stmt = $mysqli->prepare($sql)){
echo $stmt->param_count." parameters<br>";
if (!$stmt){
echo "error: ".$mysqli->error;
exit;
}
if (!$stmt->bind_param("ssss", $name,$street,$city,$state)){
printf("Bind error: %s<br>", $mysqli->error);
}
echo $stmt->param_count." parameters<br>";
$name = 'Joe';
$street = 'mystreet';
$city = 'Westerville';
$state = 'OH';
/* execute prepared statement */
$stmt->execute() or die("Error: ".$stmt->error);
printf("%s,%s,%s,%d Row inserted.<br>",$street,$city,$state,$stmt->affected_rows);
printf("Inserted row: %d <br>",$mysqli->insert_id);
$one=$mysqli->insert_id;
$name = 'Bob';
$street = 'street3';
$city = 'Westerville3';
$state = 'OH';
/* execute prepared statement */
$stmt->execute() or die("Error: ".$stmt->error);
printf("%s,%s,%s,%d Row inserted.<br>",$street,$city,$state,$stmt->affected_rows);
printf("Inserted row: %d <br>",$mysqli->insert_id);
$two=$mysqli->insert_id;
$name = 'Jim';
$street = 'anew street 2';
$city = 'Westerville 2';
$state = 'OH';
/* execute prepared statement */
$stmt->execute() or die("Error: ".$mysqli->error);
printf("%s,%s,%s,%d Row inserted.<br>",$street,$city,$state,$stmt->affected_rows);
printf("Inserted row: %d <br>",$mysqli->insert_id);
$three=$mysqli->insert_id;
$stmt->close();
echo "<br>$one,$two,$three";
}
else {
/* Error */
echo "$sql";
printf("Prepared Statement Error: %s<br>", $mysqli->error);
}
/* close statement and connection */
/* close connection */
$mysqli->close();
?>
My echos/printf's tell me what I want to hear, but....
My results: 3 new rows in the DB. The first is blank, then strange results elsewhere. Row 2 [city]="Jim" and row 3 [city]="Bob".
--Q: after taking a 2nd look at your comment about the syntax- are you saying I cannot use a prepared/bound statement (?) unless I provide a value for all available fields?