PDA

View Full Version : how to solve the conflict of 2 submit buttons in one form



mya7709
10-22-2011, 01:23 AM
<?php
session_start();
ob_start();
include("connection.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>

<script type="text/javascript">
$(function() {
$('#sdt_menu > li').bind('mouseenter',function(){
var $elem = $(this);
$elem.find('img')
.stop(true)
.animate({
'width':'140px',
'height':'140px',
'left':'20px'
},400,'easeOutBack')
.andSelf()
.find('.sdt_wrap')
.stop(true)
.animate({'top':'140px'},500,'easeOutBack')
.andSelf()
.find('.sdt_active')
.stop(true)
.animate({'height':'140px'},300,function(){
var $sub_menu = $elem.find('.sdt_box');
if($sub_menu.length){
var left = '140px';
if($elem.parent().children().length == $elem.index()+1)
left = '-120px'; /*distance adjustement for submenu*/
$sub_menu.show().animate({'left':left},200);
}
});
}).bind('mouseleave',function(){
var $elem = $(this);
var $sub_menu = $elem.find('.sdt_box');
if($sub_menu.length)
$sub_menu.hide().css('left','0px');

$elem.find('.sdt_active')
.stop(true)
.animate({'height':'0px'},300)
.andSelf().find('img')
.stop(true)
.animate({
'width':'0px',
'height':'0px',
'left':'85px'},400)
.andSelf()
.find('.sdt_wrap')
.stop(true)
.animate({'top':'35px'},500);
});
});
</script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script>



// This method is called right before the ajax form validation request

// it is typically used to setup some visuals ("Please wait...");

// you may return a false to stop the request

function beforeCall(form, options){

if (window.console)

console.log("Right before the AJAX form validation call");

return false;

}



// Called once the server replies to the ajax form validation request

function ajaxValidationCallback(status, form, json, options){

if (window.console)

console.log(status);



if (status === false) {

alert("the form is valid!");

// uncomment these lines to submit the form to form.action

// form.validationEngine('detach');

// form.submit();

// or you may use AJAX again to submit the data

}

}



jQuery(document).ready(function(){

jQuery("#formID").validationEngine({

ajaxFormValidation: false,

onAjaxFormComplete: ajaxValidationCallback,

});

});

</script>

<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>

<style type="text/css">
<!--

body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style25 {
font-size: 10px;
font-family: Verdana;
}
.style28 {
font-size: 9px;
font-family: Verdana;
font-weight: bold;
}
.style31 {font-size: 10px; font-family: Verdana; font-weight: bold; }

-->
</style>
</head>

<body onLoad="document.forms[0].id.focus()">
<form id="formID" class="test" name="frm" method="post">
<table width="100%" border="0">
<tr>
<td align="right" colspan="3">
<table width="20%" border="0" style="margin-bottom:-1px">
<tr>
<td><span class="style31">Username</span></td>
<td><span class="style31">:</span></td>
<td><input name = "username" type="text" size="12" /></td>
<td><span class="style31">Password</span></td>
<td><span class="style31">:</span></td>
<td><input name="pass" type="password" size="12" /></td>
<td><div align="center" class="style25">
<input name="login" type="submit" value="login"/>
</div></td>
<td align="left"><a href="forgotpass.php" class="style31">Forgot password?</a></td>
</tr>
<tr style="margin-left:100px">
<td colspan="7" align="left"><span class="style28">
<input type="radio" value="admin" name="user">
Admin
<input type="radio" value="customer" name="user" checked="checked">
Customer</span>
<span class="style28" style="margin-left:0px"><a href="reg_cus_registration.php">New User?</a></span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<div class="content" align="center" style="margin-left:130px">
<ul id="sdt_menu" class="sdt_menu">
<li>
<a href="login.php">
<img src="images/1.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Home</span> </span>
</a></li>
<li>
<a href="#">
<img src="images/1.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Portfolio</span>
</span>
</a>
<div class="sdt_box" style="margin-left:20px">
<a href="#">Websites</a>
<a href="#">Illustrations</a>
<a href="#">Photography</a>
</div>
</li>
<li>
<a href="#">
<img src="images/3.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Inspiration</span>
</span> </a> </li>
<li>
<a href="#">
<img src="images/4.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Photos</span>
</span> </a> </li>
<li>
<a href="#">
<img src="images/5.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Blog</span>
</span> </a> </li>
<li>
<a href="#">
<img src="images/6.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Projects</span>
</span> </a>
<div class="sdt_box">
<a href="#">Job Board Website</a>
<a href="#">Shopping Cart</a>
<a href="#">Interactive Maps</a>
</div>
</li>
</ul>
</div></td>

</tr>
<tr>
<td width="10%"></td>
<td width="80%" align="center" height="auto">
<table width="auto" border="0">
<tr class="formular">
<td>Username</td>
<td>:</td>
<td><input value="" class="validate[required,ajax[ajaxUserCallPhp]] text-input" type="text" name="username" id="username" /></td>
</tr>
<tr class="formular">
<td>Password</td>
<td>:</td>
<td><input value="" class="validate[required] text-input" type="password" name="password" id="password" />
</td>
</tr>
<tr class="formular">
<td>Confirm Password</td>
<td>:</td>
<td><input value="" class="validate[required,equals[password]] text-input" type="password" name="password2" id="password2" />
</td>
</tr>
<tr>
<td colspan="3" class="formular">
<fieldset>
<legend>
Security
</legend>
<table border="0">
<tr>
<td>Name</td>
<td>:</td>
<td><input value="" class="validate[required,custom[onlyLetterSp]] text-input" name="name" id="name" type="text" /></td>
</tr>
<tr>
<td>Brthdate</td>
<td>:</td>
<td><input value="YYYY-MM-DD" class="validate[required,custom[date]] text-input" type="text" name="date" id="date" /></td>
</tr>
<tr>
<td>IC number</td>
<td>:</td>
<td><input value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="ic" id="ic" /></td>
</tr>
<tr>
<td>Gender</td>
<td>:</td>
<td><select name="gender" id="gender" class="validate[required]">
<option value="">Choose your gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input value="" class="validate[required,custom[email]] text-input" type="text" name="email" id="email" />
</td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input value="" class="validate[required] text-input" type="text" name="add" id="add" /></td>
</tr>
<tr>
<td>H/P</td>
<td>:</td>
<td><input value="" class="validate[required,custom[phone]] text-input" type="text" name="telephone" id="telephone" />
</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status" id="status" class="validate[required]">
<option value="">Choose your status</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
</select>
</td>
</tr>
</table>
</fieldset>
</td>

</tr>
<tr>
<td colspan="3" class="formular">
<fieldset>
<legend>
Security
</legend>
<table border="0">
<tr>
<td><label><span>Question</span></label></td>
<td>:</td>
<td> <select name="ques" id="ques" class="validate[required]">
<option value="">Choose your question</option>
<option value="ques1">Where is your hometown?</option>
<option value="ques2">Who is your beloved person?</option>
</select></td>
</tr>
<tr>
<td>Answer</td>
<td>:</td>
<td><input value="" class="validate[required] text-input" type="text" name="ans" id="ans" /></td>
</tr>
</table>
</fieldset>
</td>

</tr>
<tr>
<td colspan="3"><input type="reset" id="clear" name="clear" value="Reset">
<input name="register" type="button" value="Register"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

</td>
<td width="10%"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if (isset($_POST["login"]))
{
$id= $_POST["username"];
$pass= $_POST["pass"];
$cuser= $_POST["user"];

if ($cuser=="admin")
{

$result = mysql_query("select * from admin where admin_id ='$id' and admin_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["admin_id"] = $row["admin_id"];
header("Location: admin_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

if ($cuser=="customer")
{
$result = mysql_query("select * from reg_cus where cus_user='$id' and cus_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["cus_id"] = $row["cus_id"];
header("Location: reg_cus_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

}

else if (isset($_POST["register"]))
{
$username= $_POST["username"];
$pass= $_POST["password"];
$name= $_POST["name"];
$birthdate= $_POST["date"];
$ic= $_POST["ic"];
$gender= $_POST["gender"];
$email= $_POST["email"];
$add= $_POST["add"];
$hp= $_POST["telephone"];
$status= $_POST["status"];
$ques= $_POST["ques"];
$ans= $_POST["ans"];

mysql_query("insert into reg_cus
(cus_user,cus_pass,cus_name,cus_birthdate,cus_gender,cus_email,cus_per_add,cus_hp,cus_ic,cus_status, cus_ques,cus_ans) values
('$username','$pass','$name','$birthdate','$gender','$email','$add','$hp','$ic','$status','$ques','$ ans')");

?>
<script type="text/javascript">
alert("Register successful");
</script>
<?

}
?>

i tried to use if else statement to separate 2 different submit buttons but i failed. who have other methods can solve this for me pls, thank you.

tangoforce
10-22-2011, 10:06 AM
First: Use
tags.

You have 9 posts now so you've had chance to read the sticky topic and abide by it. Not doing so will make many people not reply to you - you have a very large amount of code and its not easy to read or understand. There is a link in my signature about [php] tags - it will take you to the sticky topic.

Second: What is the exact problem you are having? - You say its something to do with two submit buttons but you don't tell us the exact problem you're having. You can use multiple submit buttons - just give them the same name - like this:



<input type="submit" name="action" value="Register">
<input type="submit" name="action" value="Login">


[php]
if (isset($_POST['action']))
{
switch (strtolower($_POST['action']))
{
case 'register':
//Your code here
break;
case 'login':
//Your code here
break;
}
}

mya7709
10-22-2011, 01:59 PM
there are 2 submit type buttons in one form, which are register and login, the 2 buttons conflict with each function, i tried what u showed me, the login and register button still conflicts


<td><div align="center" class="style25">
<input type="submit" name="action" value="Login">
</div></td>

above is my login button

td colspan="3"><input name="action" type="submit" value="Register"/></td>

above is my register button

i do what u said

<?php
if (isset($_POST['action']))
{
switch (strtolower($_POST['action']))
{
case 'Login':

$id= $_POST["username"];
$pass= $_POST["pass"];
$cuser= $_POST["user"];

if ($cuser=="admin")
{

$result = mysql_query("select * from admin where admin_id ='$id' and admin_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["admin_id"] = $row["admin_id"];
header("Location: admin_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

if ($cuser=="customer")
{
$result = mysql_query("select * from reg_cus where cus_user='$id' and cus_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["cus_id"] = $row["cus_id"];
header("Location: reg_cus_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}
break;

case 'Register':

$username= $_POST["username"];
$pass= $_POST["password"];
$name= $_POST["name"];
$birthdate= $_POST["date"];
$ic= $_POST["ic"];
$gender= $_POST["gender"];
$email= $_POST["email"];
$add= $_POST["add"];
$hp= $_POST["telephone"];
$status= $_POST["status"];
$ques= $_POST["ques"];
$ans= $_POST["ans"];

mysql_query("insert into reg_cus
(cus_user,cus_pass,cus_name,cus_birthdate,cus_gender,cus_email,cus_per_add,cus_hp,cus_ic,cus_status, cus_ques,cus_ans) values
('$username','$pass','$name','$birthdate','$gender','$email','$add','$hp','$ic','$status','$ques','$ ans')");

?>
<script type="text/javascript">
alert("Register successful");
</script>
<?

break;

}
}
?>
the first part is about login and the second part is register.
unfortunately it still cannot functions. when i click on login button, it performs like a register button

mya7709
10-22-2011, 02:01 PM
i saw another method, which is use jquery and ajax, but it is too complicated, i dun really understand how to do that

tangoforce
10-22-2011, 03:08 PM
there are 2 submit type buttons in one form, which are register and login, the 2 buttons conflict with each function, i tried what u showed me, the login and register button still conflicts


<td><div align="center" class="style25">
<input type="submit" name="action" value="Login">
</div></td>

above is my login button

td colspan="3"><input name="action" type="submit" value="Register"/></td>

above is my register button

i do what u said

<?php
if (isset($_POST['action']))
{
switch (strtolower($_POST['action']))
{
case 'Login':

$id= $_POST["username"];
$pass= $_POST["pass"];
$cuser= $_POST["user"];

if ($cuser=="admin")
{

$result = mysql_query("select * from admin where admin_id ='$id' and admin_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["admin_id"] = $row["admin_id"];
header("Location: admin_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

if ($cuser=="customer")
{
$result = mysql_query("select * from reg_cus where cus_user='$id' and cus_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["cus_id"] = $row["cus_id"];
header("Location: reg_cus_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}
break;

case 'Register':

$username= $_POST["username"];
$pass= $_POST["password"];
$name= $_POST["name"];
$birthdate= $_POST["date"];
$ic= $_POST["ic"];
$gender= $_POST["gender"];
$email= $_POST["email"];
$add= $_POST["add"];
$hp= $_POST["telephone"];
$status= $_POST["status"];
$ques= $_POST["ques"];
$ans= $_POST["ans"];

mysql_query("insert into reg_cus
(cus_user,cus_pass,cus_name,cus_birthdate,cus_gender,cus_email,cus_per_add,cus_hp,cus_ic,cus_status, cus_ques,cus_ans) values
('$username','$pass','$name','$birthdate','$gender','$email','$add','$hp','$ic','$status','$ques','$ ans')");

?>
<script type="text/javascript">
alert("Register successful");
</script>
<?

break;

}
}
?>
the first part is about login and the second part is register.
unfortunately it still cannot functions. when i click on login button, it performs like a register button

It's right there under your nose: - strtolower() - inside the switch.

Now, strtolower('Register') will become register

So why are you using case 'Register' and case 'Login' ?

Look at the code I gave you above again. You will see that both cases use lowercase strings.

mya7709
10-22-2011, 03:28 PM
i change to

<?php
if (isset($_POST['action']))
{

switch (strtolower($_POST['action']))
{
case 'login':

$id= $_POST["username"];
$pass= $_POST["pass"];
$cuser= $_POST["user"];

if ($cuser=="admin")
{

$result = mysql_query("select * from admin where admin_id ='$id' and admin_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["admin_id"] = $row["admin_id"];
header("Location: admin_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

if ($cuser=="customer")
{
$result = mysql_query("select * from reg_cus where cus_user='$id' and cus_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["cus_id"] = $row["cus_id"];
header("Location: reg_cus_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}
break;

case 'register':

$username= $_POST["username"];
$pass= $_POST["password"];
$name= $_POST["name"];
$birthdate= $_POST["date"];
$ic= $_POST["ic"];
$gender= $_POST["gender"];
$email= $_POST["email"];
$add= $_POST["add"];
$hp= $_POST["telephone"];
$status= $_POST["status"];
$ques= $_POST["ques"];
$ans= $_POST["ans"];

mysql_query("insert into reg_cus
(cus_user,cus_pass,cus_name,cus_birthdate,cus_gender,cus_email,cus_per_add,cus_hp,cus_ic,cus_status, cus_ques,cus_ans) values
('$username','$pass','$name','$birthdate','$gender','$email','$add','$hp','$ic','$status','$ques','$ ans')");

?>
<script type="text/javascript">
alert("Register successful");
</script>
<?

break;

}
}
?>

which i change to lower case for the 1st character for login and register. it still cannot works... when i click the login button. it will jump to the registration form to do the validation. i have use the javascript to validate my input field. so how?

tangoforce
10-22-2011, 04:28 PM
In that case, change this:
if (isset($_POST['action']))
{

To this:
if (isset($_POST['action']))
{
var_dump($_POST);

Then report back here with the output.

mya7709
10-23-2011, 04:13 AM
<?php
if (isset($_POST['action']))
{
var_dump($_POST);

switch (strtolower($_POST['action']))
{
case 'login':

$id= $_POST["username"];
$pass= $_POST["pass"];
$cuser= $_POST["user"];

if ($cuser=="admin")
{

$result = mysql_query("select * from admin where admin_id ='$id' and admin_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["admin_id"] = $row["admin_id"];
header("Location: admin_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

if ($cuser=="customer")
{
$result = mysql_query("select * from reg_cus where cus_user='$id' and cus_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["cus_id"] = $row["cus_id"];
header("Location: reg_cus_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}
break;

case 'register':

$username= $_POST["username"];
$pass= $_POST["password"];
$name= $_POST["name"];
$birthdate= $_POST["date"];
$ic= $_POST["ic"];
$gender= $_POST["gender"];
$email= $_POST["email"];
$add= $_POST["add"];
$hp= $_POST["telephone"];
$status= $_POST["status"];
$ques= $_POST["ques"];
$ans= $_POST["ans"];

mysql_query("insert into reg_cus
(cus_user,cus_pass,cus_name,cus_birthdate,cus_gender,cus_email,cus_per_add,cus_hp,cus_ic,cus_status, cus_ques,cus_ans) values
('$username','$pass','$name','$birthdate','$gender','$email','$add','$hp','$ic','$status','$ques','$ ans')");

?>
<script type="text/javascript">
alert("Register successful");
</script>
<?

break;

}
}
?>

Here it is, i changed, but still cannot work. Is there any possible mistake i made in my script?

tangoforce
10-23-2011, 11:02 AM
Then report back here with the output.

Run the script, show us what var_dump() outputs on your page.

mya7709
10-23-2011, 02:01 PM
outputs? there is no outputs shown in the page, when i click login, it jumps to checks the input fields

tangoforce
10-23-2011, 05:50 PM
unfortunately it still cannot functions. when i click on login button, it performs like a register button


outputs? there is no outputs shown in the page, when i click login, it jumps to checks the input fields

So if it is still acting like a register button and you've placed var_dump($_POST) in the correct place then you should be seeing some output like:

array('action' => 'register') or something.

If you're not seeing that then something else is going on that you're not telling us about or perhaps you've edited the wrong copy of the script or something.

Dubz
10-24-2011, 12:25 AM
So if it is still acting like a register button and you've placed var_dump($_POST) in the correct place then you should be seeing some output like:

array('action' => 'register') or something.

If you're not seeing that then something else is going on that you're not telling us about or perhaps you've edited the wrong copy of the script or something.

the value is just what shows on the button (ex. value="Login" will showLogin on the button) it does not do anything else. Try changing the name of it (action) to their own name so their separated like this:


<input type="submit" name="register" value="Register">
<input type="submit" name="login" value="Login">


the php part will be like this then:


if(isset($_POST['register'])){
//Register action
}
if(isset($_POST['login'])){
//Login action
}

That way it wil search if that button is actually pressed and then do the action if it is.

Input types:
button- Defines a clickable button (mostly used with a JavaScript to activate a script)
checkbox- Defines a checkbox
file- Defines an input field and a "Browse..." button, for file uploads
hidden- Defines a hidden input field
image- Defines an image as a submit button
password- Defines a password field. The characters in this field are masked
radio- Defines a radio button
reset- Defines a reset button. A reset button resets all form fields to their initial values
submit- Defines a submit button. A submit button sends form data to a server
text- Defines a one-line input field that a user can enter text into. Default width is 20 characters

the name just defines a name for the input so the script knows which is which, and the value is what is displayed (if needed)

mya7709
10-24-2011, 05:15 AM
<?php
session_start();
ob_start();
include("connection.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>

<script type="text/javascript">
$(function() {
$('#sdt_menu > li').bind('mouseenter',function(){
var $elem = $(this);
$elem.find('img')
.stop(true)
.animate({
'width':'140px',
'height':'140px',
'left':'20px'
},400,'easeOutBack')
.andSelf()
.find('.sdt_wrap')
.stop(true)
.animate({'top':'140px'},500,'easeOutBack')
.andSelf()
.find('.sdt_active')
.stop(true)
.animate({'height':'140px'},300,function(){
var $sub_menu = $elem.find('.sdt_box');
if($sub_menu.length){
var left = '140px';
if($elem.parent().children().length == $elem.index()+1)
left = '-120px'; /*distance adjustement for submenu*/
$sub_menu.show().animate({'left':left},200);
}
});
}).bind('mouseleave',function(){
var $elem = $(this);
var $sub_menu = $elem.find('.sdt_box');
if($sub_menu.length)
$sub_menu.hide().css('left','0px');

$elem.find('.sdt_active')
.stop(true)
.animate({'height':'0px'},300)
.andSelf().find('img')
.stop(true)
.animate({
'width':'0px',
'height':'0px',
'left':'85px'},400)
.andSelf()
.find('.sdt_wrap')
.stop(true)
.animate({'top':'35px'},500);
});
});
</script>

<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<style type="text/css">
<!--

body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style25 {
font-size: 10px;
font-family: Verdana;
}
.style28 {
font-size: 9px;
font-family: Verdana;
font-weight: bold;
}
.style31 {font-size: 10px; font-family: Verdana; font-weight: bold; }

-->
</style>
</head>

<body>
<form id="formID" name="formID" method="post">
<table width="20%" border="0" style="margin-bottom:-1px">
<tr>
<td><span class="style31">Username</span></td>
<td><span class="style31">:</span></td>
<td><input id="username" name = "username" type="text" size="12" /></td>
<td><span class="style31">Password</span></td>
<td><span class="style31">:</span></td>
<td><input id="pass" name="pass" type="password" size="12" /></td>
<td><div align="center" class="style25">
<input type="submit" name="action" value="Login">
</div></td>
<td align="left"><a href="forgotpass.php" class="style31">Forgot password?</a></td>
</tr>
<tr style="margin-left:100px">
<td colspan="7" align="left"><span class="style28">
<input type="radio" value="admin" name="user">
Admin
<input type="radio" value="customer" name="user" checked="checked">
Customer</span>
<span class="style28" style="margin-left:0px"><a href="reg_cus_registration.php">New User?</a></span></td>
</tr>
</table>

<table width="100%" border="0">
<tr>
<td colspan="3" align="center">
<div class="content" align="center" style="margin-left:130px">
<ul id="sdt_menu" class="sdt_menu">
<li>
<a href="login.php">
<img src="images/1.png" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Home</span>
</span></a></li>
<li>
<a href="#">
<img src="images/1.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Portfolio</span>
</span>
</a>
<div class="sdt_box" style="margin-left:20px">
<a href="#">Websites</a>
<a href="#">Illustrations</a>
<a href="#">Photography</a>
</div>
</li>
<li>
<a href="#">
<img src="images/3.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Inspiration</span>
</span></a></li>
<li>
<a href="#">
<img src="images/4.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Photos</span>
</span></a></li>
<li>
<a href="#">
<img src="images/5.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Blog</span>
</span></a></li>
<li>
<a href="#">
<img src="images/6.jpg" alt=""/>
<span class="sdt_active"></span>
<span class="sdt_wrap">
<span class="sdt_link">Projects</span>
</span></a>
<div class="sdt_box">
<a href="#">Job Board Website</a>
<a href="#">Shopping Cart</a>
<a href="#">Interactive Maps</a>
</div>
</li>
</ul>
</div></td>
</tr>
</table>

<table align="center">
<tr>
<td width="10%"></td>
<td width="80%" align="center" height="auto">
<table width="auto" border="0">
<tr class="formular">
<td>Username</td>
<td>:</td>
<td><input class="validate[required,ajax[ajaxUserCallPhp]] text-input" type="text" name="username" id="username" /></td>
</tr>
<tr class="formular">
<td>Password</td>
<td>:</td>
<td><input class="validate[required] text-input" type="password" name="password" id="password" />
</td>
</tr>
<tr class="formular">
<td>Confirm Password</td>
<td>:</td>
<td><input class="validate[required,equals[password]] text-input" type="password" name="password2" id="password2" />
</td>
</tr>
<tr>
<td colspan="3" class="formular">
<fieldset>
<legend>
Security
</legend>
<table border="0">
<tr>
<td>Name</td>
<td>:</td>
<td><input class="validate[required,custom[onlyLetterSp]] text-input" name="name" id="name" type="text" /></td>
</tr>
<tr>
<td>Brthdate</td>
<td>:</td>
<td><input class="validate[required,custom[date]] text-input" type="text" name="date" id="date" /></td>
</tr>
<tr>
<td>IC number</td>
<td>:</td>
<td><input class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="ic" id="ic" /></td>
</tr>
<tr>
<td>Gender</td>
<td>:</td>
<td><select name="gender" id="gender" class="validate[required]">
<option value="">Choose your gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input class="validate[required,custom[email]] text-input" type="text" name="email" id="email" />
</td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input class="validate[required] text-input" type="text" name="add" id="add" /></td>
</tr>
<tr>
<td>H/P</td>
<td>:</td>
<td><input class="validate[required,custom[phone]] text-input" type="text" name="tel" id="tel" />
</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status" id="status" class="validate[required]">
<option value="">Choose your status</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
</select>
</td>
</tr>
</table>
</fieldset>
</td>

</tr>
<tr>
<td colspan="3" class="formular">
<fieldset>
<legend>
Security
</legend>
<table border="0">
<tr>
<td><label><span>Question</span></label></td>
<td>:</td>
<td> <select name="ques" id="ques" class="validate[required]">
<option value="">Choose your question</option>
<option value="ques1">Where is your hometown?</option>
<option value="ques2">Who is your beloved person?</option>
</select></td>
</tr>
<tr>
<td>Answer</td>
<td>:</td>
<td><input value="" class="validate[required] text-input" type="text" name="ans" id="ans" /></td>
</tr>
</table>
</fieldset>
</td>

</tr>
<tr>
<td colspan="3"><input type="reset" id="clear" name="action" value="Reset">
<input name="register" type="submit" value="Register"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

</td>
<td width="10%"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if (isset($_POST['action']))
{
var_dump($_POST);

switch (strtolower($_POST['action']))
{
case 'login':

$id= $_POST["username"];
$pass= $_POST["pass"];
$cuser= $_POST["user"];

if ($cuser=="admin")
{

$result = mysql_query("select * from admin where admin_id ='$id' and admin_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["admin_id"] = $row["admin_id"];
header("Location: admin_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}

if ($cuser=="customer")
{
$result = mysql_query("select * from reg_cus where cus_user='$id' and cus_pass='$pass'");
if ($row=mysql_fetch_assoc($result))
{
$_SESSION["cus_id"] = $row["cus_id"];
header("Location: reg_cus_profile.php");
}
else
{?>
<script type="text/javascript">
alert("Invalid");
</script><?php }
}
break;

case 'register':

$username= $_POST["username"];
$pass= $_POST["password"];
$name= $_POST["name"];
$birthdate= $_POST["date"];
$ic= $_POST["ic"];
$gender= $_POST["gender"];
$email= $_POST["email"];
$add= $_POST["add"];
$hp= $_POST["telephone"];
$status= $_POST["status"];
$ques= $_POST["ques"];
$ans= $_POST["ans"];

mysql_query("insert into reg_cus
(cus_user,cus_pass,cus_name,cus_birthdate,cus_gender,cus_email,cus_per_add,cus_hp,cus_ic,cus_status, cus_ques,cus_ans) values
('$username','$pass','$name','$birthdate','$gender','$email','$add','$hp','$ic','$status','$ques','$ ans')");

?>
<script type="text/javascript">
alert("Register successful");
</script>
<?

break;

}
}
?>


above is the latest code for the page, when i click the login button, it shows this at the bottom of my page after i disable the form validation javascript. but my register button still not working


array(16) { ["username"]=> string(0) "" ["pass"]=> string(8) "686635c0" ["action"]=> string(5) "Login" ["user"]=> string(8) "customer" ["password"]=> string(0) "" ["password2"]=> string(0) "" ["name"]=> string(0) "" ["date"]=> string(0) "" ["ic"]=> string(0) "" ["gender"]=> string(0) "" ["email"]=> string(0) "" ["add"]=> string(0) "" ["tel"]=> string(0) "" ["status"]=> string(0) "" ["ques"]=> string(0) "" ["ans"]=> string(0) "" }

mya7709
10-24-2011, 05:19 AM
it seems cant get my username

mya7709
10-24-2011, 09:35 AM
i solved the problem, i can register and login now, but only if i delete the function for the validation. Is there possible to crash between php and jquery?

tangoforce
10-24-2011, 11:05 AM
the value is just what shows on the button (ex. value="Login" will showLogin on the button) it does not do anything else. Try changing the name of it (action) to their own name so their separated like this:


<input type="submit" name="register" value="Register">
<input type="submit" name="login" value="Login">


the php part will be like this then:


if(isset($_POST['register'])){
//Register action
}
if(isset($_POST['login'])){
//Login action
}



Dubz, If you want to come and take over from more experienced programmers with code and techniques which is less efficient then you're not going to make yourself a good name.

There is nothing wrong with the code I have provided, it works in countless scenarios and as the user has just stated it works when his validation is removed. I appreciate you think you're trying to help but your inexperience in php shows by the very fact that you don't understand this method or why a switch is even used.

Please, in the future, unless you understand the code, don't comment on it or recommend less efficient code.