|
|
|
Code Testinput.php Error ตรง if(isset(($_GET["login"] !== "null")) กับ if(isset(($_GET["show"] !== "null")) ครับ |
|
|
|
|
|
|
|
Code Testinput.php Error ตรง if(isset(($_GET["login"] !== "null")) กับ if(isset(($_GET["show"] !== "null")) ช่วยแก้ปัญหา Code ให้หน่อย โดย Code PHP ทั้ง 2 ไฟล์ อยู่ข้างล่างครับ
1.FormInput.php
Code (PHP)
<form method="post" action="TestInput.php" enctype="multipart/form-data">
สมัคร ข้อมูลส่วนตัว
<table>
<tr>
<td>รหัส</td>
<td><input type="text" name="txtId"></td>
</tr>
<tr>
<td>ชื่อ</td>
<td><input type="text" name="txtName"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="txtPassword"></td>
</tr>
</table>
<input type="hidden" name="MAX_FILE_SIZE" value="102400" />
<input type="file" name="fupload" /><br/>
<input type="submit" name="register" value="Add">
<input type="submit" name="login" value="login">
<input type="submit" name="show" value="show">
</form>
2.TestInput.php
Code (PHP)
<?php
if(isset($_POST["Add"]))
print $_POST["txt"];
mysql_connect("localhost","root","123456");
mysql_select_db("tum");
$txtid = $_POST['txtId'];
$txtname = $_POST['txtName'];
$txtpassword = $_POST['txtPassword'];
$query = "INSERT INTO student(ID , Name , Password) values('$txtid','$txtname','$txtpassword')";
$result = mysql_query($query);
// Display an appropriate message
if ($result)
print "<p>Product successfully inserted!</p>";
else
print "<p>There was a problem inserting the name!</p>";
mysql_close();
if(isset(($_GET["login"] !== "null"))
{
$objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
$objDB = mysql_select_db("tum");
// Search By Name or Email
$strSQL = "SELECT * FROM customer WHERE (Name LIKE '%".$_GET["txtKeyword"]."%' or Email LIKE '%".$_GET["txtKeyword"]."%' )";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["CustomerID"];?></div></td>
<td><?php echo $objResult["Name"];?></td>
<td><?php echo $objResult["Email"];?></td>
<td><div align="center"><?php echo $objResult["CountryCode"];?></div></td>
<td align="right"><?php echo $objResult["Budget"];?></td>
<td align="right"><?php echo $objResult["Used"];?></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close($objConnect);
}
if(isset(($_GET["show"] !== "null"))
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["CustomerID"];?></div></td>
<td><?php echo $objResult["Name"];?></td>
<td><?php echo $objResult["Email"];?></td>
<td><div align="center"><?php echo $objResult["CountryCode"];?></div></td>
<td align="right"><?php echo $objResult["Budget"];?></td>
<td align="right"><?php echo $objResult["Used"];?></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close($objConnect);
?>
ขอบคุณครับล่วงหน้า
Tag : PHP, MySQL, Windows, Linux, Mac
|
|
|
|
|
|
Date :
2014-10-23 12:19:03 |
By :
doanga2007 |
View :
1554 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เนื่องจากเป็น type submit หลายอัน จะมีแค่อันเดียวที่กดถึงจะส่งตัวแปรมา
ใช้แค่
Code (PHP)
if( isset(($_GET["login"])) ถ้าส่งค่า login มาทำอันนี้
ทำนองเดียวกันกับ show
Code (PHP)
if( isset(($_GET["show"])) ถ้าส่งค่า show มาทำอันนี้
result ของ isset() true หรือ |false ไม่ใช่ 'null'
|
ประวัติการแก้ไข 2014-10-23 12:35:40
|
|
|
|
Date :
2014-10-23 12:32:48 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับสำหรับคำตอบ ตอนนี้แก้ปัญหาได้แล้วครับ
|
|
|
|
|
Date :
2014-10-23 12:47:44 |
By :
doanga2007 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ปล. อีกที เพิ่งสังเกต ใช้คำสั่ง isset ผิดรูปแบบอะครับ ต้องใช้ กับ ตัวแปร ไม่ได้ใช้กับ ค่า true | false
$_GET["login"] !== "null" จะได้ result เป็น true หรือ false; ถ้าไม่เออเร่อร์
และ "null" เป็น String นะครับ ไม่ใช่ ค่า null
ถ้าจะเปรียบเทียงว่าเป็นค่า null หรือไม่ ใช้ is_null() หรือ empty()
isset() ใช้ตรวจสอบว่ามีการประกาศตัวแปรหรือไม่ จะเป็น null หรือ ไม่เป้น ก็ได้
|
|
|
|
|
Date :
2014-10-23 13:00:15 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|