PHP function giving me exception when trying to display on HTML

bandoy123

I am having issues executing an SQL statement and printing the results on my HTML page.

This is the function:

function getFirstName($shId) {


$query  = 'SELECT sh_firstname';
$query .= 'FROM Shaddr';
$query .= 'WHERE shopper_id = ?';

$dbo = db_connect();

try {
    $statement = $dbo->prepare($query);
    $statement->bindParam(1,$shId,PDO::PARAM_INT);
    $statement->execute();
}
catch (PDOException $ex) {
    error_log($ex->getMessage());
    die("Errors encountered while obtaining first name");
}

return $statement;
}

and this is how i'm trying to show it in my HTML:

<?php 
$results = getFirstName(2);
echo $results;
?>

The database is connected properly and everything as I have other working queries. The error i'm getting is the exception I made "Errors encountered while obtaining first name".

What is wrong with this function?

Saty

You need to space before FROM and WHERE clause

$query  = 'SELECT sh_firstname';
$query .= ' FROM Shaddr';
$query .= ' WHERE shopper_id = ?';

You need to return result set from your getFirstName()

 try {
    $statement = $dbo->prepare($query);
    $statement->bindParam(1,$shId,PDO::PARAM_INT);
    $statement->execute();
}
catch (PDOException $ex) {
    error_log($ex->getMessage());
    die("Errors encountered while obtaining first name");
}

return $result = $statement->fetch(PDO::FETCH_ASSOC);

And you get your value as

<?php 
$results = getFirstName(2);
print_r($results);
?>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

SqlCeCommand keeps giving me an exception

분류에서Dev

Error Appears When Trying to Display MySQL Table Data in HTML Table

분류에서Dev

Exception when trying to refresh Clojure code in cider

분류에서Dev

NullPointer Exception When Trying to Update Sprite

분류에서Dev

Server gives me a permission error when trying to scp, but not when ssh

분류에서Dev

Segmentation fault when trying to clone a function (in C)

분류에서Dev

Exception when trying to run a map of LinkedLists through a scanner

분류에서Dev

Argument Null Exception error when trying to create a Text File

분류에서Dev

Undefined property exception when trying to instantiate dependency from IOC container

분류에서Dev

Unhandled Exception when using abstract function

분류에서Dev

Classnotfound Exception when Embedding jar with HTML

분류에서Dev

Getting black screen when trying to remove ViewController from display in iOS

분류에서Dev

How to resolve error when trying to open Windows Display Settings?

분류에서Dev

Displaying image in tooltip is giving me a flickering effect when hovered over the content

분류에서Dev

Why is it giving me an error when i'm calling it from inside the 'student class?

분류에서Dev

Nginx Autoindex giving me a 403

분류에서Dev

Display data returned by function in PHP MySQL

분류에서Dev

Php display as a html text the new line \n

분류에서Dev

Using a function to output HTML in PHP

분류에서Dev

Put HTML markup in PHP if function

분류에서Dev

Trying to create a PHP function that only utilizes new instance of variable

분류에서Dev

php syntax error while am trying to add foreach inside function

분류에서Dev

When iam trying to run spring example i am facing the following exception

분류에서Dev

Why i'm getting "titlebarViewController not supported for this window style" exception when trying to add title bar accessory view

분류에서Dev

Getting an exception when trying to get the content of a file from response Web API2 WPF

분류에서Dev

PyTorch is giving me a different value for a scalar

분류에서Dev

Checking for repeated characters not giving me the desired output

분류에서Dev

Why is my Makefile giving me problems?

분류에서Dev

When i run cron for a database function it returns me the same value

Related 관련 기사

  1. 1

    SqlCeCommand keeps giving me an exception

  2. 2

    Error Appears When Trying to Display MySQL Table Data in HTML Table

  3. 3

    Exception when trying to refresh Clojure code in cider

  4. 4

    NullPointer Exception When Trying to Update Sprite

  5. 5

    Server gives me a permission error when trying to scp, but not when ssh

  6. 6

    Segmentation fault when trying to clone a function (in C)

  7. 7

    Exception when trying to run a map of LinkedLists through a scanner

  8. 8

    Argument Null Exception error when trying to create a Text File

  9. 9

    Undefined property exception when trying to instantiate dependency from IOC container

  10. 10

    Unhandled Exception when using abstract function

  11. 11

    Classnotfound Exception when Embedding jar with HTML

  12. 12

    Getting black screen when trying to remove ViewController from display in iOS

  13. 13

    How to resolve error when trying to open Windows Display Settings?

  14. 14

    Displaying image in tooltip is giving me a flickering effect when hovered over the content

  15. 15

    Why is it giving me an error when i'm calling it from inside the 'student class?

  16. 16

    Nginx Autoindex giving me a 403

  17. 17

    Display data returned by function in PHP MySQL

  18. 18

    Php display as a html text the new line \n

  19. 19

    Using a function to output HTML in PHP

  20. 20

    Put HTML markup in PHP if function

  21. 21

    Trying to create a PHP function that only utilizes new instance of variable

  22. 22

    php syntax error while am trying to add foreach inside function

  23. 23

    When iam trying to run spring example i am facing the following exception

  24. 24

    Why i'm getting "titlebarViewController not supported for this window style" exception when trying to add title bar accessory view

  25. 25

    Getting an exception when trying to get the content of a file from response Web API2 WPF

  26. 26

    PyTorch is giving me a different value for a scalar

  27. 27

    Checking for repeated characters not giving me the desired output

  28. 28

    Why is my Makefile giving me problems?

  29. 29

    When i run cron for a database function it returns me the same value

뜨겁다태그

보관