【问题标题】:Undefined index php by POSTPOST未定义的索引php
【发布时间】:2014-12-19 10:12:48
【问题描述】:

我有我的ppf.php 文件:

它有一个包含一些项目的表单,我在其中显示数据库中的数据,它可以正常工作,我对此没有任何问题。

<form name="pagar"  method="post" action="updaterecord.php">
<input type="text" name="num_paciente" size=40 maxlength=40 readonly value="<?php echo $fila['num_paciente']; ?>">// Here I show data from my data base // it works.
<input name="monto"  size=40 maxlength=40 type="text"  value="" required />
<textarea id="concepto" name="concepto" rows="5" cols="58" required></textarea>
..more input fields
 <input align="middle" type="submit" value="paga">
</form>

问题是

ppf.php 有一个提交按钮,我的表单发送到updaterecord.php。 在 updaterecord.php 中,我需要接收我的 ppf.php 的所有值来更新我的数据库中的表:

<?php
$num_paciente=$_POST['num_paciente'];
$monto=$_POST['monto'];
$concepto=$_POST['concepto'];

$updater="UPDATE op SET monto = '$monto', concepto='$concepto', status='PAGADO' where num_paciente='".$num_paciente."'";
mysql_query($updater,$con)or die (mysql_error());
?>

它不起作用:我明白了:

Notice: Undefined index: num_paciente in C:\xampp\htdocs\...\updaterecord.php on line 16    
Notice: Undefined index: monto in C:\xampp\htdocs\...\updaterecord.php on line 17    
Notice: Undefined index: concepto in C:\xampp\htdocs\...\updaterecord.php on line 18

我该如何解决这个问题? 谢谢

【问题讨论】:

  • 正如 Barry 所说,您应该指定表单以使用 POST 方法。另外,请查一下什么是 SQL 注入。 php.net/manual/en/images/…
  • 发送var_dump($_POST) 以查看脚本真正接收到的内容。
  • @JustinKiang 我的代码有它,(对不起,我的错误。我更新了问题)。而且它不起作用...
  • 更好的是,执行 print_r($_REQUEST) 来查看所有内容
  • 你是怎么发的?我没有看到一个按钮。你使用按钮还是 JavaScript?

标签: php mysql undefined-index


【解决方案1】:

使用

<form method="post">

使用 post 操作发送表单值。默认方法是“获取”。 您还可以在 php 脚本中使用 $_GET 获取值。

【讨论】:

  • 对不起,我没有把它放在这里,在问题中,但代码有它
  • 按钮在我的 ppf.php 表单中
【解决方案2】:

除了@Barry 的回答,您的查询必须更正如下:

$updater="UPDATE op SET monto = '".$monto."', concepto='".$concepto."', status='PAGADO' where num_paciente='".$num_paciente."'";

我又看了一遍你的代码,请注意textarea,改一下:

<input type="text" name="num_paciente" size=40 maxlength=40

<input type="text" name="num_paciente" size="40" maxlength="40"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-18
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    相关资源
    最近更新 更多