This is currently the code I am using:

<?php

//connect to database
include 'global.php';

$case = date(ymdHis);

 //get form data
 $p1_firstname = addslashes(strip_tags($_POST['p1_firstname']));
 $p1_lastname = addslashes(strip_tags($_POST['p1_lastname']));
 $p2_firstname = addslashes(strip_tags($_POST['p2_firstname']));
 $p2_lastname = addslashes(strip_tags($_POST['p2_lastname']));
 $p3_firstname = addslashes(strip_tags($_POST['p3_firstname']));
 $p3_lastname = addslashes(strip_tags($_POST['p3_lastname']));
 $city = addslashes(strip_tags($_POST['city']));

 //register into database
 $register_case = mysql_query ("INSERT INTO cases VALUES 
 ('$case','$p1_firstname','$p1_lastname','$city'),
 ('$case','$p2_firstname','$p2_lastname','$city'),
 ('$case','$p3_firstname','$p3_lastname','$city')");


?>

The problem with this is that there is often only data for p1. What can I do to check if there is data in a specific name field before inserting it as a row?

Member Avatar for brewbuff
if (!empty($p1_lastname)) $register_case = mysql_query ("INSERT INTO cases VALUES '$case','$p1_firstname','$p1_lastname','$city'";
if (!empty($p2_lastname)) $register_case = mysql_query ("INSERT INTO cases VALUES '$case','$p2_firstname','$p2_lastname','$city'";
if (!empty($p3_lastname)) $register_case = mysql_query ("INSERT INTO cases VALUES '$case','$p3_firstname','$p3_lastname','$city'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.