插入数据库失败

时间:2014-11-07 08:44:19

标签: php mysql

我正在尝试将我拥有的数据保存到mysql数据库中,但我很难做到这一点。起初,我在练习数据中取得了成功。问题是,当我向查询添加其他所需信息时,我的查询不再有效。

代码是这样的。假设所有变量都有正确的对应值。

<body>

<?php 


$username = "formtemplate";
$password = "admin123";
$hostname = "localhost";
$db = "practice";
$dbhandle = mysqli_connect($hostname, $username, $password, $db);

$sql = "INSERT INTO transactions (id_num, emp_name, branch, work_sched, dayoff, transaction, date_from, date_to, time_from, time_to, total, replacement, reason, pending, approve, decline, consume, paid) VALUES ( '$employeeNum', '$name', '$branch', '$workSched', '$dayoff', '$temptable', '$tempdatefrom', '$tempdateto', '$tempTimeFrom', '$tempTimeTo', '$tempTotal', '$tempReplacement', '$tempReason', 'yes', 'no', 'no', 'no', 'no')";

mysqli_query($dbhandle, $sql)

or die ( mysql_error() );

echo "success";

?>

</body>

这是数据库信息

trans_num int(11)

id_num varchar(10)

emp_name varchar(30)

branch varchar(20)

work_sched varchar(25)

dayoff varchar(15)

transaction varchar(10)

date_from date

date_to date

time_from varchar(25)

time_to varchar(25)

总varchar(25)

替换varchar(30)

原因varchar(100)

待定varchar(5)

批准的varchar(5)

拒绝varchar(5)

消费varchar(5)

付费varchar(5)

1 个答案:

答案 0 :(得分:0)

<?php

mysql_connect("username","password","") or die("databse connected");
mysql_select_db("dbname") or die("databse not found");

$username=$_post['username'];
$password=$_post['password'];

mysqli`enter code here`_query("INSERT INTO `tablename` (`username`,`password`) VALUES ('$username','$password')");
echo "successfully insert record";


?>