mark103 Posted July 6, 2011 Share Posted July 6, 2011 i have got a weird problem right here. I have printed out the images from mysql database, so i have added the the text data code in my php script where I can extact the data from mysql, but when I ran my site for a scale test, I saw my site link have been printed out and displaying as a image on my php page which it looks like this: http://mysite.myhostname.com/images.php?user=test&pass=test I find it werid, so if I remove this: echo "<p id='textdata'>"; echo $row['textdata'] . "</p>"; It will extact the images from the database, but I will not be able to extact the data. I can't find the solution to extact the images and the data from mysql database at the same time, it has to be either one of them to get it to works. And I have found out that it will causes huge traffic of the server to make them getting slowing down, so I should have stored the images in the file manager of my webhost but I have no idea how to link them in mysql database. here's the current code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'dbusername'); define('DB_PASSWORD', 'dbpassword'); define('DB_DATABASE', 'dbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $pass = clean($_GET['pass']); if($username == '' && $pass == ''){ // both are empty $errmsg_arr[] = 'Username and password are missing. You must enter both or the other one.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $qrytable1="SELECT username, dbimages, textdata FROM images_list WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { header('Content-Type: image/jpeg'); echo $row['image']; echo "<p id='textdata'>"; echo $row['textdata'] . "</p>"; } } } } ?> Any help would be much appreicated. thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/241175-have-trouble-of-extact-the-images-and-the-data-from-mysql-at-the-same-time/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2011 Share Posted July 6, 2011 Each image you put onto a WEB PAGE must use an <img src="..." alt=""> HTML TAG. The src="..." attribute must be a URL to where the browser fetches the image from. You cannot output the raw image data directly in the HTML source of a WEB PAGE (well you can, but it is not nice for a couple of different reasons.) As TeNDoLLA indicated in your existing thread for this problem, you would use a .php script in the URL in the src="..." attribute. That .php script would output the correct content type header followed by the image data. -------- To store the images in a folder, you would put the file name of the image into the database (instead of the actual image data) and simply use the file location and the file name when you output the URL in the <img src="..." alt=''> tag on the web page. Quote Link to comment https://forums.phpfreaks.com/topic/241175-have-trouble-of-extact-the-images-and-the-data-from-mysql-at-the-same-time/#findComment-1238795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.