dpgbh20688 2016-01-07 23:45
浏览 32
已采纳

使用$ _POST从Select语句设置文本框值?

I'm currently trying to create a update type of script where a admin can click a update button, the text that's already in the database is shown in the textboxes & the admin can then replace the text if it's incorrect.

I currently have a error called "Undefined index". This is when i attempt to set a value to my text boxes from my select statement.

This is my current progress,

<?php
require 'configure.php';
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['Edit']))
{
    $sql = "UPDATE `pet` SET `pettype` = :petType WHERE id = :id";
    $statement = $pdo->prepare($sql);
    $id = $_GET['id'];
    $petType = $_POST['petType'];
    $statement->bindValue(':id', $id);
    $statement->bindValue(':petType', $petType);
    $update = $statement->execute();
if($sql)
{
header('location:index.php');
}
}
$jobID = $_GET['id'];
$stmt = $pdo->query('SELECT * FROM pet WHERE petType = "' . $jobID . '"');
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}

?>

This is my update code, as well as my populate statement at the bottom.

<form method="post" action="">
Name:<input type="text" name="petID" value="<?php echo $_POST['petID'] ?>" /><br />
Age:<input type="text" name="petType" value="<?php echo $_POST['petType'] ?>" /><br /><br />
<br />
<input type="submit" name="submit" value="update" />
</form>

This is my Form which i'm using to edit the data.

I've tried

value="<?php echo ($pdo['petType']) ?>"
value="<?php echo $stmt['petType'] ?>"

Perhaps someone with a little more knoeledge would be able to help. Thank you

  • 写回答

1条回答 默认 最新

  • duangang1991 2016-01-07 23:55
    关注
    value="<?php echo $result['petType'] ?>"
    

    But a problem with your code is that you're just inserting the $jobID into the query without sanitizing it. This could lead to sql injection.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记