After using JQuery for form controls validation, I am facing an error as Access forbidden!. But the same page was running properly without using JQuery or after making certain changes in the form tag....
I tell you in details what i need. I have two buttons on my web page, button1 = btn_save and button2 = s_close..
When I click on the btn_save, first it calls the JQuery page for page validation. If it passes the validation
then, the $_POST variables that are present in the newdep.php files
My actual partial code is as:
<?php
session_start();
if(!$_SESSION['sessionusername'])
{
header("location:index.php");
}
else
{
include ('connection2.php');
$local_session = $_SESSION['sessionusername'];
if (isset($_POST['btn_save'])) {
echo "Hi";
include ('PHP/newdep.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$deptid = $_POST['text_depid'];
$deptname = $_POST['text_depname'];
save_fxn($deptid, $deptname);
echo "Hi";
}
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<link rel="stylesheet" media="screen" href="css/master.css">
<link rel="stylesheet" media="screen" href="css/menus.css">
<link href="CSS/pstyle.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="JScript/jquery-1.9.1.js"> </script>
<script type="text/javascript" src="JScript/newdep.js"></script>
<title>Phytec India</title>
</head>
<body>
<?php /*?><form action="newdepartment.php" method="post" id="ndep"><?php */?>
<form action=<?php
if(isset($_POST['s_close']))
{
header("location:department.php");
}
elseif(isset($_POST['btn_save']))
{
header("newdepartment.php");
}
?> method="post" id="ndep">
<div id="welcome">
<div id="welcome_text">Welcome <?php echo "$local_session" ?> <a href="logout.php">Signout</a></div>
</div>
<div id="header">
<div id="header_logo">
<img src="Images/logo.gif" height="29" width="178" />
</div>
</div>
<div id="wrap2">
<p class="validate_msg">Please fix the errors below!</p>
<p> <label for="dep_id">Department Id :</label> <input name="text_depid" type="text" /> <span class="sdepid"></span> </p>
<p> <label for="dep_name">Deparment Name :</label> <input name="text_depname" type="text" /> <span class="sdepname"></span> </p>
<input type="submit" name="btn_save" value="Save">
</form>
</div>
My newdep.php file code where function save definition is saved as shown below:
<?php
function save_fxn($ltxt_deptid, $ltxt_deptname)
{
$query = "SELECT * FROM table_mstr_department WHERE DeptId='$ltxt_deptid'";
$query_result = mysql_query($query);
if(is_resource($query_result) && mysql_num_rows($query_result) > 0 )
{
$sql_result = mysql_fetch_assoc($query_result);
}
else
{
$query = "INSERT INTO table_mstr_department (DeptId, DeptName) VALUES ('$ltxt_deptid','$ltxt_deptname')";
$output = mysql_query($query);
$ltxt_deptid;
$ltxt_deptname;
if(!$output)
{
echo "Data not inserted successfully!";
}
}
}
?>
Working code with little bit modification as shown below:
one change is here:
<form action="submit" method="post" id="ndep">
Another change is here:
<input type="submit" name="btn_save" value="Save">
But the thing is that i want to use the code that i have posted initially and I know I need little bit modification.... PLz help me to solve the issue........