Forum Moderators: coopster
but when ever im sending data to it self like this.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
its working sending data and so on but when im trying it to send data also goes to next page like this.
<form action="process.php" method="post">
its not working what should i do?
here is my code
<?php
require($_SERVER["DOCUMENT_ROOT"] ."site/config/db_config.php");
$connection = mysql_connect("$host","$user","$pass") or die("error connect");
mysql_select_db("$db_name");
if(isset($_POST['submit']))
{
$first_name = $_POST["fname"];
$last_name = $_POST["lastname"];
$email_address = $_POST["email"];
$address = $_POST["address"];
$city = $_POST["city"];
$province = $_POST["province"];
$contact_no = $_POST["contactno"];
$query = "INSERT INTO user_information (first_name, last_name, email_address, address, city, province, contact_no) VALUES('$first_name', '$last_name', '$email_address', '$address', '$city', '$province', '$contact_no')";
mysql_query($query, $connection) or die(mysql_error());
}
?>
<!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=utf-8" />
<title>Online Bus Ticket Reservation System</title>
<link href="obrs.css" rel="stylesheet" type="text/css" />
<!--[if IE 5]>
<style type="text/css">
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixRtHdr #sidebar1 { width: 220px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixRtHdr #sidebar1 { padding-top: 30px; }
.twoColFixRtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
.style1 {
color: #FFFF00;
font-weight: bold;
}
.style2 {
color: #FFFF66;
font-weight: bold;
}
.style8 {
color: #0066FF;
font-weight: bold;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 ¦¦ p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min ¦¦ max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body class="twoColFixRtHdr">
<div id="container">
<div id="header">
<!-- end #header -->
<img src="images/header" alt="OBTRS: Header" /></div>
<div id="sidebar1">
<!-- end #sidebar1 -->
<img src="images/sidebar_slideshow" alt="" />
<div id="blogarea">
<p class="style2">Casual Dining Restaurants</p>
<p><br>
Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p>
<p><br>
<span class="style1">Convenience Stores</span></p>
<p><br>
Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be "fast" to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong "team spirit" that provides the customers what they are looking for as they travel.</p>
</div>
</div>
<div id="mainContent">
<div id="nav">
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9, 0,28,0', 'width','760','height','30','src','images/nav_bar2', 'quality','high','pluginspage', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', 'movie','images/nav_bar2' ); //end AC code
</script>
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30">
<param name="movie" value="images/nav_bar2.swf" />
<param name="quality" value="high" />
<embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed>
</object>
</noscript>
</div>
<div id="features"></div>
<div class="style8" id="writeinfo">Please Fill your Personal Information below</div>
<div id="forminfo"><form name="theform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
First Name:
<INPUT name=fname type="text" id="fname" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Last Name:
<INPUT name=lastname type="text" id="lastname" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Email Address: <INPUT name=email type="text" id="email" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Address:
<INPUT name=address type="text" id="address" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
City:
<INPUT name=city type="text" id="city" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Province:
<INPUT name=province type="text" id="province" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Contact No:
<INPUT name=contactno type="text" id="contactno" style="HEIGHT: 19px; WIDTH: 174px" size="20" maxlength="11" align="center">
<br>
<br>
<br>
<input name="submit" type="submit" onclick="MM_validateForm('fname','','R','lastname','','R','email','','RisEmail','address','','R','city','','R','province','','R','contactno','','RisNum');return document.MM_returnValue" value="submit" />
</form>
</div>
<!-- end #mainContent -->
</div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
<br class="clearfloat" />
<div id="footer">
<p><a href="aboutus.html">About us</a> ¦<a href="feedback.html"> Feedback</a> ¦<a href="faqs.html"> FAQs</a> ¦ <a href="terms.html">Terms & Conditions</a> ¦ <a href="contactus.html">Contact us</a></p>
<p> 2009 Copyright - Shah Abdul Latif University Khairpur</p>
<!-- end #footer -->
</div>
<!-- end #container -->
</div>
</body>
</html>
[edited by: eelixduppy at 7:42 pm (utc) on May 12, 2009]
[edit reason] fixed side scroll [/edit]
Secondly, your query is confusing. However, if your form says:
action="<?php echo $_SERVER['PHP_SELF']; ?>" - It submits to itself, meaning your processing code will be contained within the same page.
action="process.php" - It submits to process.php and your processing codee will be in here.
You got to make a conscious decision as to where you want your processing to take place, ie, same page or a different page.
I hope I have tried to clarify your query, if I have understood your confusion.