อยากได้ความรู้ครับว่าผมต้องแก้ไขอย่างไรเพื่อให้ค่าตรงที่เลือกใน radio checkbox ตรงกับใน ฐานข้อมูล ผม ลองมาหลายวิธีไม่ได้เลยครับ
คือผมทำการส่งข้อมูลไปเก็บในฐานข้อมูลแบบ ajax แต่ว่า ค่าที่ได้ในช่อง ของ package(radiogroup) / period(radiogroup) / option_webboard(checkbox) /option_cart(checkbox) / option_tax(checkbox)
กลับได้ค่าแบบเดิมมาตลอดไม่ว่าจะเลือกค่าใดก็จะได้กลับมาเป็นค่าเดิมในฐานข้อมูลตลอดคือ
supreme c
2 year b
option_webboard a
option_cart a
option_tax a
อยากได้ความรู้ครับว่าผมต้องแก้ไขอย่างไรเพื่อให้ค่าตรงที่เลือกใน radio checkbox ตรงกับใน ฐานข้อมูล ผม ลองมาหลายวิธีไม่ได้เลยครับ
หน้า ฟอร์ม
Code (PHP)
<!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>
<title>StudioClick | Contact</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen" />
<style type="text/css">.sf-sub-indicator {behavior: url(css/iepngfix.htc);}</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="javascript/superfish.js"></script>
<script type="text/javascript" src="javascript/dd.min.js"></script>
<script type="text/javascript">
//<![CDATA[
// initialise plugins
$(document).ready(function () {
if ($('#slider').length == 1) {
$('#slider').cycle({
fx: 'fade',
speed: 2000,
timeout: 4000
});
}
var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
if (!ie6) {
$('ul.sf-menu').superfish({
delay: 1000,
// one second delay on mouseout
animation: {
opacity: 'show',
height: 'show'
},
// fade-in and slide-down animation
speed: 'normal' // faster animation speed
});
}
else {
DD_belatedPNG.fix('#topbar, img, a, .commentbubble, .infobubble, .view-all, #category-picture1, #category-picture2, #category-picture3, #footer');
}
});
//]]>
</script>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'register_save.php';
var pmeters = "torganization=" + encodeURI( document.getElementById("organization").value) +
"&tcontact_phone=" + encodeURI( document.getElementById("contact_phone").value ) +
"&turl=" + encodeURI( document.getElementById("url").value ) +
"&tpackage1=" + encodeURI( document.getElementById("package1").value) +
"&tpackage2=" + encodeURI( document.getElementById("package2").value) +
"&tpackage3=" + encodeURI( document.getElementById("package3").value) +
"&tperiod1=" + encodeURI( document.getElementById("period1").value) +
"&tperiod2=" + encodeURI( document.getElementById("period2").value) +
"&toption_webboard=" + encodeURI( document.getElementById("option_webboard").value ) +
"&toption_cart=" + encodeURI( document.getElementById("option_cart").value ) +
"&toption_tax=" + encodeURI( document.getElementById("option_tax").value ) +
"&tcustomer_name=" + encodeURI( document.getElementById("customer_name").value ) +
"&tcontact_name=" + encodeURI( document.getElementById("contact_name").value ) +
"&temail=" + encodeURI( document.getElementById("email").value ) +
"&tcard_id=" + encodeURI( document.getElementById("card_id").value ) +
"&tac_no=" + encodeURI( document.getElementById("ac_no").value ) +
"&tac_bank=" + encodeURI( document.getElementById("ac_bank").value ) +
"&tac_branch=" + encodeURI( document.getElementById("ac_branch").value ) +
"&tac_name=" + encodeURI( document.getElementById("ac_name").value ) +
"&tusername=" + encodeURI( document.getElementById("username").value ) +
"&tpassword=" + encodeURI( document.getElementById("password").value );
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
document.getElementById("mySpan").innerHTML = "Success!! thx for register";
}
else
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
}
</script>
</head>
<body>
<!-- Wrapper -->
<div id="wrapper">
<!-- Top bar -->
<div style="width:940px;height:100px;background:url(images/logoistyle.png) no-repeat;">
<div class="nametel">
<p style="padding:0;">Tel : 085-1578066,086-8193896</p>
<p style="padding:0;">E-Mail : [email protected] </p>
</div>
</div>
<div id="topbar">
<!-- Logo -->
<img class="logo" src="images/logo.png" alt="" />
<!-- Menu -->
<div id="secnav">
<ul>
<li> <a href="#">SIGN UP</a> </li>
<li class="noimg"> <a href="#">LOGIN</a> </li>
</ul>
</div>
<div class="menu">
<ul class="sf-menu">
<li> <a href="index.html">HOME</a></li>
<li> <a href="about.html">ABOUT</a>
<ul>
<li class="first"><a href="#">TEAM</a></li>
<li><a href="#">PHILOSOPHY</a></li>
<li><a href="#">COMPANY</a></li>
<li class="last"><a href="#">PRODUCTS</a>
<ul>
<li class="first"><a href="#">PRODUCT ONE</a></li>
<li><a href="#">PRODUCT TWO</a></li>
<li class="last"><a href="#">PRODUCT THREE</a></li>
</ul>
</li>
</ul>
</li>
<li> <a href="portfolio.html">PORTFOLIO</a>
<ul>
<li><a href="#">WEBDESIGN</a></li>
<li><a href="#">PHOTOS</a>
<ul>
<li class="first"><a href="#">NATURE</a></li>
<li><a href="#">ANIMALS</a></li>
<li class="last"><a href="#">CITIES</a>
<ul>
<li class="first"><a href="#">NEW YORK</a></li>
<li><a href="#">MONTREAL</a></li>
<li class="last"><a href="#">LAS VEGAS</a></li>
</ul>
</li>
</ul>
</li>
<li class="last"><a href="#">ARTS</a></li>
</ul>
</li>
<li> <a href="blog.html">SERVICERS</a>
<ul>
<li class="first"><a href="#">CATEGORY ONE</a></li>
<li><a href="#">CATEGORY TWO</a></li>
<li class="last"><a href="#">CATEGORY THREE</a></li>
</ul>
</li>
<li> <a href="contact.html">CONTACT</a> </li>
</ul>
</div>
<!-- End of Menu -->
</div>
<div class="clear"></div>
<!-- End of Topbar -->
<!-- Introtext -->
<div class="subcategory-contact">
<h1>OUR OFFICE +</h1>
<ul>
<li><a href="#">MONTREAL</a></li>
<li class="contact">Phone : 514.123.1234</li>
<li class="contact">[email protected] </li>
<li><a href="#">LOS ANGELES</a></li>
<li class="contact">Phone : 251.123.1234</li>
<li class="contact">[email protected] </li>
<li><a href="#">NEW YORK</a></li>
<li class="contact">Phone : 616.123.1234</li>
<li class="contact">[email protected] </li>
<li><a href="#">HONK HONG</a></li>
<li class="contact">Phone : 616.123.1234</li>
<li class="contact">[email protected] </li>
</ul>
</div>
<div id="introtext-contact">
<h1>CONTACT US +</h1>
<p>Praesent id dolor et dolor viverra sagittis. Integer scelerisque quam nec est congue tempor eu ut metus. Etiam fringilla aliquam nulla eu bibendum. Ut cursus, ligula vel mollis hendrerit, est enim posuere velit, ultricies pretium tortor massa ut ipsum. Aenean a aliquet arcu.</p>
<div class="clear"></div>
</div>
<!-- End of introtext -->
<!-- Form -->
<form name="frmMain">
<div id="contactform">
<div id="main">
<span id="mySpan"></span><br><br>
<h1>ชื่อองค์การ : </h1>
<p>
<input type="text" name="organization" id="organization" class="name" />
</p>
<h1>เบอร์โทร :</h1>
<p>
<input type="text" name="contact_phone" id="contact_phone" class="email" />
</p>
<h1>URL :</h1>
<p>
<input type="text" name="url" id="url" class="email" />
</p><br />
<div style="width:250px;">
<table width="250" border="1">
<tr>
<td><h1>Package :</h1></td>
<td><label>
<input name="package" type="radio" id="package1" value="executive" checked="checked"/>
<img src="images/executive.png" /></label></td>
</tr>
<tr>
<td> </td>
<td> <label>
<input type="radio" name="package" id="package2" value="premier"/>
<img src="images/premier.png" /></label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="radio" name="package" id="package3" value="supreme"/>
<img src="images/supreme.png" /></label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><h1>ระยะเวลา :</h1></td>
<td><label>
<input name="period" type="radio" id="period1" value="1 year" checked="checked"/>
<h1>1 ปี</h1></label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="radio" name="period" id="period2" value="2 year"/>
<h1>2 ปี</h1></label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><h1>Optional :</h1> </td>
<td><label>
<input type="checkbox" name="option_webboard" id="option_webboard" value="true"/>
<h1>Webboard</h1></label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="checkbox" name="option_cart" id="option_cart" value="true"/>
<h1>ระบบตะกร้า</h1></label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="checkbox" name="option_tax" id="option_tax" value="true"/>
<h1>หัก ณ ที่จ่าย</h1></label></td>
</tr>
</table>
<p><br /><br /><br />
<input name="btnRegister" type="button" id="btnRegister" OnClick="JavaScript:doCallAjax();" value="Register" class="button">
</p><br/><br/><br/><br/><br/><br/>
<div style="position:absolute;width:200px;top:175px;left:350px">
<h1>ชื่อลูกค้า :</h1>
<p>
<input type="text" name="customer_name" id="customer_name" class="email" />
</p>
<h1>ชื่อผู้ติดต่อ :</h1>
<p>
<input type="text" name="contact_name" id="contact_name" class="email" />
</p>
<h1>E-mail :</h1>
<p>
<input type="text" name="email" id="email" class="email" />
</p>
<h1>บัตรประชาชน :</h1>
<p>
<input type="text" name="card_id" id="card_id" class="email" />
</p>
<h1>เลขที่บัญชี :</h1>
<p>
<input type="text" name="ac_no" id="ac_no" class="email" />
</p>
<h1>ธนาคาร :</h1>
<p>
<select type="text" name="ac_bank" id="ac_bank" class="email">
<option value="ไทยพาณิชย์" selected="">ธนาคารไทยพาณิชย์</option>
<option value="กรุงไทย">ธนาคารกรุงไทย</option>
<option value="ทหารไทย">ธนาคารทหารไทย</option>
<option value="กสิกร">ธนาคารกสิกร</option>
<option value="กรุงเทพ">ธนาคารกรุงเทพ</option>
</select>
</p>
<h1>สาขา :</h1>
<p>
<input type="text" name="ac_branch" id="ac_branch" class="email" />
</p>
<h1>ชื่อบัญชี :</h1>
<p>
<input type="text" name="ac_name" id="ac_name" class="email" />
</p>
<h1>username :</h1>
<p>
<input type="text" name="username" id="username" class="email" />
</p>
<h1>password :</h1>
<p>
<input type="password" name="password" id="password" class="email" />
</p>
</div>
</div>
</div>
</form>
<!-- End of form-->
<div class="clear"></div>
<!-- Footer-->
<div id="footer">
<div class="info">© 2009 StudioCLICK | DESIGNED AND DEVELOPPED BY <a href="http://freepsdtheme.com/">DDSTUDIOS</a></div>
<div class="infonav"> <a href="#">HOME</a> | <a href="#">ABOUT</a> | <a href="#">PORTFOLIO</a> | <a href="#">BLOG</a> | <a href="#">CONTACT</a> </div>
</div>
<!-- End of footer-->
</div>
<!-- End of wrapper -->
</body>
</html>
หน้าประมวลผลCode (PHP)
<?php
$strorganization = trim($_POST["torganization"]);
$strcontact_phone = trim($_POST["tcontact_phone"]);
$strurl = trim($_POST["turl"]);
$package1 = trim($_POST["tpackage1"]);
$package2 = trim($_POST["tpackage2"]);
$package3 = trim($_POST["tpackage3"]);
$period1 = trim($_POST["tperiod1"]);
$period2 = trim($_POST["tperiod2"]);
$option_webboard = trim($_POST["toption_webboard"]);
$option_cart = trim($_POST["toption_cart"]);
$option_tax = trim($_POST["toption_tax"]);
$strcustomer_name = trim($_POST["tcustomer_name"]);
$strcontact_name = trim($_POST["tcontact_name"]);
$stremail = trim($_POST["temail"]);
$strcard_id = trim($_POST["tcard_id"]);
$strac_no = trim($_POST["tac_no"]);
$strac_bank = trim($_POST["tac_bank"]);
$strac_branch = trim($_POST["tac_branch"]);
$strac_name = trim($_POST["tac_name"]);
$strusername = trim($_POST["tusername"]);
$strpassword = trim($_POST["tpassword"]);
//*** Check radio and checkbox
if($package1==true){$strpackage="excutive a";}
if($package2==true){$strpackage="premier b";}
if($package3==true){$strpackage="supreme c";}
if($period1==true){$strperiod="1 year a ";}
if($period2==true){$strperiod="2 year b";}
if($option_webboard==true){$stroption_webboard="option_webboard a";}
if($option_cart==true){$stroption_cart="option_cart a";}
if($option_tax==true){$stroption_tax="option_tax a";}
//*** Check organization ***//
if(trim($strorganization) == "")
{
echo "<font color=red>**</font><h1> Plase input [organization]</h1><font color=red>**</font>";
exit();
}
//*** Check contact_phone ***//
if(trim($strcontact_phone) == "")
{
echo "<font color=red>**</font><h1> Plase input [contact_phone]</h1><font color=red>**</font>";
exit();
}
//*** Check url ***//
if(trim($strurl) == "")
{
echo "<font color=red>**</font><h1> Plase input [url]</h1><font color=red>**</font>";
exit();
}
//*** Check customer_name ***//
if(trim($strcustomer_name) == "")
{
echo "<font color=red>**</font><h1> Plase input [customer_name]</h1><font color=red>**</font>";
exit();
}
//*** Check contact_name ***//
if(trim($strcontact_name) == "")
{
echo "<font color=red>**</font><h1> Plase input [contact_name]</h1><font color=red>**</font>";
exit();
}
//*** Check email ***//
if(trim($stremail) == "")
{
echo "<font color=red>**</font><h1> Plase input [email]</h1><font color=red>**</font>";
exit();
}
//*** Check card_id ***//
if(trim($strcard_id) == "")
{
echo "<font color=red>**</font><h1>Plase input [card_id]</h1><font color=red>**</font>";
exit();
}
//*** Check ac_no ***//
if(trim($strac_no) == "")
{
echo "<font color=red>**</font><h1> Plase input [ac_no]</h1><font color=red>**</font>";
exit();
}
//*** Check ac_branch ***//
if(trim($strac_branch) == "")
{
echo "<font color=red>**</font><h1> Plase input [ac_branch]</h1><font color=red>**</font>";
exit();
}
//*** Check ac_name ***//
if(trim($strac_name) == "")
{
echo "<font color=red>**</font><h1> Plase input [ac_name]</h1><font color=red>**</font>";
exit();
}
//*** Check username ***//
if(trim($strusername) == "")
{
echo "<font color=red>**</font><h1> Plase input [username]</h1><font color=red>**</font>";
exit();
}
//*** Check password ***//
if(trim($strpassword) == "")
{
echo "<font color=red>**</font><h1> Plase input [password]</h1><font color=red>**</font>";
exit();
}
$objConnect = mysql_connect("localhost","_istyle","ypgk") or die("Connect error");
$objDB = mysql_select_db("istylestudio") or die("DB error");
mysql_query("SET NAMES utf8") or die (mysql_error());
//*** Check Username (already exists) ***//
$strSQL = "SELECT * FROM customer WHERE username = '".$strusername."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<font color=red>**</font> Username [$strusername] already exists";
}
else
{
$strSQL="INSERT INTO customer(organization,contact_phone,url,package,period,option_webboard,option_cart,option_tax";
$strSQL=$strSQL.",customer_name,contact_name,email,card_id,ac_no,ac_bank,ac_branch,ac_name,username,password)";
$strSQL=$strSQL." values('".$strorganization."','".$strcontact_phone."','".$strurl."','".$strpackage."','".$strperiod."'";
$strSQL=$strSQL.",'".$stroption_webboard."','".$stroption_cart."','".$stroption_tax."','".$strcustomer_name."'";
$strSQL=$strSQL.",'".$strcontact_name."','".$stremail."','".$strcard_id."','".$strac_no."','".$strac_bank."'";
$strSQL=$strSQL.",'".$strac_branch."','".$strac_name."','".$strusername."','".$strpassword."')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Y"; // Finish Register Return "Y"
}
else
{
echo "<font color=red>**</font> Can not register";
}
}
mysql_close();
?>
Tag : PHP, MySQL, Ajax
Date :
2012-04-02 13:01:21
By :
onekisz
View :
893
Reply :
1
ถ้าเป็น radio จะต้อง loop แต่ล่ะตัวครับ จากนั้นให้ใช้ checked กรณีที่ค่าตรงกับ radio ตัวนั้น ๆ ครับ
Date :
2012-04-05 10:33:03
By :
webmaster
Load balance : Server 00