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

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

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

this is an old way of doing things <?=$success?>

 

please use

 

<?php echo $success; ?>

 

Ok thank's, picking it up as I go ;)

 

Before I mark it as solved would there be a way of adding a different graphic to each of these statements?

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.