我在使用php插入mysql数据库时遇到问题。 特别是这段代码给了我一些问题:
$sql = "INSERT INTO '$mysql_database'.'$UsersTable' ('firstName', 'lastName', 'password', 'email','userType')VALUES ('$firstName', '$lastName', '$password','$email','$userType')";
我似乎无法在此处找到语法错误。给我的所有信息似乎都是正确的。我哪里错了?
答案 0 :(得分:1)
试试这个
$sql = "INSERT INTO $mysql_database.$UsersTable (firstName, lastName, password, email,userType)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";
从表格列中删除引用
答案 1 :(得分:0)
尝试此查询
$sql = "INSERT INTO $mysql_database.$UsersTable (firstName, lastName, password, email,userType)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";
答案 2 :(得分:0)
您好,您无法使用表格列名中的单个引用,因此请将其删除
<?php
session_start();
$user_id = $_SESSION['uid'];
include('db.php');
$sql = "SELECT * from registered_users";
$query = mysql_query($sql) or die(mysql_error());
$result = mysql_query("SELECT * FROM user_files_public where uid = $user_id");
?>
<!DOCTYPE html>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src = "http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="ajax-jaquery.js"></script>
<script type="text/javascript">
$(function(){
$(".file").click(function(){
$(".userlist").click(function(){
var elementUser = $(this);
var elementFile = $(".file").$(this);
var name = elementUser.attr("id");
var id = elementFile.attr("name");
var info='name='+name+'&id='+id;
$.ajax({
type: "POST",
url: "share.php",
data: info,
success: function(){
}
});
$(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
.animate({ opacity: "hide" }, "slow");
return true;
});
});
});
</script>
<style>
.ontop_share {
z-index: 999;
width: 900px;
height: 900px;
top: 0;
left: 0;
display: none;
position: absolute;
background-color: #cccccc;
color: #aaaaaa;
opacity: 1.9;
filter: alpha(opacity = 50);
}
#popup_share {
width: 900px;
height: 900px;
position: absolute;
color: #000000;
border: 2px solid red;
background-color: #ffffff;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -150px;
}
</style>
<script type="text/javascript">
function pop(div) {
document.getElementById(div).style.display = 'block';
}
function hide(div) {
document.getElementById(div).style.display = 'none';
}
</script>
</head>
<body>
<div id="popDiv_share" class="ontop_share">
<div id="popup_share">
<?php
while($row = mysql_fetch_array($query)){
$id = $row['id'];
$name =$row['first_name'];?>
<a href="" class="userlist" id="<?php echo $id;?>"><?php echo $id.' '.$name;?></a><?php
echo '<br/>';
}
?>
</div>
<a href="#" onClick="hide('popDiv_share')">Close</a>
</div>
<table id="repos" align="center" cellspacing="20px">
<thead>
<tr>
<th>File name</th>
<th>Share</th>
</tr>
</thead>
<?php
while($row = mysql_fetch_array($result)) {
$id=$row['id'];
$user_id = $row['uid'];
$filename =$row['user_file_name'];
?>
<tbody>
<tr>
<td id ="actions"><?php echo $filename; ?></td>
<td id ="actions">
<a name="<?php echo $filename;?>" class="file" href="#" onClick="pop('popDiv_share')">Share</a>
</td>
</tr>
</tbody>
<?php
}
?>
</table>
</body>
</html>
否则使用这种方式
$sql = "INSERT INTO $mysql_database.$UsersTable (firstName, lastName, password, email,userType)VALUES ('$firstName', '$lastName', '$password','$email','$userType')";