Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:37:26+00:00 2026-06-14T02:37:26+00:00

I wrote this code, but it was pointed out by people here at stackoverflow

  • 0

I wrote this code, but it was pointed out by people here at stackoverflow that these functions will deprecate. So I’m updating it with mysqli functions. The new one won’t return the image url i want to show though.

Here’s the old working code :

<html>
<head>

<title>My first PHP script</title>
</head>
<body> 

<?php

$dbhost = 'access.website';
$dbname = 'my_db';
$dbuser = 'usr_nam';
$dbpass = 'passwrd';

$mysql_handle = mysql_connect($dbhost, $dbuser, $dbpass)
    or die("Error Connecting To Database Server");

mysql_select_db($dbname, $mysql_handle)
    or die("Error selecting database: $dbname");

$query = sprintf("SELECT image_url, Type FROM Pokemon 
    c WHERE c.name='%s'", 
    mysql_real_escape_string($_GET["fname"]));

$result = mysql_fetch_assoc(mysql_query($query));   

echo '<img height="450" width="330" src="'.$result['image_url'].'" />';

mysql_close($mysql_handle);

?>

</body>
</html>

And here is my new code:

<html>
<head>

  <title>My first PHP script</title>
</head>
<body> 

<?php

$dbhost = 'access.website';
$dbname = 'my_db';
$dbuser = 'usr_nam';
$dbpass = 'passwrd';

$link = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);

mysqli_select_db($link,$dbname);

$query = sprintf("SELECT image_url, Type FROM Pokemon 
    c WHERE c.name='%s'", 
    mysqli_real_escape_string($link,$_GET["fname"]));

$result = mysqli_query($link,$query);   

echo '<img height="450" width="330" src="'.$result['image_url'].'" />';

mysqli_close($link);

?>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:37:28+00:00Added an answer on June 14, 2026 at 2:37 am

    You have not actually fetched a result from the $result resource via mysqli_fetch_assoc() or similar:

    $result = mysqli_query($link,$query);   
    $row = mysqli_fetch_assoc($result);
    
    echo '<img height="450" width="330" src="'.$row['image_url'].'" />';
    

    Another suggestion: Although you have switched to MySQLi, you are not receiving its primary security benefit through prepared statements. This would be better done with a prepared statement and placeholders:

    // MySQLi object-oriented version with a prepared statement
    $mysqli = new mysqli('host','user','pass','dbname');
    // Prepare the query and placeholder
    $stmt = $mysqli->prepare("SELECT image_url, Type FROM Pokemon c WHERE c.name=?");
    // Bind input var & execute
    $stmt->bind_param('s', $_GET['fname']);
    $stmt->execute();
    $stmt->bind_result($img_url)
    $stmt->fetch();
    
    echo '<img height="450" width="330" src="'.$img_url.'" />';
    

    Or the non-OO version:

    // $link is already defined
    $stmt = mysqli_prepare($link, "SELECT image_url, Type FROM Pokemon c WHERE c.name=?");
    mysqli_stmt_bind_param($stmt, 's', $_GET['fname']);
    mysqli_stmt_execute($stmt);
    // Bind output var & fetch
    mysqli_stmt_bind_result($stmt, $img_url);
    mysqli_stmt_fetch($stmt);
    // $img_url now holds the value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this code for zoom in/out . it works but even with one
Im new to ruby, wrote this code and works but i know is not
I wrote this code. The constructor works normally, but in the destructor I get
My brother wrote this code for me to show an example of polymorhism. But
I wrote this little code std::map<int,template<class T>> map_; map_.insert(make_pair<int,message>(myMsg.id,myMsg)); but the compiler doesn't seem
I have to fix a glitch with this code someone wrote but I'm not
I have write this code but it does work only if I am already
I've write this code to add textview into table row, but I've problem for
I have this code to write to a file, it works perfect but I
I have this code to update users data, but I can't write the for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.