Jump to content

Recommended Posts

I'm getting kinda frustrated and wondering what I am doing wrong.  I have a form that posts two values, tech and site and named them accordingly.  When I enter in both a tech and a site the code works or when I enter in neither the code works, when I enter in one or the other and leave the value to all for either I am unable to get any return.  I believe my syntax is right and have tried all the versions of the does not equal sign.  If anyone could help I would really appreciate it.

 

Thanks,

T.J.

 

<?php
include 'includes/config.php';
include 'includes/opendb.php';

$tech1=$_POST['tech'];
$site1=$_POST['site'];

echo $site1;
echo $tech1;

if ($site1 <> 'All' && $tech1 == 'All')
{
$query ="SELECT * 
FROM helpdesk h
WHERE h.site = '$site1'";

}

if ($site1 == 'All' && $tech1 <> 'All')
{
$query ="SELECT * 
FROM helpdesk h
WHERE h.tech = '$tech1'";
}

if ($site1 == 'All' && $tech1 == 'All')
{
$query ="SELECT * 
FROM helpdesk h";
}

else
{
$query ="SELECT * 
FROM helpdesk h
WHERE h.tech = '$tech1' 
AND h.site = '$site1'";
}

$result = mysql_query($query);

while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
   
   $tech=$r["tech"];
   $ticketno=$r["ticketno"];
   $connect=$r["connect"];
   $date=$r["date"];
   $site=$r["site"];
   $rmnum=$r["rmnum"];
   $problem=$r["problem"];
   $resolution=$r["resolution"];
   $connected=$r["connected"];
   
   //display the row
     echo "<tr>";
     echo "<td>";
 echo $tech;
 echo "</td>";
 echo "<td>";
 echo $ticketno;
 echo "</td>";
 echo "<td>";
 echo $connect;
 echo "</td>";
 echo "<td>";
 echo $date;
 echo "</td>";
 echo "<td>";
 echo $site;
 echo "</td>";
 echo "<td>";
 echo $rmnum;
 echo "</td>";
 echo "<td>";
 echo $problem;
 echo "</td>";
 echo "<td>";
 echo $resolution;
 echo "</td>";
 echo "<td>";
 echo $connected;
 echo "</td>";
}

include 'includes/closedb.php';
?>

Link to comment
https://forums.phpfreaks.com/topic/72802-solved-help-please/
Share on other sites

k i think ive got it this time :)

 

you need to put else's before the second and third if because its defaulting to the last "else"

 

if this doesn't work then maybe i stop giving stupid suggestions :)

 

<?php
/...
if ($site1 <> 'All' && $tech1 == 'All')
{
$query ="SELECT * 
FROM helpdesk h
WHERE h.site = '$site1'";

}
else if ($site1 == 'All' && $tech1 <> 'All')
{
$query ="SELECT * 
FROM helpdesk h
WHERE h.tech = '$tech1'";
}
else if ($site1 == 'All' && $tech1 == 'All')
{
$query ="SELECT * 
FROM helpdesk h";
}
else
{
$query ="SELECT * 
FROM helpdesk h
WHERE h.tech = '$tech1' 
AND h.site = '$site1'";
}

Link to comment
https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367171
Share on other sites

Before you believe all errors are gone, take a look at this:

 

if ($site1 == 'All' && $tech1 == 'All')

{

$query ="SELECT *

FROM helpdesk h";

}

 

See the FROM helpdesk line; there's an extra double quote.

If this is a copy/paste from your original script, you should check that.

php will be looking for the next double quote....

Link to comment
https://forums.phpfreaks.com/topic/72802-solved-help-please/#findComment-367187
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.