Code: Select all
IF the form is posted THEN
IF the required fields are not empty THEN
EXECUTE the query and show results
ELSE
SHOW the user what was wrong
SHOW the form
END IF
ELSE
SHOW the form
END IF
Moderator: General Moderators
Code: Select all
IF the form is posted THEN
IF the required fields are not empty THEN
EXECUTE the query and show results
ELSE
SHOW the user what was wrong
SHOW the form
END IF
ELSE
SHOW the form
END IF
Code: Select all
if($_POST['$strAuthor'] == "" || $_POST['$strTitle'] == "")
{
print "An error has occured. Author and Title require input";
}
else {
...............
}That's not going to work. You quoted your array index variables.DeFacto wrote:try that way.Code: Select all
if($_POST['$strAuthor'] == "" || $_POST['$strTitle'] == "") { print "An error has occured. Author and Title require input"; } else { ............... }
Code: Select all
$_POST['variable'] isn't the same as $_POST['$variable'];
Have you written code that is in line with the pseudo code I posted earlier?sirTemplar wrote:no one to check what's wrong?
Code: Select all
{$Author = $_POST['Author'];}
{$Title = $_POST['Title'];}
if($_POST['Author'] == "" || $_POST['Title'] == "")
{
print "An error has occured. Author and Title require input";
}
else
{
$result = mysql_query ("SELECT * FROM catalogue
WHERE Author LIKE '%$Author%'
AND Title LIKE '%$Title%'
ORDER BY Title ASC, Author
",$conn);
$totalrows = mysql_num_rows($result);
if ($row = mysql_fetch_array($result)) {
do { Code: Select all
<?php
$Author = $_POST['Author'];
$Title = $_POST['Title'];
if (empty($Author) && empty($Title)) {
print "An error has occured. Either Author or Title must be entered";
exit;
}
$sql = 'SELECT * FROM catalogue
WHERE ';
if ($Author) {
$sql .= 'Author LIKE \'%' . mysql_real_escape_string($Author) . '%\'';
}
if ($Title) {
if ($Author) {
$sql .= ' AND ';
}
$sql .= 'Title LIKE \'%' . mysql_real_escape_string($Title) . '%\'';
}
$sql .= 'ORDER BY Title ASC, Author';
if (!$result = mysql_query($sql)) {
die('Query failed: ' . mysql_error());
}
$totalrows = mysql_num_rows($result);
?>