 |
แอดข้อมูลไม่ได้ครับ ช่วยดูโคดทีครับ มันแอดลงฐานข้อมูลไม่ได้ |
|
 |
|
|
 |
 |
|
ช่วยดูโคดทีครับ มันแอดลงฐานข้อมูลไม่ได้
Code (PHP)
<?php
$con=mysql_connect("localhost","root","123456") or die (mysql_error);
$db=mysql_select_db("test",$con)or die (mysql_error);
mysql_query("SET NAMES UTF8");
$sql=mysql_query("INSERT INTO user (user,userpass) VALUES ('$user','$pass') ");
mysql_close($con);
?>
นี่ฐานข้อมูล
Code (SQL)
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง:
-- รุ่นของเซิร์ฟเวอร์: 5.5.22
-- รุ่นของ PHP: 6.0.0-dev
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `test`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `user`
--
CREATE TABLE `user` (
`userid` int(20) NOT NULL AUTO_INCREMENT,
`user` varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`userpass` varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
--
-- dump ตาราง `user`
--
INSERT INTO `user` VALUES (1, 0x626f7373, 0x313233343536);
INSERT INTO `user` VALUES (8, 0x70726172696e7961, 0x363534333231);
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2014-03-08 09:19:52
|
 |
 |
 |
 |
Date :
2014-03-08 08:51:46 |
By :
meatspin |
View :
660 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$sql=mysql_query("INSERT INTO user (user,userpass) VALUES ('$user','$pass') ") or die(mysql_error());
เอา Error มาดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2014-03-08 09:47:02 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ Error ครับ
|
 |
 |
 |
 |
Date :
2014-03-08 09:59:18 |
By :
meatspin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใครก้ได้ช่วยหน่อยครับ
|
 |
 |
 |
 |
Date :
2014-03-08 11:08:20 |
By :
meatspin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$user, $pass มาจากไหนครับ?
|
 |
 |
 |
 |
Date :
2014-03-08 11:13:31 |
By :
itpcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูฟอร์ม (เฉพาะ HTML) หน่อยครับ
|
 |
 |
 |
 |
Date :
2014-03-08 11:37:20 |
By :
itpcc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทั้งโค้ด
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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="show.php">
<p>
<label for="user"></label>
<input type="text" name="user" id="user" />
</p>
<p>
<label for="pass"></label>
<input type="text" name="pass" id="pass" />
</p>
<p>
<input type="submit" name="button" id="button" value="Register" />
</p>
</form>
<p> </p>
<p> </p>
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
$con=mysql_connect("localhost","root","123456") or die (mysql_error());
$db=mysql_select_db("test",$con)or die (mysql_error());
if($con)
echo"Connected";
else
echo"connect Faild";
mysql_query("SET NAMES UTF8");
$sql=mysql_query("INSERT INTO user (user,userpass) VALUES ('$user','$pass') ") or die(mysql_error());
?>
</body>
</html>
|
ประวัติการแก้ไข 2014-03-08 11:45:27 2014-03-08 11:48:01
 |
 |
 |
 |
Date :
2014-03-08 11:43:13 |
By :
meatspin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ลองก็อฟเว็บอื่นมา
โค้ด form.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form name="form1" method="post" action="add.php">
Name :
<input name="name" type="text" id="name">
Surname :
<input name="surname" type="text" id="surname">
<br>
Grade :
<input name="grade" type="text" id="grade">
<input type="submit" name="Submit" value="เพิ่มข้อมูล">
<input type="reset" name="Submit2" value="Reset">
</form>
</body>
</html>
โค้ด 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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//กำหนดตัวแปรเพื่อนำไปใช้งาน
$hostname = "localhost"; //ชื่อโฮสต์
$user = "root"; //ชื่อผู้ใช้
$password = "123456"; //รหัสผ่าน
$dbname = "boss"; //ชื่อฐานข้อมูล
$tblname = "student"; //ชื่อตาราง
// เริ่มติดต่อฐานข้อมูล
mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้");
// เลือกฐานข้อมูล
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
// คำสั่ง SQL และสั่งให้ทำงาน
$sql = "insert into $tblname (name, surname, grade) values ('$name', '$surname', '$grade')"; // กำหนดคำสั่ง SQL เพื่อเพิ่มข้อมูลแบบคีย์ในคำสั่ง SQL
$dbquery = mysql_db_query($dbname, $sql);
// ปิดการติดต่อฐานข้อมูล
mysql_close();
echo "<Font Size=4><B>เพิ่มข้อมูลลงฐานข้อมูลเรียบร้อยแล้ว</B>";
?>
</body>
</html>
ผลลัพธ์

|
 |
 |
 |
 |
Date :
2014-03-08 11:48:24 |
By :
meatspin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|