gpt4 book ai didi

php - 如何在mysql查询中插入$_GET[variable]

转载 作者:行者123 更新时间:2023-11-29 13:03:55 24 4
gpt4 key购买 nike

我想从网址获取 ID,例如:www.example.com/upload.php?sc=1

并将 ID 输入到我的数据库中。我已经附上了我的代码,但是 ID 没有插入到数据库中。请帮助我获取也存储在数据库中的 ID。

谢谢

<?php require_once '../database.php'; ?>
<?php $eventid = $_GET['event']; ?>
<?php $sc = $_GET['sc']; ?>
</head>

<body>
<?php
$result = mysql_query("SELECT * FROM category");
while($row = mysql_fetch_array($result)){
echo "<a href=?event=" . $row['id'] .">" . $row['category'] . "</a>&nbsp;";
}
?><br>
<?php
$result = $db->query("SELECT * FROM sub_category WHERE category_id LIKE '" . $eventid . "';");
$event = $result->fetch();
?>
<?php
echo "<a href=?event=" . $row['id'] .">" . $row['category'] . "</a>&nbsp;";
?>
<?php
echo "<a href=?sc=" . $event['id'] .">" . $event['sub_category'] . "</a>&nbsp;";
?>
<form method="POST" action="upload1.php" enctype="multipart/form-data" id="subForm">
<b>Upload your file here</b>
<br/>
<span>Name:*</span>&nbsp;<input name="name" type="text" class="required"><br/>
Description:* <input name="description" type="text" class="required"><br/><br/>
Thumbnail Size: 400px X 400px | Featured Image Size: 2100px X 525px<br><br>
Browse:*<input name="userfile" type="file" class="required">&nbsp;<br>
<br/>
<input type="submit" value="Upload" style="width: 150px">
</form>
<?php
$name = $_POST['name'];
$description = $_POST['description'];
$sc = $_GET['sc'];
$kj=$sc;
if(empty($name)) {
echo("<br>All the above details must filled in! We dont want monkeys on the page!");
}
else {
$target="images/";
$target.=$_FILES['userfile']['name'];
move_uploaded_file($_FILES['userfile']['tmp_name'],$target);
move_uploaded_file($_FILES['userfile']['tmp_name'],$target);
mysql_query("INSERT INTO upload(upload, name, description, sub_category_id) VALUES ('".$target."', '$_POST[name]', '$_POST[description]', '".$sc."')") or die( mysql_error());
echo "<br>File Successfully Uploaded!";
}
?>

最佳答案

mysql_query("INSERT INTO upload(upload, name, description, sub_category_id) VALUES ('".$target."', '$_POST[name]', '$_POST[description]', '".$sc."')") or die( mysql_error());

这行可能会杀人。试试这个:

mysql_query("INSERT INTO upload(upload, name, description, sub_category_id) VALUES ('" . $target . "', '$name', '$description', '" . $sc . "')") or die(mysql_error());

您已设置

$name = $_POST['name'];
$description = $_POST['description'];
$sc = $_GET['sc'];
$kj = $sc;

就在之前!并且在您的查询中您使用了

$_POST[name];

这是 1. 不正确的,因为名称前后缺少 ' 和 ',2. 您在前面声明了一个变量 $name。

关于php - 如何在mysql查询中插入$_GET[variable],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22985985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com