...

View Full Version : PHP-Multiple Submit Buttons on Page Problem



kccagal
08-03-2012, 05:09 AM
I am using the following code for this issue and it doesn't do anything. I select the button to Create User and I stay on the same page. What should be happening is that a form which is built on createUserAccount.php. Can anyone give me direction as I really need to get this project completed so I can get a new, better paying job? Thank you.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(isset($_POST['submit1']))
{
header("Location: createUserAccount.php");
}
else if(isset($_POST[["submit2"]))
{
header("Location: loginUser.php");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Create User-Login Functions</title>

<![endif]--></head>

<body class="thrColElsHdr">
<div id="container">
<div id="header">

<!-- end #header --></div>

<div id="sidebar1">

<!-- end #sidebar1 --></div>

<div id="sidebar2">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="tkdHistory.html">TaeKwonDo History</a></li>
<li><a href="blackbelts.html">Blackbelts</a></li>
<li><a href="contact.html">Contact Us</a></li>
<li><a href="adminFunctions.php">Administration Functions</a></li>
<li><a href="createUserLoginFunctions.php">Create User-Login Functions</a></li>
</ul>
<!-- end #sidebar2 --></div>

<div id="mainContent">
<form id="createUserLoginFunctions" name="createUserLoginFunctions" method="post" action="">
<br />
<label>Create New User Account </label>
<input type="submit" name="submit1" value="CREATE USER">
<br />
<br />
<label>Login User </label>
<input type="submit" name="submit2" value="LOGIN USER">
<br />
<br />
</form>

<!-- end #mainContent --></div>
<br class="clearfloat" />

<div id="footer">

<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

abduraooft
08-03-2012, 10:45 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(isset($_POST['submit1']))
{
header("Location: createUserAccount.php");
}
else if(isset($_POST[["submit2"]))
{
header("Location: loginUser.php");
}
?>


Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Move your DOCTYPE to the immediate top of
<html xmlns="http://www.w3.org/1999/xhtml">

kccagal
08-03-2012, 12:49 PM
I made the change and it hasn't made any difference...the same thing is happening. It stays on the page and not moving to the form.

guelphdad
08-03-2012, 02:26 PM
Please make sure you post in the correct forums. your thread has nothing to do with mysql. Thread moved to PHP forum.

tangoforce
08-03-2012, 03:03 PM
<?php
if(isset($_POST['submit1']))
{
header("Location: createUserAccount.php");
}
else if(isset($_POST[["submit2"]))
{
header("Location: loginUser.php");
}
?>


For simplicities sake, it's better to give all of your buttons the same name when they're in the same form:



<input type="submit" name="mode" value="Create User">
<input type="submit" name="mode" value="Login User">




<?php

if (!isset($_POST['mode']))
{
//Exit or error here
}

switch (strtolower($_POST['mode']))
{
case 'create user':
//Your code here
break;
case 'login user':
//Your code here
break;
}
?>

kccagal
08-04-2012, 05:05 PM
Thank you all for your assistance. I am a student just trying to get this project completed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum