Jump to content

How can I implement HTML buttons in a PHP script?


APD1993

Recommended Posts

I'm trying to implement a simple submit button within a PHP script so that when it is clicked, the user goes back to the homepage. However, at the moment my coding does not work. Any ideas on how to solve this?

 

My code at the moment is:

 

<?php
//Creating a variable that essentially is used to make sure that the file being created by the user will be named based on what they entered into the text box called filename that collected the Client's Surname they gave in the fileupload.html page and that the new, user created file will be stored in the RCM3 folder and will be stored in an HTML format
$filename="C:/xampp/htdocs/RCM3/".$_POST['filename'].".html";
//Getting the car accident information from the text box named info on the fileupload.html page and using it as the content for the user created file
$info=$_POST['info'];
//Opening the file (by using the fopen function) and giving append and write permissions for the file
$file=fopen($filename, 'a+w');
//Putting in the user created file name and the accident details into the new file by using the fputs function 
fputs($file, $info);
//Closing the file and ending the editing of the file name and file contents by using the fclose function
fclose($file);
?>
<html><head><title>Creating An Accident Report Form</title></head>
<body>
<?php
//Using an IF statement so that if the file has successfully been created, the file details (name, filepath and file size) will be displayed to the user, as well as a submit button that takes the user back to the RCM Homepage--> 
if(file_exists($filename)){
$file_length=filesize($filename);
$msg = "<p>File created: $filename<br>";
$msg.="File size: $file_length bytes<br></p>";
//INSERT SUBMIT BUTTON HERE
$msg.="<form action="Congrats.html" method="post" input type="submit" value="Go back to RCM Homepage"></form>
echo ($msg);
}
//If the file does not exist, then an error message will appear telling the user that file was not able to be created. A submit button will also be in place so that the user can go back to the RCM Homepage if they so choose
else
{
echo("Unable to create file");
}
?>
</body>
</html>
           

 

Any help is appreciated!

I see a problem with this line

$msg.="<form action="Congrats.html" method="post" input type="submit" value="Go back to RCM Homepage"></form>

 

Should be:

$msg.="<form action=\"Congrats.html\" method=\"post\" input type=\"submit\" value=\"Go back to RCM Homepage\"></form>";

 

Don't think this is enough to fix your problem though... You have nothing in your <form></form>

All on one line:

 

You're using unescaped double quotes in a double-quoted string, which is then not closed with an ending double quote, and not terminated with a semicolon.

 

Your opening form tag isn't closed with >, and your input element for the submit button isn't opened with <.

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.