Jump to content

[SOLVED] How to use what's echoed in an else statenements in the HTML


toxictoad

Recommended Posts

I have this code working

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br /><br />";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>

 

What I don't get is how to take what's being echoed in the else statements and have it in the HTML code. Can anyone help?

 

Thanks

TT

Link to comment
Share on other sites

<?php
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
$uploadResult = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br /><br />";
}
else {
$uploadResult =  "Sorry, there was a problem uploading your file.";
}
?>

 

Then in your html put <?php echo $uplaodResult; ?> where ever you want it

Link to comment
Share on other sites

thanks guys, I was playing with it and figured it out, I did it a little different though

 

$success="The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br /><br />";

 

$error= "Sorry, there was a problem uploading your file.";

 

then use <?=$success?><?=$error?> in the HTML code but your use of just $uploadResult will just mean that I only need to add <?=$uploadResult?> so thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.