I have a website with a form. The user first inputs a name and email into the database (I've got this working) and then he can input a name to search in the database and get a photo with the email. I've got the $return value but it is an Object, and in the image creation method I need it to be a String. I've tried to convert it with a cast but it doesn't work. (I've tried outputing it first)
Here's the HTML:
<form name="getEmail"
action="getEmail.php"
method="GET">
Name: <input type="text" name="getEmail" id="getEmail" value="Email..." maxlength="100" size="20" onclick="this.value=''" />
Here's the PHP:
<?php
$con=mysqli_connect("localhost","root","","assignment1");
if (mysqli_connect_errno()) {
echo "Could not connect to the mySQL database: " . mysqli_connect_error();
}
// create a 100*30 image
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 120, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
$name=$_GET['getEmail'];
$result = mysqli_query($con,"SELECT email FROM Users WHERE name='$name' ");
echo (String)$result;
// write the string at the top left
imagestring($im, 5, 0, 0,$result, $textcolor);
// output the image
header("Content-type: image/png");
imagepng($im);
mysqli_close($con);
?>
mysqli_queryand maybemysqli_fetch_array. Then you will figure it out.mysqli_real_escape_string()instead.