jeudi 30 avril 2015

I can't get my else to work php mysql

I have a function to get the tire size from the database and display it. The else, which should function when the size isn't in the database, isn't working. Any help will be appreciated: Here is my code for the function:

 function tiresize() {
    global $db;

    if (isset($_POST['size'])) {
        $_SESSION['size'] = $_POST['size'];
        $size = $_SESSION['size'];
        // $size=mysql_real_escape_string($size);
        // trim($size);
    }


    if (isset($size)) {
        $query = $db->prepare("SELECT size FROM tires WHERE size = '$size'");
        $query->execute();

     $tires = $query->fetchAll();
        if (isset($tires)) {
            echo "<ul>";
            foreach ($tires as $name) {
                echo "<li id='tiresearch'>";
                echo "Tire Size is Available: " . $name['size'];
                echo "</li>";
            }
     } else {
            echo "Tire size was not found";
         echo "</ul>";
        }
 }
 }

Aucun commentaire:

Enregistrer un commentaire