|
 |
|
รับค่าตัวแปร $strid $strname$strmajor มาจาก Mssql ปัญหาการส่งค่าตัวแปร $strid $strname $strmajor ไปที่หน้า save.php |
|
 |
|
|
 |
 |
|
รับค่าตัวแปร $strid $strname$strmajor มาจาก Mssql ปัญหาการส่งค่าตัวแปร $strid $strname $strmajor ไปที่หน้า save.php เป็น mysql ลอง echo ตัวแปร $strid $strname$strmajor หน้า save ค่าเป็น null บันทึกลงฐานข้อมูลไม่ได้ แต่หน้า search เห็นค่าที่มีอยู่ตัวแปรทั้งหมด ทำอย่างไรให้ตัวแปร $strid $strname$strmajor สามารถบันทึกลงฐานข้อมูลได้
หน้า search.php
Code (PHP)
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=window-874">
</head>
<body>
<form name="frmSearch" method="get" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?php
if($_GET["txtKeyword"] != "")
{
$objConnect = mssql_connect("xxx","xxx","xxx");
$objDB = mssql_select_db("script");
mysql_query("SET character_set_results=utf8");
$strSQL = "SELECT * FROM student1 WHERE (Name LIKE '%".$_GET["txtKeyword"]."%' or ID LIKE '%".$_GET["txtKeyword"]."%' ) ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">รหัสนิสิต</div></th>
<th width="98"> <div align="center">ชื่อ-นามสกุลนิสิต</div></th>
<th width="198"> <div align="center">สาขา</div></th>
</tr>
<?php
while($objResult = mssql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["ID"];
$strid.=$objResult["ID"];?></div></td>
<td><?php echo $objResult["NAME"];$strname.=$objResult["NAME"];?></td>
<td><?php echo $objResult["MAJOR"]; $strmajor.=$objResult["MAJOR"];?></td>
</tr>
<?php
}
?>
</table>
<form action="Save.php" name="frmAdd" method="post">
<table width="526" border="1">
<tr>
<th width="160"> <div align="center">ภาคต้น/ปลาย/ฤดูร้อน</div></th>
<th width="198"> <div align="center">ปีการศึกษา </div></th>
<th width="70"> <div align="center">จำนวนเงิน</div></th>
<th width="70"> <div align="center">รายละเอียด </div></th>
</tr>
<tr>
<td><?php /*?><input type="text" name="txtseeson" size="20"><?php */?>
<label for="1"></label>
<select name="txtseeson" id="1">
<option value="1">ภาคต้น</option>
<option value="2">ภาคปลาย</option>
<option value="3">ฤดูร้อน</option>
</select></td>
<td><input type="text" name="txtyear" size="20"></td>
<td align="right"><input type="text" name="txtmoney" size="10"></td>
<td align="right"><input type="text" name="txtnote" size="20"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form>
<p>
<?php
mssql_close($objConnect);
}
?>
</p>
</body>
</html>
หน้า save.php
Code (PHP)
<html>
<head>
<title></title>
</head>
<body>
<?php
$objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
$objDB = mssql_select_db("save_money");
$strSQL = "INSERT INTO money ";
$strSQL .="(ID,NAME,MAJOR,seeson,year,money,note) ";
$strSQL .="VALUES ";
$strSQL .="('".$strid."','".$strname."','".$strmajor."','".$_POST["txtseeson"]."','".$_POST["txtyear"]."','".$_POST["txtmoney"]."' ";
$strSQL .=",'".$_POST["txtnote"]."') ";
$objQuery = mssql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mssql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL, Ms SQL Server 2012

|
ประวัติการแก้ไข 2015-09-18 09:53:12
|
 |
 |
 |
 |
Date :
2015-09-18 09:52:22 |
By :
mininova |
View :
1109 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่านแล้วไม่เข้าใจโค๊ดหลายจุด
<td><?php echo $objResult["NAME"];$strname.=$objResult["NAME"];?></td>
จุดสีแดงข้างบน เป็นการต่อ string
เมื่อเอามาไว้ในลูป แสดงว่า ต้องการต่อ $strname ด้วย field NAME ของทุกเรคคอร์ดเลยหรือครับ
ลองเช็คความต้องการ และใช้โค๊ดให้ถูกต้องด้วยนะครับ
ส่วนตัวแปรที่ไม่ส่งมาเพราะมันไม่สามารถส่งตัวแปรเก่า ไปให้ อีกโปรแกรม ที่ทำการ request ใหม่ได้ครับ
request ใหม่เกิดจากกด submit ใน form ดังนั้นต้องทำการส่งค่าไปด้วยใน form
Code (PHP)
<td><?php echo $objResult["NAME"];$strname.=$objResult["NAME"];?></td>
ให้แก้เป็น
Code (PHP)
<td><input type="hidden" name="strname"
value="<?php echo $strname=$objResult["NAME"];?>" ><?php echo $strname; ?></td>
|
 |
 |
 |
 |
Date :
2015-09-18 10:20:47 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมต้องการนำค่าตัวแปร $strid $strname $strmajor รับมาจากตารางใน Mssql ไปใส่ในตารางของ Mysql
|
 |
 |
 |
 |
Date :
2015-09-18 13:29:13 |
By :
mininova |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากที่แนะนำ คห 1 ตัวอย่าง <input name=strname value="xxxxyyy" type=hidden >
โปรแกรมรับ Save.php ให้กำหนด$strname ตามโค๊ดบันทัดล่างนี้
Code (PHP)
$strname=mysql_real_escape_string($_POST['strname']);
ส่วนตัวแปรที่เหลือก็ทำในลักษณะเดียวกัน
|
 |
 |
 |
 |
Date :
2015-09-18 18:00:39 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|