unexpected T_ELSE and problem getting errorCode working

mrbrin

New Member
Messages
2
Reaction score
0
Points
0
Hi
anyone have any idea why im getting a Parse error: syntax error, unexpected T_ELSE on line 28? i know it has to do with if($stmt->errorCode() == 0) { what im trying to do is add that so if there is no ticket number that you searched for in the database it will give you a message saying sorry ticket number cannot be found thanks.

PHP:
<?php
require("db.php");
$error_message="";
if (isset($_POST['submit'])){
if(empty($_POST['term']))
{
$error_message="Please enter a Ticket Number.";
}
else
{

if($stmt->errorCode() == 0) {


$query = "SELECT department, subject, message FROM supporttickets Where ticketnumber LIKE :term";


$stmt = $db->prepare($query);
$stmt->execute(array(':term' => $_POST['term']));



while (list($department,$subject,$message) = $stmt->fetch(PDO::FETCH_NUM)) {
echo htmlentities($department);
}
else
{
$error_message="sorry ticket number cannot be found.";
 }

 }
 }
}
?>
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
The else after the while loop should have another } before it. The one there now goes with the while.

Edit/add: Then you have to remove a later }
 
Last edited:

mrbrin

New Member
Messages
2
Reaction score
0
Points
0
The else after the while loop should have another } before it. The one there now goes with the while.

Edit/add: Then you have to remove a later }

hi thanks,
now im getting Fatal error: Call to a member function errorCode() on a non-object in for this line if($stmt->errorCode() == 0) { again thanks
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
hi thanks,
now im getting Fatal error: Call to a member function errorCode() on a non-object in for this line if($stmt->errorCode() == 0) { again thanks

It is saying $stmt is not set.

$stmt = $db->prepare($query);

happens later in your script.

Is "db.php" supposed to set $stmt?
 
Top