Hi,
I was wondering if this was possible, i am INSERTING an array of authors like so in a table, see insertAuthor() method below:
<?php
class People {
public function checkNameExists(){
$query = "SELECT * FROM People WHERE Pname = '". mysql_real_escape_string($_POST['Pname'])."'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0):
$row = mysql_fetch_array($result);
return true;
else:
return false;
endif;
}
public function insertAuthor(){
$callback = create_function('$author','return "(\\'".mysql_real_escape_string($author)."\\',NOW(),0)";');
$sql = sprintf(
'INSERT INTO People (Pname, Pdateadded, Pdeleted) VALUES %s'
,implode(',',array_map($callback,$_POST['author']))
);
$result = mysql_query($sql);
return "Successfully added author";
}
public function insertAuthorCon(){
$sql = "INSERT INTO PeopleCon
(Pid, PCorder, PCdateadded, PCdeleted) VALUES
(
'MAX ID WILL GO HERE',
(select MAX(PCorder) + 1),
now(),
0
)";
$result = mysql_query($sql);
return "Successfully added event";
}
}
?>
However what i need to do is, check to see if an Author exists, if so INSERT into a table called PeopleCon, if the Author does NOT exist i need to INSERT into 2 different tables, People and PeopleCon…
The reason i have the 2 tables is because People simply holds the persons personal details, but PeopleCon holds details linking to different tables.
So i already have the authors looping through and INSERTING into the People table, but i now need to check to see if the author exists which will be checked by the name.
I do this in the front end:
if(isset($_POST['add_author'])):
People::insertAuthor();
endif;
So now i need to change the checkNameExists AND insertAuthorCon method and somehow combine the 3 so i can accomplish this.
Is this possible?
I would appreciate any help.
Thanks