|
 |
|
มือใหม่ครับ ช่วยตรวจสอบเรื่อง code ให้ทีครับ ผมเพิ่มข้อมูลลงฐานข้อมูลไม่ได้ |
|
 |
|
|
 |
 |
|
แนะนำตัวก่อนนะครับ ผมเป็นนักศึกษากำลังทำโปรเจคครับ เกี่ยวกับเว็บไซด์ขายของ ผมติดตรงนี้ครับ เมื่อผมเพิ่มข้อมูลสินค้า แต่เมื่อกด submit ไป มันไม่เซฟลงฐานข้อมูลให้ครับ ผมไม่แน่ใจว่า ผิดตรงไหนอะครับ แต่ผม พอจะ(เดาๆ)ได้ว่า น่าจะผิดหน้า login (หรือป่าว) รบกวน พวกพี่ๆช่วยดูให้ผมทีครับ

หน้า connect.php
Code (PHP)
<?
function connectdb ($dbname){
$con = mysql_connect("localhost","root","root");
if(!$con) { echo "connect error" ;}
$con = mysql_select_db($dbname);
if(!$con) {echo "select datadase error" ;}
}
?>
หน้า login.php
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>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>loing</title>
</head>
<head>
<style type="text/css">
body { background-image : url('login1.jpg') }
พื้น
</style>
</head>
<body>
<form name="form1" method="post" action="checkuser.php" >
<br />
<br />
<table width="434" border="1" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#666666">
<td width="430" align="center">เข้าสู่ระบบ</td>
</tr>
<tr>
<td height="72" align="center" bgcolor="#999999"><strong>Username</strong> : <input type="text" name="username" /></td>
</tr>
<tr>
<td height="76" align="center" bgcolor="#999999"><strong>Password</strong> : <input type="password" name="pwd" /></td>
</tr>
<tr>
</tr>
<tr>
<td height="81" align="center" bgcolor="#666666"><input type="submit" name="b1" value="login" /></td>
</tr>
</table>
</form>
</body>
หน้า product_admin.php
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>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>สินค้าทั้งหมด</title>
<?
require("connect.php");
connectdb("orderdb");
$sql = "select * from product order by pid";
mysql_query("set names tis620");
$result = mysql_query($sql);
?>
<p align = "center">
<a href ="add.php"><img src="Picweb/pic admin/add.png" width="80" height="80" /> </a><br/>
<strong> ข้อมูลสินค้า </strong>
</p>
<table width="1024" height="193" border="1" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#99CCFF">
<td width="179" height="31" align="center" bgcolor="#333333">ภาพสินค้า</td>
<td width="137" align="center" bgcolor="#333333">รหัสสินค้า</td>
<td width="119" align="center" bgcolor="#333333">ชื่อสินค้า</td>
<td width="219" align="center" bgcolor="#333333">รายละเอียดสินค้า</td>
<td width="97" align="center" bgcolor="#333333">ราคา</td>
<td width="142" align="center" bgcolor="#333333">แก้ไข</td>
<td width="115" align="center" bgcolor="#333333">ลบ</td>
</tr>
<?
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td width="179" align="center" bgcolor="#666666"><img src="<?=$row[pic]?>" width="100" height="100"/></td>
<td align="center" bgcolor="#666666"><?=$row[pid]?></td>
<td align="center" bgcolor="#666666"><?=$row[pname] ?></td>
<td align="center" bgcolor="#666666"><?= $row[detail] ?></td>
<td align="center" bgcolor="#666666"><?= $row[price] ?></td>
<td align="center" bgcolor="#666666"><a href="edit.php?pid=<?=$row[pid]?>" ><img src="Picweb/pic admin/edit.png" width="40" height="40" /></a>
</td>
<td align="center" bgcolor="#666666"><a href="delete.php?pid=<?=$row[pid]?>" ><img src="Picweb/pic admin/deletecart.png" width="40" height="40" /></a>
</td>
</tr>
<? } ?>
</table>
<p align="center">จำนวนทั้งหมด = <?=mysql_num_rows($result)?> </p>
<A HREF="javascript:history.back()">กลับไปหน้าแรก</A>
หน้า add.php
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>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>เพิ่มสินค้า</title>
<p align="center"> <strong>เพิ่มสินค้า</strong></p>
<form name="form1" action="save.php" method="post" enctype="multipart/form-data" >
<table width="599" height="335" border="1" align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td width="237" height="48" bgcolor="#666666">รูปภาพ</td>
<td width="257" align="left"> <input type="file" name="pic" /></td>
</tr>
<tr align="center">
<td height="57" bgcolor="#666666">ชื่อสินค้า</td>
<td align="left"> <input type="text" name= "pname"></td>
</tr>
<tr align="center">
<td height="61" bgcolor="#666666">รายละเอียด</td>
<td><textarea name="detail" cols="45" row="5"> </textarea></td>
</tr>
<tr align="center">
<td height="49" bgcolor="#666666">ราคา</td>
<td align="left"> <input type="text" name= "price"></td>
</tr>
<tr align="center">
<td height="51" bgcolor="#666666">จำนวนสินค้า</td>
<td align="left"> <input type="text" name= "strock"></td>
</tr>
<tr align="center">
<td height="52" bgcolor="#666666"> </td>
<td><input type="submit" name="button" value="Submit"/>
<input type ="reset" name="button2" value="Reset"/></td>
</tr>
</table>
หน้า save.php
Code (PHP)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>Untitled Document</title>
</head>
<body>
<? include("connect.php");
connectdb("orderdb");
$pid =$_POST['pid'];
$pname =$_POST['pname'];
$detail = $_POST['detail'];
$price = $_POST['price'];
$strock = $_POST['strock'];
$pic = $_FILES['pic']['name'];
if( ($pname=="") || ($price=="") ) {
?>
<script>
alert('กรุณาป้อนชื่อสินค้าหรือราคา');
history.back(-1);
</script>
<? exit;
}//if
$path = basename($pic);
$upload = move_uploaded_file($_FILES['pic']['tmp_name'],$path);
mysql_query("set names tis620");
$sql = "insert into product(pname,detail,price,pic,stock) values('$pname','$detail','$price','$pic','$stock')";
$result = mysql_query($sql);
if($result) {
?>
<script>
alert("เพิ่มข้อมูลสำเร็จ");
window.location = "product_admin.php" ;
</script>
<? } else { ?>
<script>
alert("ล้มเหลว");
window.location = "add.php" ;
</script>
<? } ?>
</body>
รบกวนพี่ๆช่วยแนะนำด้วยนะครับ ผมยังไม่มีความเข้าใจ php ผมพยายามแก้มาเป็นอาทิตย์แล้วครับ มันไม่ได้จริงๆครับ รบกวนด้วยนะครับ 
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2015-12-14 09:52:31 2015-12-14 09:52:58 2015-12-14 09:53:48 2015-12-14 09:55:24 2015-12-14 10:00:48 2015-12-14 10:24:42 2015-12-14 10:35:30
|
 |
 |
 |
 |
Date :
2015-12-14 09:50:45 |
By :
bankguszo |
View :
1100 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

เอาครอบโค๊ดไว้ด้วยครับ แยกไฟล์ด้วยนะครับ ใส่ชื่อไฟล์ด้วยว่าไฟล์ไหนเป็นไฟล์ไหน
|
 |
 |
 |
 |
Date :
2015-12-14 10:15:20 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขแล้วครับผม รบกวนด้วยนะครับ 
|
 |
 |
 |
 |
Date :
2015-12-14 10:30:42 |
By :
bankguszo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
27.
$sql = "insert into product(pname,detail,price,pic,stock) values('$pname','$detail','$price','$pic','$stock')";
สีแดงชื่อฟีลด์มันไม่ตรงนะครับ แนะนำให้ไปแก้ที่ database ให้ถูกครับ
ส่วนตัวโปรแกรม ทุกไฟล์ ควรมีการตรวจสอบ คน login ด้วย session ด้วยครับ เขียนแบบนี้ ใครก็เข้ามาได้
เวลาทำงานไปนาน ชือ url มันจะไปขึ้นที่ google ค้นหาได้ แล้วจะปวดหัวใครเข้ามาเพิ่มข้อมูลลดข้อมูลให้ที่หลังนะครับ
|
 |
 |
 |
 |
Date :
2015-12-14 11:02:23 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มได้แล้วครับขอบคุณครับผม 
|
 |
 |
 |
 |
Date :
2015-12-14 11:17:17 |
By :
bankguszo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2015-12-14 13:27:11 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|