Jump to content

Submit button dont work


kristian_gl

Recommended Posts

preview.php:

 

 <form id="form100" name="form100" method="POST" action="preview.php">

             <input type="submit" name="back" id="tilbake" value="Back" />
             <input type="submit" name="finish" id="lagre" value="Finished" />
             <input type="submit" name="publish" id="publiser" value="Publish" />
             </form>
             <br />
       

         

   

<?php
        $finish= $_POST['finish'];
	$back= $_POST['back'];
	$publish= $_POST['publish'];



	if (isset($finish))
	{
	setcookie("navn_cookie", "", time()-3600);
	header('Location: http://stud.aitel.hist.no/~oddl/admin/admin.php');
        }
	elseif (isset($back))
	{
	header('Location: http://stud.aitel.hist.no/~oddl/admin/leggtilspm.php');
	}
	elseif (isset($publish))
	{
	$drop_table = "DROP TABLE `svar`";
	mysql_query($drop_table);
	$create_table = 'CREATE TABLE `svar` ('
        . ' `id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY'
        . ' )'
        . ' ENGINE = myisam;';
	mysql_query($create_table);

	header('Location: http://stud.aitel.hist.no/~oddl/admin/undersokelse.php');

	}

?>		

 

When I click on any of the submitbuttons, the page just refreshes itself, and doing what I've haved specified in the if-loop

Link to comment
https://forums.phpfreaks.com/topic/200547-submit-button-dont-work/
Share on other sites

Isset checks if the variable has been set or exists, you have set each variable to exist just above the if statement that checks it, it will always return true - and execute. Use if(isset($_POST['finish'])), and if(isset($_POST['back'])) instead.

 

Also,

I would use hard links instead though, rather than extra submit buttons (since you don't need to submit data unless your publishing), just like:

 

 <form id="form100" name="form100" method="POST" action="preview.php">

            <a href="preview.php?action=back">Back</a>
            <a href="preview.php?action=finish">Finished</a>
             <input type="submit" name="publish" id="publiser" value="Publish" />
             </form>
             <br />

then just change this

   

<?php
	if (isset($_GET['finish']))
	{
	setcookie("navn_cookie", "", time()-3600);
	header('Location: http://stud.aitel.hist.no/~oddl/admin/admin.php');
        }
	elseif (isset($_GET['back']))
	{
	header('Location: http://stud.aitel.hist.no/~oddl/admin/leggtilspm.php');
	}
	elseif (isset($_POST['publish']))
	{
	$drop_table = "DROP TABLE `svar`";
	mysql_query($drop_table);
	$create_table = 'CREATE TABLE `svar` ('
        . ' `id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY'
        . ' )'
        . ' ENGINE = myisam;';
	mysql_query($create_table);

	header('Location: http://stud.aitel.hist.no/~oddl/admin/undersokelse.php');

	}

?>		

 

-cb-

Works for me.  What I would do however is to use the same name for the submit button, but only change the value

 

<input type="submit" name="submit" id="tilbake" value="Back" />
<input type="submit" name="submit" id="lagre" value="Finished" />
<input type="submit" name="submit" id="publiser" value="Publish" />

 

Then in the preview.php

 

$selection = $_POST['submit'];

if ($selection == 'Back') {

...

} elseif ($selection == 'Finished') {

.....

} elseif ($selection == 'Publish') {

......

}

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.