squiblo Posted January 9, 2010 Share Posted January 9, 2010 Hi, I have never used the "goto" function before, and I am having a little trouble understanding it, I have a very simple script to upload profile pictures. When the picture is uploaded I want it to goto another part of the script and echo "upload successfull" but for some reason "upload successfull" is always being echoed even before anything is uploaded. If there is a better way of doing this please help. Thanks. <?php mysql_connect("","","") or die ("Couldn't connect"); mysql_select_db("") or die ("Couldn't find db"); $username = $user->data['username']; if ($_POST['submit']) { //GET FILE ATTRIBUTES $name = $_FILES['myfile']['name']; //append user ID make name unqiue $name = $user->data['user_id'] . $name; $tmp_name = $_FILES['myfile']['tmp_name']; if ($name) { $query_check = mysql_query("SELECT * FROM profile_set_data WHERE username='$username'"); $num_rows = mysql_num_rows($query_check); if ($num_rows != "0") { //start remove OLD from file process while ($row = mysql_fetch_assoc($query_check)) { $file_remove = $row['image_location']; } unlink($file_remove); //start upload NEW process $location = "content/logged_bar/hub/myprofile/profile_pics/$name"; move_uploaded_file($tmp_name,$location); $query_upload = mysql_query("UPDATE profile_set_data SET image_location='$location' WHERE username='$username'"); goto complete; } else { //start upload process $location = "content/logged_bar/hub/myprofile/profile_pics/$name"; move_uploaded_file($tmp_name,$location); $query_upload = mysql_query("INSERT INTO profile_set_data VALUES('','$username','$location')"); goto complete; } } else echo "Please select a file"; } $query_check = mysql_query("SELECT * FROM profile_set_data WHERE username='$username'"); $num_rows = mysql_num_rows($query_check); if ($num_rows != "0") { while ($row = mysql_fetch_assoc($query_check)) { $profile_pic = $row['image_location']; } } else $profile_pic = "bob"; echo " <table width='100%'> <tr> <td> <table width='30%' class='profile_pic' align='left'> <tr> <td><b>Current Picture</b><br><br><img src='$profile_pic' width='100%' height=''></td> </tr> </table> <table width='70%' class='upload_table' align='right'> <tr> <td><br><h3>Upload Picture</h3></td> </tr> <tr> <td>You can upload a JPG, GIF or PNG file.<br><br> <form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='myfile'> <input type='submit' name='submit' value='upload'> </form> </td> </tr> </table> </td> </tr> </table> "; ?> <?php complete: echo "upload successfull"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/187821-goto-function-help/ Share on other sites More sharing options...
salathe Posted January 9, 2010 Share Posted January 9, 2010 The portion of code below the "complete" label will always be executed, just because there is a label before it does not make that code special in any way. The label just acts as a point that the script can say "hey, skip along and execute this bit right away" and not as a place that says "only execute this code if I've been told to do so". Quote Link to comment https://forums.phpfreaks.com/topic/187821-goto-function-help/#findComment-991664 Share on other sites More sharing options...
squiblo Posted January 9, 2010 Author Share Posted January 9, 2010 Thank you salathe, ill stop trying to use the goto funtion. Any suggestions on how to do this without using "header("location:...")? Quote Link to comment https://forums.phpfreaks.com/topic/187821-goto-function-help/#findComment-991665 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.