roopurt18 Posted December 3, 2007 Share Posted December 3, 2007 Yes, but just to be sure you didn't leave out the other call to mysql_query(), here it is in completeness. $sql = "DELETE FROM `user_images` WHERE `user_id`={$Clean['user_id']}"; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database delete successful'); } $sql = " INSERT INTO `user_images` (`user_id`, `ext`, `created`, `modified`) VALUES ( {$Clean['user_id']}, {$Clean['ext']}, NOW(), NOW() ) "; $q = mysql_query($sql); if($q === FALSE){ dbg_out('ERROR: ' . mysql_error()); }else{ dbg_out('Database insert successful'); } Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-405560 Share on other sites More sharing options...
runnerjp Posted December 3, 2007 Author Share Posted December 3, 2007 hey i did it and it doesnt delete the image Array ( [user_id] => 1 [logged_in] => 1 ) Array ( [image] => Array ( [name] => logoo.bmp [type] => image/bmp [tmp_name] => /tmp/phpkbw3Ja [error] => 0 [size] => 135054 ) ) image/bmp /home/runningp/public_html/members/images/1.bmp SUCCESS! Database delete successful Database insert successful Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-405581 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 Well, if it deletes the old image and then inserts a new one, the record will still be there. To test it, upload a .gif followed by a .jpg and make sure in the DB the record changes from gif to jpg. Or just check that the created field has changed. Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-405665 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 it does chnage in the db sorry lol what is the next part to follow then Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-405913 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 That's it as far as uploading is concerned. The next part is to display the avatars where appropriate. That should be as easy as selecting a user's avatar from the database and creating an img tag. Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406176 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 what you mean by creating an img tag. Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406188 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 Well these are avatars. I assume they're meant to be displayed while viewing a member's profile or forum post. In order to do so you have to SELECT the data from the database and then create an HTML img tag. Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406190 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 hey i treid this code to show image but gets notting and no error shown :S $sql = "SELECT * FROM user_image WHERE user_id=".$_GET["id"]; $result = mysql_query ($sql, $conn); if (mysql_num_rows ($result)>0) { $row = @mysql_fetch_array ($result); $image_type = $row["ext"]; Header ("Content-type: $image"); print $image; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406281 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 is my code correct? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406315 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 If it were correct it would be working, which you already said it wasn't. You're using a variable $image in your header() call but I don't see where you're setting it. Anyways, you don't have to make any calls to header(). The file has the extension attached so the browser will know what to do with it. All you need to do is look up the record in the table for the appropriate extension. <?php $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.yourdomain.com/members/images/' . $_GET['id'] . '.' . $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406334 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 humm it not selecting any img... it just echos image not found even though 1 is uploaded Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406340 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 Try echo'ing the SQL statement and running it directly in phpMyAdmin. Try echo'ing mysql_error(). At some point you need to learn how to debug your application. Other than copying and pasting what I put, running it once, and then coming back to say it doesn't work, what have you done to try and troubleshoot it yourself? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406344 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 well i have been echoing it and i have found that $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); is the error Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406352 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 mesingarround i got #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id']' at line Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406355 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 It seems that the PHP snippet I gave you is somehow being sent as the query. How are you calling this code? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406357 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 calling it... surly the code alone will show the image?? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406366 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 That error message is telling you that this is your query: '<?php $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id']' Whatever you are doing, mysql is running something like this: mysql_query("<?php\n$sql = 'SELECT `ext` ..."); which is surely wrong. So if this code is in a single file that you are referring to in your browser, yah it should work. But if you are including() or requiring() that code I gave you, that could explain it. Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406370 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 no single file like so... <?php session_start(); require_once '../settings.php'; // see if a name was passed via the url. if (isset($_GET['username'])) { $username = mysql_real_escape_string($_GET['username']); } elseif (isset($_SESSION['username'])) { $username = $_SESSION['user_id']; } else { die("No profile to search for"); } $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> <?php $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); echo 'emma'; if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' . $_GET['id'] . '.' . $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } ?> so it should work Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406374 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 What does this print: <?php session_start(); require_once '../settings.php'; // see if a name was passed via the url. if (isset($_GET['username'])) { $username = mysql_real_escape_string($_GET['username']); } elseif (isset($_SESSION['username'])) { $username = $_SESSION['user_id']; } else { die("No profile to search for"); } $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } echo '<pre style="text-align: left;">id: ' . $_GET['id'] . '</pre>'; $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id']; $q = mysql_query($sql); echo '<pre style="text-align: left;">sql: ' . $sql . '</pre>'; echo '<pre style="text-align: left;">q: ' . $q . '</pre>'; echo '<pre style="text-align: left;">error: ' . mysql_error() . '</pre>'; if($q){ $row = mysql_fetch_array($q); echo 'emma'; if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' . $_GET['id'] . '.' . $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406381 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 id: sql: SELECT `ext` FROM `user_image` WHERE `user_id`= q: error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 why is it not getting the id?? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406387 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 What does the URL look like? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406394 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 well u gotta be signed in lol www.runningprofiles.com username test password test then go to update profile and will show you the page Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406396 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 why will it not work? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406418 Share on other sites More sharing options...
runnerjp Posted December 4, 2007 Author Share Posted December 4, 2007 did u try it out? Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406434 Share on other sites More sharing options...
roopurt18 Posted December 4, 2007 Share Posted December 4, 2007 It won't work because the URL looks like this: http://www.runningprofiles.com/members/test Where if you're going to use $_GET it needs to look like this: http://www.runningprofiles.com/members/test?id=<users_number_id> So either you change the URL or you change the script to not use $_GET. I recommend changing the script to not use $_GET since you are already passing the username into it. Quote Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/3/#findComment-406445 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.