0

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?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by brewbuff
1
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'";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.