|
|
|
การเก็บ session กับการเรียกใช้ session เพื่อบันทึกลง database ผมใส่ผิดตรงไหนหรือเปล่าครับ |
|
|
|
|
|
|
|
หน้า เก็บ session ครับ
Code (PHP)
<?php
mysql_connect("localhost","root","1234");
mysql_select_db("membernew");
$strSQL = "SELECT * FROM member";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<?php
session_start();
session_unregister("stdid");
session_unregister("name");
session_unregister("number");
?>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
</style>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
</head>
<form name="form1" method="post" action="">
<table width="404" border="1" style="width: 400px">
<tr>
<td width="188" align="right">รหัสนักศึกษา : </td>
<td width="200"><input name="stdid" type="text" id="stdid"></td>
</tr>
<tr>
<td align="right">ขื่อ-สกุล : </td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td align="right">หมายเลขบัตรประชาชน : </td>
<td><input name="number" type="text" id="number"></td>
</tr>
<tr>
<td align="right"><input type="button" name="Button" value="Save" onClick="window.location.href='user_page.php'"></td>
<td> </td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
หน้าเรียกใช้ session ครับ
<?php
mysql_connect("localhost","root","1234");
mysql_select_db("membernew");
mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<?php
session_start();
session_register("stdid");
session_register("name");
session_register("number");
?>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
</style>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
</head>
<?php
$show = "select * from student where stdid = '$stdid'";
$result = mysql_query($show);
if(mysql_num_rows($result)>0){
echo exit ("<script>
alert ('รหัสนักศึกษาซ้ำ กรุณากรอกใหม่');
window.location='user_page.php';
</script>");
}
?>
<?php
//Save data Section
//1. receive data
$stdid=$_POST[stdid];
$name=$_POST[name];
$number=$_POST[number];
$date =$_POST[year].'-'.$_POST[month].'-'.$_POST[date];
if($name!=""){
mysql_query("ALTER TABLE `student` AUTO_INCREMENT =1");
//2. save data
$sql="insert into student
set stdid='$stdid',
name='$name',
topnumber='$number',
time ='$date'";
$result=mysql_query($sql);
//3. Alert and goto show.php
exit ("<script>
alert ('Save Data Complete :D');
window.location='edit_user_page.php';
</script>");
}
?>
<body>
<form name="form1" method="post" action="">
<table width="540" align="center">
<tr>
<td><span id="sprytextfield13"></span></td>
</tr>
</table>
</form>
<p>
</p>
<p> </p>
<table width="540" align="center">
<tr></tr>
<tr>
<td colspan="3" align="center">กรอกข้อมูลนักศึกษาให้ครบถ้วน</td>
</tr>
<tr>
<td width="188" align="right">รหัสนักศึกษา : </td>
<td width="181"><label for="textfield3"><span id="sprytextfield1">
<input type="text" name="stdid" id="stdid" onKeyUp="if(isNaN(this.value)){ alert('กรุณากรอกตัวเลข'); this.value='';}" value="<?php echo $_SESSION["stdid"];?>"/>
<span class="textfieldRequiredMsg">*</span></span></label></td>
<td width="139"><label for="stdid"></label></td>
</tr>
<tr>
<td align="right">ขื่อ-สกุล : </td>
<td><span id="sprytextfield2">
<input type="text" name="name" id="name" onKeyUp="if(!(isNaN(this.value))) { alert('กรุณากรอกอักษร'); this.value='';}" value="<?php echo $_SESSION["name"];?>"/>
<span class="textfieldRequiredMsg">*</span></span></td>
<td><label for="name"></label></td>
</tr>
<tr>
<td align="right">หมายเลขบัตรประชาชน : </td>
<td><span id="sprytextfield3">
<input type="text" name="number" id="number" maxlength="13" onKeyUp="if(isNaN(this.value)){ alert('กรุณากรอกตัวเลข'); this.value='';}" value="<?php echo $_SESSION["number"];?>"/>
<span class="textfieldRequiredMsg">*</span></span></td>
<td> </td>
</tr>
<tr>
<td align="right">วันที่ระบุข้อมูล : </td>
<td><label for="birth"></label>
<select name="date" id="date">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<label for="month"></label>
<select name="month" id="month">
<option value="01">ม.ค.</option>
<option value="01">ก.พ.</option>
<option value="01">มี.ค.</option>
<option value="01">เม.ย.</option>
<option value="01">พ.ค.</option>
<option value="01">มิ.ย.</option>
<option value="01">ก.ค.</option>
<option value="01">ส.ค.</option>
<option value="01">ก.ย.</option>
<option value="01">ต.ค.</option>
<option value="01">พ.ย.</option>
<option value="01">ธ.ค.</option>
</select>
<select name="year" id="year">
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
<td>
<td width="12">
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" id="button" value="ส่งข้อมูล"></td>
<td> </td>
</tr>
</table>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7");
var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8");
var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9");
var sprytextfield10 = new Spry.Widget.ValidationTextField("sprytextfield10");
var sprytextfield11 = new Spry.Widget.ValidationTextField("sprytextfield11");
var sprytextfield12 = new Spry.Widget.ValidationTextField("sprytextfield12");
var sprytextfield13 = new Spry.Widget.ValidationTextField("sprytextfield13");
var sprytextfield14 = new Spry.Widget.ValidationTextField("sprytextfield14");
var sprytextfield15 = new Spry.Widget.ValidationTextField("sprytextfield15");
var sprytextfield16 = new Spry.Widget.ValidationTextField("sprytextfield16");
var sprytextfield17 = new Spry.Widget.ValidationTextField("sprytextfield17");
var sprytextfield18 = new Spry.Widget.ValidationTextField("sprytextfield18");
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");
var sprytextfield20 = new Spry.Widget.ValidationTextField("sprytextfield20");
var sprytextfield21 = new Spry.Widget.ValidationTextField("sprytextfield21");
</script>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2014-10-23 21:35:39 |
By :
jakkrapop |
View :
1252 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
<html>
<head>
<?php
session_start();
session_start();
?>
<html>
<head>
<?php
วางไว้ก่อน การ ส่ง header ต่างๆ
|
|
|
|
|
Date :
2014-10-24 06:59:24 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|