www.webdeveloper.com
Results 1 to 2 of 2

Thread: problem seeing if exist in db

  1. #1
    Join Date
    Jul 2013
    Posts
    2

    problem seeing if exist in db

    Hi
    i was wondering if anyone had any idea what im doing wrong for the error handling in my script? what im trying to do is if there is no record in the database it will show a message saying no record found when a search is made.
    PHP Code:
    <?php
    require("common.php");
    $error_message="";
    if (isset(
    $_POST['submit'])){
    if(empty(
    $_POST['term']))
    {
    $error_message="Please enter a Ticket Number.";
    }
    else
    {
    $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)) {

    ///I'M SURE THIS IS WRONG
    if($stmt->rowCount()>1)
        echo 
    'no record found';
            
    else

          
        echo 
    htmlentities($department);

      }
     }
    }
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    752
    I would say it's because you put your error message inside of the processing loop which may never get executed. Do the count check before starting a loop on a non-existent result set.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles