Hello All
I am having a DB problem with my PHP code, and I can't seem to find the problem. I am using Dreamweaver as my Dev. environment. Our Backend is mysql on Linux/Apache.
First the code was working fine, then all I did to the SQL code is I added a Where clause, and where there was already a where clause, I added And balbala='blabla'
First i'm wondering if this the problem is with Dreamweaver
Go here to see why:
http://www.macromedia.com/support/dreamweaver/ts/documents/httppostvars_why.htm
I will paste the code of the man DB code. The config.php just sets the DB username and password, so no need to paste that.
<?php
include("config.php");
if($action == "del"){
$where = " WHERE Status='d' AND Contest_name='$contest'";
}elseif(IsSet($HTTP_POST_VARS['sorttype'])){
if($HTTP_POST_VARS['sorttype'] == "last"){
$where = " WHERE upper(Lname) like upper('%$key%') AND Contest_name='$contest' ORDER BY Lname";
}elseif($HTTP_POST_VARS['sorttype'] == "zip"){
$where = " WHERE upper(Zip) like upper('%$key%') AND Contest_name='$contest' ORDER BY Zip";
}elseif($HTTP_POST_VARS['sorttype'] == "cid"){
$where = " WHERE Contestant_ID = '$key' AND Contest_name='$contest'";
}elseif($HTTP_POST_VARS['sorttype'] == 'web'){
$where = " WHERE Type = 'web' AND Contest_name='$contest'";
}elseif($HTTP_POST_VARS['sorttype'] == 'fax'){
$where = " WHERE Type = 'fax' AND Contest_name='$contest'";
}
}
else{
$where = Contest_name='$contest';
}
$query = "SELECT count(Contestant_ID) FROM Contests $where";
$result = build_query($query,LINE,FILE);
$row = mysql_fetch_array($result);
$total = $row[0];
mysql_free_result($result);
$max = 10; // How many results you want to see in the page
$query = "SELECT * FROM Contests ";
if(!IsSet($begin)){
$where = " WHERE Contestant_ID <= $max AND Contest_name='$contest'";
}else{
$end = $begin + $max;
$where = " limit $begin,$max";
}
$HTTP_GET_VARS['action'];
if ($action=="search"){
if($HTTP_POST_VARS['sorttype'] == "last"){
$where .= " AND upper(Lname) like upper('%$key%') ORDER BY Lname";
}elseif($HTTP_POST_VARS['sorttype'] == "zip"){
$where .= " AND upper(Zip) like upper('%$key%') ORDER BY Zip";
}elseif($HTTP_POST_VARS['sorttype'] == "cid"){
$where .= " AND Contestant_ID = '$key'";
}elseif($HTTP_POST_VARS['sorttype'] == 'web'){
$where .= " AND Type = 'web'";
}elseif($HTTP_POST_VARS['sorttype'] == 'fax'){
$where .= " AND Type = 'fax'";
}
}elseif($action == "del"){
$where = " WHERE Status = 'd' AND Contest_name='$contest' ";
}
$query .= $where;
$result = build_query($query,__LINE__,__FILE__);
$begin++;
if($total == 0){
$begin = 0;
}
$num = mysql_num_rows($result);
if($total - $begin > $max){
$end = $begin + $max;
}else{
$end = $total;
}
$num = ceil($total/$max);
if($num > 1){
for($i=0;$i<$num;$i++){
$temp_i = $i + 1;
$start = $i*$max;
$next .= "<a href=\"index.php?begin=$start&begin=$start\">$temp_i</a> ";
}
}
$table .="<p><FONT FACE=Arial SIZE=1>There are <B>".$total."</B> matching contestants.<br>Displaying contestants <B>".$begin."</B> through <B>".$end."</B>.</FONT></p>";
$table .="<p><FONT FACE=Arial SIZE=1>Pages $next</FONT></p>";
$table .= "<table width=\"100%\" border=\"1\" align=\"center\" cellpadding=\"6\">\n";
$table .="<tr bgcolor='#6666666'>";
$table .="<th><FONT FACE=Arial color=#FFFFFF SIZE=1>Client ID</FONT></th>";
$table .= "<th><FONT FACE=Arial color=#FFFFFF SIZE=1>Last Name</FONT></th>";
$table .= "<th><FONT FACE=Arial color=#FFFFFF SIZE=1>City</FONT></th>";
$table .= "<th><FONT FACE=Arial color=#FFFFFF SIZE=1>State/Province</FONT></th>";
$table .= "<th><FONT FACE=Arial color=#FFFFFF SIZE=1>Age</FONT></th>";
$table .= "<th><FONT FACE=Arial color=#FFFFFF SIZE=1>Entry Date</FONT></th>";
$table .="</tr>";
$c_canada = 0;
$c_usa = 0;
$total = 0;
$color = "#CCCCCC";
while($row = mysql_fetch_array($result)){
$i = 0;
$tok = strtok($row['entrydate']," ");
while ($tok) {
if($i == 0){
$date = $tok;
}else{
$time = $tok;
}
$tok = strtok(" ");
$i++;
}
if(!isset($action)){
$action = "";
}else{
$action = "&action=".$action;
}
$table .= "<tr bgcolor=\"$color\">";
$table .= "<td><a href=\"contestant.php?id=".$row['Contestant_ID'].$action."\"><FONT FACE=Arial SIZE=1>" .stripslashes($row['Contestant_ID'])."</FONT></a></td>";
$table .= "<td><a href=\"contestant.php?id=".$row['Contestant_ID'].$action."\"><FONT FACE=Arial SIZE=1>".stripslashes($row['Lname'])."</FONT></a></td>";
$table .= "<td><a href=\"contestant.php?id=".$row['Contestant_ID'].$action."\"><FONT FACE=Arial SIZE=1>".stripslashes($row['City'])."</FONT></a></td>";
$table .= "<td><a href=\"contestant.php?id=".$row['Contestant_ID'].$action."\"><FONT FACE=Arial SIZE=1>".stripslashes($row['State'])."</FONT></a></td>";
$table .= "<td><a href=\"contestant.php?id=".$row['Contestant_ID'].$action."\"><FONT FACE=Arial SIZE=1>".stripslashes($row['Age'])."</FONT></a></td>";
$table .= "<td><a href=\"contestant.php?id=".$row['Contestant_ID'].$action."\"><FONT FACE=Arial SIZE=1>".stripslashes($date)."</FONT></a></td>";
$table .= "</tr>";
unset($action);
$total++;
if($color == "#CCCCCC")
{
$color = "#E2E2E2";
}
else
{
$color = "#CCCCCC";
}
}
$table .= "</td></tr></table>";
echo $table;
?>
Can anyone please help me and tell me why My code is no longer working?
Thank You
MK