|
|
|
อยากให้มันดึงข้อมูลจากการใส่รหัสสมาชิกครับ รบกวนด้วยครับ มือใหม่มาก ๆ |
|
|
|
|
|
|
|
ตอนเพิ่ม ข้อมูลอยากให้มันดึงข้อมูลจากการ ใส่รหัสลูกค้าครับ เช่น ใส่รหัสลูกค้าแล้ว ชื่อ นามสกุล โผ่ลมาเองเลย มือใหม่มาก ๆ กำลังทำโปรเจคจบเกี่ยวกับระบบจัดการฐานข้อมูลผ่านเว็บครับ รบกวนด้วยนะครับ
Code (PHP)
<?php require_once('Connections/MyConnect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO q_foraddpoint (shop, `no`, name, lastname, product, `size`, quantity, price, score, buydate, savedate, employadd) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['shop'], "text"),
GetSQLValueString($_POST['no'], "int"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['lastname'], "text"),
GetSQLValueString($_POST['product'], "text"),
GetSQLValueString($_POST['size'], "text"),
GetSQLValueString($_POST['quantity'], "int"),
GetSQLValueString($_POST['price'], "int"),
GetSQLValueString($_POST['score'], "int"),
GetSQLValueString($_POST['buydate'], "text"),
GetSQLValueString($_POST['savedate'], "text"),
GetSQLValueString($_POST['employadd'], "text"));
mysql_select_db($database_MyConnect, $MyConnect);
$Result1 = mysql_query($insertSQL, $MyConnect) or die(mysql_error());
$insertGoTo = "q_foraddpoint.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_MyConnect, $MyConnect);
$query_em = "SELECT * FROM employ";
$em = mysql_query($query_em, $MyConnect) or die(mysql_error());
$row_em = mysql_fetch_assoc($em);
$totalRows_em = mysql_num_rows($em);
mysql_select_db($database_MyConnect, $MyConnect);
$query_pro = "SELECT * FROM product";
$pro = mysql_query($query_pro, $MyConnect) or die(mysql_error());
$row_pro = mysql_fetch_assoc($pro);
$totalRows_pro = mysql_num_rows($pro);
mysql_select_db($database_MyConnect, $MyConnect);
$query_cus = "SELECT * FROM real_db";
$cus = mysql_query($query_cus, $MyConnect) or die(mysql_error());
$row_cus = mysql_fetch_assoc($cus);
$totalRows_cus = mysql_num_rows($cus);
mysql_select_db($database_MyConnect, $MyConnect);
$query_size = "SELECT * FROM `size`";
$size = mysql_query($query_size, $MyConnect) or die(mysql_error());
$row_size = mysql_fetch_assoc($size);
$totalRows_size = mysql_num_rows($size);
mysql_select_db($database_MyConnect, $MyConnect);
$query_deal = "SELECT * FROM table_dealer";
$deal = mysql_query($query_deal, $MyConnect) or die(mysql_error());
$row_deal = mysql_fetch_assoc($deal);
$totalRows_deal = mysql_num_rows($deal);
?>
<!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>- ระบบบันทึกการซื้อและคะแนน -</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<h1 align="center"><strong>เพิ่มข้อมูลการซื้อสินค้า</strong></h1>
<table width="723" height="391" align="center">
<tr valign="baseline">
<td width="83" align="right" nowrap="nowrap">ร้านค้า :</td>
<td width="192"><select name="shop">
<?php
do {
?>
<option value="<?php echo $row_deal['Dealer']?>" ><?php echo $row_deal['Dealer']?></option>
<?php
} while ($row_deal = mysql_fetch_assoc($deal));
?>
</select></td>
<td width="90"> </td>
<td width="10"> </td>
<td width="73"> </td>
<td width="211"> </td>
<td width="32"><h1> </h1></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">รหัสสมาชิก :</td>
<td><input name="no" type="text" size="32" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td height="24" align="right" nowrap="nowrap">ชื่อ :</td>
<td><input name="name" type="text" size="32" /></td>
<td> </td>
<td> </td>
<td>นามสกุล</td>
<td><input type="text" name="lastname" value="" size="32" /></td>
<td> </td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">สินค้า :</td>
<td><select name="product">
<?php
do {
?>
<option value="<?php echo $row_pro['product']?>" ><?php echo $row_pro['product']?></option>
<?php
} while ($row_pro = mysql_fetch_assoc($pro));
?>
</select></td>
<td> </td>
<td> </td>
<td>ขนาด :</td>
<td><select name="size">
<?php
do {
?>
<option value="<?php echo $row_size['Size']?>" ><?php echo $row_size['Size']?></option>
<?php
} while ($row_size = mysql_fetch_assoc($size));
?>
</select></td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">จำนวน :</td>
<td><input type="text" name="quantity" value="" size="32" /></td>
<td>ถัง</td>
<td> </td>
<td>ราคา :</td>
<td><input type="text" name="price" value="" size="32" /></td>
<td>บาท</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">คะแนนที่ได้ :</td>
<td><input type="text" name="score" value="" size="32" /></td>
<td>คะแนน</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">วันที่ซื้อ :</td>
<td><input type="text" name="buydate" value="" size="32" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">บันทึกวันที่:</td>
<td><input type="text" name="savedate" value="" size="32" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">พนักงานคีย์ :</td>
<td><select name="employadd">
<?php
do {
?>
<option value="<?php echo $row_em['Name']?>" ><?php echo $row_em['Name']?></option>
<?php
} while ($row_em = mysql_fetch_assoc($em));
?>
</select></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> </td>
<td><input type="submit" value="บันทึกข้อมูล !!" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($deal);
mysql_free_result($em);
mysql_free_result($pro);
mysql_free_result($cus);
mysql_free_result($size);
?>
Tag : PHP, MySQL, Ajax, jQuery
|
|
|
|
|
|
Date :
2015-10-12 22:10:18 |
By :
Jaruwatth |
View :
1600 |
Reply :
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mysql_select_db($database_MyConnect, $MyConnect);
บันทัดบน เอาออกทุกบันทัด
ใส่ที่ตอนต้นโปรแกรม อันเดียวพอครับ
Code (PHP)
<?php require_once('Connections/MyConnect.php');
mysql_select_db($database_MyConnect, $MyConnect);
mysql_query('SET NAME utf-8', $MyConnect); // สำหรับ database ภาษาไทย
?>
|
|
|
|
|
Date :
2015-10-14 19:33:58 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่เป็นภาษาไทยทั้งหมดหรือเปล่าครับ
|
|
|
|
|
Date :
2015-10-15 01:15:43 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อันนี้เป็น Code ที่ดึงข้อมูลมาครับ
Code (PHP)
<?php require_once('Connections/MyConnect.php');
mysql_select_db($database_MyConnect, $MyConnect);
mysql_query('SET NAME utf-8', $MyConnect); // สำหรับ database ภาษาไทย
?>
<?php
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("test_db");
$strSQL = "SELECT * FROM real_db WHERE 1 AND CustomerID = '".$_POST["sCusID"]."' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
|
ประวัติการแก้ไข 2015-10-15 09:18:56
|
|
|
|
Date :
2015-10-15 09:18:00 |
By :
Jaruwatth |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|