请帮我把它插入我的数据库。
//Start session
session_start();
//database connection
require_once 'connection.php';
$data = json_decode(json_encode($_POST), true);
foreach($data as $key => $value) {
$prefix = strtoupper($data[$key]['prefix']);
$fullname= strtoupper($data[$key]['fullname']);
$position= strtoupper($data[$key]['position']);
$result= connect("INSERT INTO `register_info` (prefix, fullname, position) VALUES ('$prefix','$fullname','$position')");
}
if($result){
echo json_encode(true);
}else{
echo json_encode(false);
}
我认为$ result中有错误..但我不知道那是什么? 请帮帮我们。
答案 0 :(得分:0)
@Aditya,这是我的函数connect()
function connect($sql){
$host = "localhost";
$username = "admin";
$password = "";
$db_name = "database";
$db = mysql_connect($host,$username,$password) or die('Cannot connect to server.');
mysql_select_db($db_name, $db) or die('Database does not exist.');
$result=mysql_query($sql,$db);
return $result;
}
我的连接没有错误。