Page 1 of 1

Yet, another form faux pah!

Posted: Mon Dec 06, 2010 1:34 pm
by cap2cap10
Greetings again, php Technorati. Ok, I am trying to create a script that will access database and search for specific criteria in each row. I have about 4 search criteria on one page, but when I try to search via home phone # or cell phone or email, I get no results found. The data that I input in corresponds to the data in my database, but before it searches, It returns no matches. This is because of the MySQL Syntax. Here is the code:

Code: Select all

<?php
require 'open_db.php';
if (isset($_POST['submit_3']))
{
$LN=$_POST['markLN'];
$query = "SELECT * FROM initials WHERE LN ='$markLN'";
$result = mysql_query($query) or die(mysql_error());
$check = '0';

	while($row = mysql_fetch_assoc($result))
	{
		if ($check % 2 == 0)
			{
				$text1 .= '<tr width="970">';
			}
			else
			{
				$text1 .= '<tr bgcolor="#F89858">';
			}
            $text1 .= '<td width="96" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row['candidateID'].'</span></td>';
            $text1 .= '<td width="226" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row['FN'].' '.$row['LN'].'</span></td>';
            $text1 .= '<td width="206" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row['email'].'</span></td>';
            $text1 .= '<td width="76" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1"><b>'.$row['progress'].'</b></span></td>';
            $text1 .= '<td width="106" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row['add_date'].'</span></td>';
            $text1 .= '<td width="96" align="center" valign="middle" style="padding-left: 15px;"><span class="style1"><a href="view_mark.php?ID='.$row['ID'].'" class="style1">View Mark</a></span></td>';
            $text1 .= '</tr>';

	$check ++;
		}

 if($check == 0)
	{
		$text1 .= '<tr width = "970">';
		$text1 .= '<td align="center" width="100%"><span class="style1"><b>No Matches found!</b></span></td>';
		$text1 .= '</tr>';
	}
     echo $text1;
 }
elseif (isset($_POST['submit_4']))
{
$home_1=$_POST['home_1'];
$home_2=$_POST['home_2'];
$home_3=$_POST['home_3'];

$query = "SELECT * FROM initials WHERE home_1 ='$home_1' AND home_2 ='$home_2' AND home_3 ='$home_3'";
$result = mysql_query($query) or die(mysql_error());
$check = '0';

	while($row1 = mysql_fetch_assoc($result))
	{
		if ($check % 2 == 0)
			{
				$text2 .= '<tr width="970">';
			}
			else
			{
				$text2 .= '<tr bgcolor="#F89858">';
			}
             $text2 .= '<td width="74" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row1['candidateID'].'</span></td>';
            $text2 .= '<td width="224" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row1['FN'].' '.$row1['LN'].'</span></td>';
            $text2 .= '<td width="204" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row1['email'].'</span></td>';
            $text2 .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1"><b>'.$row1['progress'].'</b></span></td>';
            $text2 .= '<td width="84" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row1['add_date'].'</span></td>';
            $text2 .= '<td width="64" align="center" valign="middle" style="padding-left: 15px;"><span class="style1"><a href="view_mark.php?ID='.$row1['ID'].'" class="style1">View Mark</a></span></td>';
            $text2 .= '</tr>';
$check ++;
		}

	if($check == 0)
	{
		$text2 .= '<tr width = "970">';
		$text2 .= '<td align="center" width="100%"><span class="style1"><b>No Matches found!</b></span></td>';
		$text2 .= '</tr>';
	}
     echo $text2;
 }
elseif (isset($_POST['submit_5']))
{
$cell_1=$_POST['cell_1'];
$cell_2=$_POST['cell_2'];
$cell_3=$_POST['cell_3'];

$query = "SELECT * FROM initials WHERE cell_1 ='$cell_1' AND cell_2 ='$cell_2' AND cell_3 ='$cell_3'";
$result = mysql_query($query) or die(mysql_error());
$check = '0';

	while($row2 = mysql_fetch_assoc($result))
	{
		if ($check % 2 == 0)
			{
				$text3 .= '<tr width="970">';
			}
			else
			{
				$text3 .= '<tr bgcolor="#F89858">';
			}
			$text3 .= '<td width="74" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row2['candidateID'].'</span></td>';
            $text3 .= '<td width="224" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row2['FN'].' '.$row2['LN'].'</span></td>';
            $text3 .= '<td width="204" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row2['email'].'</span></td>';
            $text3 .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1"><b>'.$row2['progress'].'</b></span></td>';
            $text3 .= '<td width="84" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row2['add_date'].'</span></td>';
            $text3 .= '<td width="64" align="center" valign="middle" style="padding-left: 15px;"><span class="style1"><a href="view_mark.php?ID='.$row2['ID'].'" class="style1">View Mark</a></span></td>';
            $text3 .= '</tr>';
$check ++;
		}

	if($check == 0)
	{
		$text3 .= '<tr width = "970">';
		$text3 .= '<td align="center" width="100%"><span class="style1"><b>No Matches found!</b></span></td>';
		$text3 .= '</tr>';
	}
     echo $text3;

}
elseif (isset($_POST['submit_6']))
{
$email=$_POST['email'];

$query = "SELECT * FROM initials WHERE email ='$email'";
$result = mysql_query($query) or die(mysql_error());
$check = '0';

	while($row3 = mysql_fetch_assoc($result))
	{
		if ($check % 2 == 0)
			{
				$text4 .= '<tr width="970">';
			}
			else
			{
				$text4 .= '<tr bgcolor="#F89858">';
			}
            $text4 .= '<td width="74" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row3['candidateID'].'</span></td>';
            $text4 .= '<td width="224" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row3['FN'].' '.$row3['LN'].'</span></td>';
            $text4 .= '<td width="204" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row3['email'].'</span></td>';
            $text4 .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1"><b>'.$row3['progress'].'</b></span></td>';
            $text4 .= '<td width="84" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$row3['add_date'].'</span></td>';
            $text4 .= '<td width="64" align="center" valign="middle" style="padding-left: 15px;"><span class="style1"><a href="view_mark.php?ID='.$row3['ID'].'" class="style1">View Mark</a></span></td>';
            $text4 .= '</tr>';
$check ++;
  }

 if($check == 0)
	{
		$text4 .= '<tr width = "970">';
		$text4 .= '<td align="center" width="100%"><span class="style1"><b>No Matches found!</b></span></td>';
		$text4 .= '</tr>';
	}
     echo $text4;
 mysql_close();
}
?>
Here is the culprit:

Code: Select all

 if($check == 0)
	{
		$text4 .= '<tr width = "970">';
		$text4 .= '<td align="center" width="100%"><span class="style1"><b>No Matches found!</b></span></td>';
		$text4 .= '</tr>';
	}
I have to many of them. I need to reorganize this code so that after it checks the conditions and they are false, it will issue the above
code as the output. Can someone show me the way?
Thanks in advance,

Batoe
____________________________________________
"The road to success is filled with obstacles, but also success!"

Re: Yet, another form faux pah!

Posted: Tue Dec 07, 2010 9:51 am
by social_experiment

Code: Select all

<?php 
$LN=$_POST['markLN'];
$query = "SELECT * FROM initials WHERE LN ='$markLN'"; 
?>
This could be a typo but where do you define $markLN in the script?

Re: Yet, another form faux pah!

Posted: Tue Dec 07, 2010 4:53 pm
by cap2cap10
Thanks again, guys. I found the problem why the code did not work. :D All forms where missing </form> tags! :banghead: :oops:

Merry Christmas and have a Happy New Year- :drunk:

Batoe