Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6116359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:11:50+00:00 2026-05-23T15:11:50+00:00

First time poster, long time lurker :) I have a form setup that posts

  • 0

First time poster, long time lurker 🙂
I have a form setup that posts data for multiple rows in a single table with seven colums to a php function to insert it as new records in a database. The form is working great, however, if one of the rows in the form is left unfilled then the php function is creating a blank row in the database. I am attempting to figure out how to avoid this. I am certain it has nothing to do with the form itself, and rather has to do with the php. Please have a look at it. I’m totally open to suggestions.

<?php
require("header.php");
require("dbinc.php");
foreach($_POST['card'] as $row=>$cardcounted) 
{
    $model=$_POST['model'];
    $serial=$_POST['serial'][$row];
    $card=$cardcounted;
    $status=$_POST['status'];
    $date=$_POST['date'];
    $location=$_POST['location'];
    $query = mysql_query("INSERT INTO receivers (`id`, `model`, `serial`, `card`, `status`, `date`, `location`) VALUES ('null','$model','$serial','$card','$status','$date','$location')");

    if(!isset($serial[$row]) || $serial[$row] == '') {
        // error message here, redisplay form if desired
    } else {
        // no errors - process data
    } 

    if (!$query)
    {
        die('Error: ' . mysql_error());
    }
}
echo $row+1 . " record(s) added";

mysql_close()
?>

I added in the !isset on the serial numbers by row to check for null posts but am unsure as to how to incorporate that properly. i think im on the right track, just need that little push 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:11:51+00:00Added an answer on May 23, 2026 at 3:11 pm

    First choice is to use JavaScript validation to find out invalid form submits, Some users may disable JavaScript, so its always recommended to do server-side validations

    So write a method like

    isValid($postArray) {
      foreach($postArray as $key => $value) {
        if ($value == "") {
           return false;    
        }
      }
      return true;
    }
    

    If form field names and db column names are similar you can use

    $sql = "INSERT INTO receivers ";
    $keys = "(";
    $values = "(";
    foreach($postArray as $key => $value) {
        if ($value != "") {
           $keys += $key;
           $values += $value;
        }
    }
    
    $sql = $sql + $keys +" VALUES "+ $values;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long term lurker, first time poster here. I have written a class to model
long time reader/first time poster here. So I've got a checkbox array that posted
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
long time reader, first time poster. I’m coming with an issue that many of
Long time lurker, first time poster. I'm making a ServerConnection module to make it
(first time poster, long time visitor via Google) I'm trying to extract the contents
first time poster, long time reader so be gentle with me :) See the
Long time reader, first time poster asks: After many weeks of google and forum
Long time reader, first time poster. I'm a big noob when it comes to
Long time reader, first time poster. Working on a web site at http://www.howardpitch.com/ ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.