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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

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.