Jump to content

Recommended Posts

Ok so here it goes:  I have an array that is attached to a web form. It's function is to ask the user what she has been involved in. There are 3 rows with 4 columns each. The user is required to fill out at least one row but not all three.

Here is the problem.  When I test it out all three rows are entered into the database wether they hold information or not. How do I get the parser to recognize when a row is blank and ignore it before the info is inserted into the database?

 

Here is the PHP Code for the Array

foreach($_POST['Activity'] as $row=>$Act)

{

  $Activity=($Act);

  $Position=($_POST['Position'][$row]);

  $StartDate=($_POST['StartDate'][$row]);

  $EndDate=($_POST['EndDate'][$row]);

  if ($row=="")

  {$row=="NULL";}

 

  $involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate)

  VALUES ('$Activity','$Position','$StartDate','$EndDate')";

Link to comment
https://forums.phpfreaks.com/topic/170624-help-with-arrays/
Share on other sites

foreach($_POST['Activity'] as $row=>$Act)
{
  $Activity=($Act);
  $Position=($_POST['Position'][$row]);
  $StartDate=($_POST['StartDate'][$row]);
  $EndDate=($_POST['EndDate'][$row]);

  if (!empty($Act)) {
  $involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate)
  VALUES ('$Activity','$Position','$StartDate','$EndDate')";
  }

 

I believe thats what you want... also before posting any data to a mysql database you should use mysql_real_escape_string() -> http://ca.php.net/manual/en/function.mysql-real-escape-string.php

Link to comment
https://forums.phpfreaks.com/topic/170624-help-with-arrays/#findComment-899930
Share on other sites

Well try this, you're just asking it to say NULL instead of actually nulling it out.

 

foreach($_POST['Activity'] as $row=>$Act)
{
  $Activity=($Act);
  $Position=($_POST['Position'][$row]);
  $StartDate=($_POST['StartDate'][$row]);
  $EndDate=($_POST['EndDate'][$row]);

  $involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate)
  VALUES (
if isset($Activity){echo '$Activity';},
if isset($Position){echo '$Position';},
if isset($StartDate){echo '$StartDate';},
if isset($EndDate){echo '$EndDate';}
)";

 

That'll not place it into the database if it is not set..

Link to comment
https://forums.phpfreaks.com/topic/170624-help-with-arrays/#findComment-899935
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.