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

Link to comment
Share on other sites

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') {

......

}

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.