I have a form where the user can add inventory into a table within mysql db. I am trying to setup it up so that the user can submit two items at a time.
I have the form working when adding just one item and actually it is also working for adding two items.
The issue I am having is around it adding an empty row is the user does not complete the section for the second item.
Here is my code:
- Code: Select all
... connect to db code
$category = check_input($_POST['category']);
$title = check_input($_POST['title']);
$issue = check_input($_POST['issue']);
$date = check_input($_POST['date']);
$price = check_input($_POST['price']);
$book = check_input($_POST['book']);
$category2 = check_input($_POST['category2']);
$title2 = check_input($_POST['title2']);
$issue2 = check_input($_POST['issue2']);
$date2 = check_input($_POST['date2']);
$price2 = check_input($_POST['price2']);
$book2 = check_input($_POST['book2']);
//Create INSERT query
$qry = "INSERT INTO inventory(category, title, issue, date, price, book, image)
VALUES('$category', '$title', '$issue', '$date', '$price', '$book')";
$qry2 = "INSERT INTO inventory(category, title, issue, date, price, book, image)
VALUES('$category2', '$title2', '$issue2', '$date2', '$price2', '$book2'";
$result = @mysql_query($qry);
$result2 = @mysql_query($qry2);
//Check whether the query was successful or not
if($result && $result2) {
header("location: survey-success1.php");
exit();
}else {
die("Query failed");
}
?>
I tried the if statement below but it throws me a "Query failed"
- Code: Select all
if($name2 == !null){
$qry2 = "INSERT INTO inventory(category, title, issue, date, price, book, image)
VALUES('$category2', '$title2', '$issue2', '$date2', '$price2', '$book2', '$file_name2')";
If anyone has any suggestions, I would greatly appreciate them!


