Hi,
I am having problems with the code below, i donn’t get any errors, but it just does not go into the IF statement and hence does not do the INSERT statement.
So i try checking to see where the code breaks:
public function insertAuthor()
{
$authArray = array_map('mysql_real_escape_string',
$_POST['author']);
$query = sprintf('SELECT Pid, Pname FROM People
WHERE Pname = IN(\\'%s\\')', implode('\\',\\'', $authArray));
$result = mysql_query($query);
if($result && mysql_num_rows($result) > 0)
{
die('here');
$PCorder = 0;
$sqlValues = array();
while(list($PId, $PName) = mysql_fetch_row($result))
{
if(in_array($PName, $authArray))
$sqlValues[] = sprintf("(%d, %d, now(), 0)",
$PId, $PCorder++ );
}
$sql = "INSERT INTO PeopleCon(Pid, PCorder,
PCdateadded, PCdeleted) VALUES \
";
$sql .= implode(",\
", $sqlValues);
die ("Generated SQL Query:<pre>$sql</pre>");
$result = mysql_query($sql);
}
}
See die(‘here’);
Basically the code does not reach the IF statement, it does not die, so that means it does not like this line:
if($result && mysql_num_rows($result) > 0)...
I tried echoing out the $query to see what it was showing and it displays like this:
SELECT Pid, Pname FROM People
WHERE
Pname = IN('Testing 1','Testing 2')
So this also seems fine, that means the IF statement is not firing.
Any ideas?
Thanks