用户输入是';使用php从html表单中读取
我的代码中出现了一个错误,基本上我的用户输入没有被读取,我不知道为什么。我使用了isset,它跳过了,这意味着用户输入没有被读取,对吗?为什么不呢?当我提交表单时,我收到另一个错误,上面写着“注意:未定义的变量:绑定在C:\xampp\htdocs\editart.php中” 但我认为这是因为当你搜索时,你不再有身份证了。我留下了一些代码来展示用户输入是';使用php从html表单中读取,php,Php,我的代码中出现了一个错误,基本上我的用户输入没有被读取,我不知道为什么。我使用了isset,它跳过了,这意味着用户输入没有被读取,对吗?为什么不呢?当我提交表单时,我收到另一个错误,上面写着“注意:未定义的变量:绑定在C:\xampp\htdocs\editart.php中” 但我认为这是因为当你搜索时,你不再有身份证了。我留下了一些代码来展示 <?php if(isset($_GET['id'])) { $artistID = fix_string($_GET['id'])
<?php
if(isset($_GET['id']))
{
$artistID = fix_string($_GET['id']);
$sql = ("SELECT artName FROM artist WHERE artID = '$artistID' ");
$result = $conn->prepare($sql);
$result->execute();
$result->bind_result($bound);
$result->fetch();
}
else {
echo "this is broken";
}
?>
<form method="post" action="editartist.php"/>
<?php echo '<input type="text" name="artistname" value= "'.$bound.'">' ?>
<input type="submit" value="Save"/>
</form>
<?php
if(isset($_GET['id'])) {
if(isset($_GET['artistname'])) {
$userinput = $_GET['artistname'];
echo "$userinput $artistID";
$sqltwo = ("UPDATE artist SET artName='$userinput' WHERE artID='$artistID'");
$stmt = $conn->prepare($sqltwo);
$stmt->execute();
} else {
echo "this is broken 2";
}
}
?>
因为您正在html表单中使用POST方法,
而在php中正在等待GET方法
我重写了您的代码,假设您正在Get请求中发送ID
如下
<?php
if(isset($_GET['id']))
{
$artistID = fix_string($_GET['id']);
$sql = ("SELECT artName FROM artist WHERE artID = '$artistID' ");
$result = $conn->prepare($sql);
$result->execute();
$result->bind_result($bound);
$result->fetch();
}
else {
echo "this is broken";
}
?>
<form method="post" action="editartist.php"/>
<?php echo '<input type="text" name="artistname" value= "'.$bound.'">' ?>
<input type="submit" value="Save"/>
</form>
<?php
//no need to check for the id here , assuming you are posting data now.and you //already checked at the top of script for $_GET['id']
if(isset($_POST['artistname'])) {
$userinput = $_POST['artistname'];
echo "$userinput $artistID";
$sqltwo = ("UPDATE artist SET artName='$userinput' WHERE artID='$artistID'");
$stmt = $conn->prepare($sqltwo);
$stmt->execute();
} else {
echo "this is broken 2";
}
?>
您必须在提交时传递idaction=“editArtister.php?id=“
这是什么$bound
变量?发送id的表单是什么?你能发布吗?他正在发送post请求,而监听GET请求则不会这样做:)另外,过滤你的输入!!如果artistID为“fake”;删除table artist“并运行第一个查询,则不再有表“artist”。注意代码注入!id来自页面名称这还不起作用,清理过滤器或绑定参数会解决我的问题吗,或者这只是我应该再次尝试的东西我输入了错别字是的,这仍然不起作用你需要编写完整的场景你在做什么,没有清理和绑定参数只会保护你的应用程序。