我有一个PHP的问题
问题:
如果您之前看到代码可能您看到两个查询函数插入不同的表,第一个查询插入的问题没有任何问题,但第二个查询不起作用,我不知道为什么请帮我。
在第一个查询中,我向表中插入了新闻数据,第二个查询需要插入图片以便为读者提供更多详细信息。
这是代码:
<?php
ob_start();
session_start();
include("../includes/config.php");
if(!$_SESSION['admin']){
header("Location: index.php");
}
?>
<html>
<body align="center">
<?php
if(isset($_POST['add'])){
$title = $_POST['title'];
$topic = $_POST['topic'];
if(empty($topic) || empty($title)){
echo"please don't leave the feilds empty";
}else{
//file vars
$url = $_FILES["upload"]["tmp_name"];
$path = mysqli_real_escape_string($connect,file_get_contents($url));
$name = mysqli_real_escape_string($connect,$_FILES["upload"]["name"]);
$type = mysqli_real_escape_string($connect,$_FILES["upload"]["type"]);
if(substr($type,0,5) == "image"){
$sql = "INSERT INTO news(title,topic) VALUES('$title','$topic')";
$query = mysqli_query($connect,$sql);
$id = mysqli_insert_id($connect);
$sqll = "INSERT INTO pic(name,type,content,for) VALUES('$name','$type','$path','$id')";
$queryy = mysqli_query($connect,$sqll);
if($query && $queryy){
echo"Worked";
}else{
echo"error";
}
}else{
echo"it's not an image";
echo $type;
}
}
}
?>
<form method="post" action="addnew.php" enctype="multipart/form-data">
<input type="text" name="title" style="text-align:center" placeholder="title"/><br/>
<textarea name="topic" placeholder="topic" style="width:800px;height:500px;resize:none;text-align:right;font-size:23">
</textarea>
<br/>
<input type="file" name="upload"/><br/>
<input type="submit" name="add" value="sed">
</form>
</body>
</html>
答案 0 :(得分:2)
对于第二个查询,请转义列名:
impressions
(2500, 5000] 2332
(5000, 10000] 1118
(10000, 50000] 570
(50000, 10000000] 14
Name: username, dtype: int64
因为$sqll = "INSERT INTO pic(`name`,`type`,`content`,`for`) VALUES('$name','$type','$path','$id')";
等名称是保留的mysql关键字,你显然会收到错误