Jump to content

goto function help


squiblo

Recommended Posts

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/187821-goto-function-help/
Share on other sites

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".

Link to comment
https://forums.phpfreaks.com/topic/187821-goto-function-help/#findComment-991664
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.