Jump to content

php help, if


roxiroxi

Recommended Posts

hi,

I've got a problem here, can anyone help me?

$hostName = "localhost";
$userName = "root";
$password = "password";
$dbName = "dvdswap";

$title = $_POST['title'];
$option = $_POST['option'];

       
// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");

mysql_select_db($dbName) or die( "Unable to select database $dbName");

if ($_POST['option'] == "exactly")
{
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid
        FROM product where product.title = '$title'";
}

else ($_POST['option'] == "starts") {
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid
        FROM product where product.title like '$title%'";
}

else ($_POST['option'] == "includes") {
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid
        FROM product where product.title like '%$title%'";
}
Link to comment
https://forums.phpfreaks.com/topic/30488-php-help-if/
Share on other sites

Couple of things:
echo $_POST['option'] to see what you get.

If you get the right thing, try this switch code instead of the ifs.:

[code]switch ($_POST['option']){
case "exactly":
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid FROM product where product.title = '$title'";
break;

case "starts":
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid FROM product where product.title like '$title%'";
break;

case "includes":
$query = "SELECT product.prodid, product.title, product.pyear, product.format, product.cert, product.userid FROM product where product.title like '%$title%'";
break;
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/30488-php-help-if/#findComment-140360
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.