gpt4 book ai didi

php - 帖子内容的空白输出

转载 作者:行者123 更新时间:2023-12-02 21:33:46 27 4
gpt4 key购买 nike

当我回显帖子内容或将其插入数据库时​​,我总是得到空白结果$这是我的代码

PHP

<?php

$host = "mysql.1freehosting.com";
$user = "u249494946_user";
$pass = "aqwaqwaqw";
$db = "u249494946_first";

mysql_connect($host,$user,$pass);
mysql_select_db($db);

/*if(isset($_post["ajout"])) {
echo("error submitting");
}
else {
*/
var_dump(isset($_post['submit']));
$nom = $_post["nom"];
$prenom = $_post["prenom"];
echo $_post[nom];
echo $nom;
$result1=mysql_query("INSERT INTO eleve (id,nom,prenom) VALUES (NULL,'$nom','$prenom')");var_dump($result1);
/*$result2=mysql_query("INSERT INTO eleve(id, nom, prenom) VALUES (null,'y','y')");
if(!$result1){
die('errreur result1 :' . mysql_error());
}
*/
var_dump($_POST);

?>

HTML

<html>
<head>

<title>disaster</title>
</head>
<body>
<div align="center">
<form id="form" method="post" action="ajout.php">

nom : <input type="text" id="nom" />
prenom : <input type="text" id="prenom" />
<input type="submit" value="ajouter" id="submit" />

</form>
</div>
</body>
</html>

这是我得到的结果

bool(false)
bool(true)
array(3) {
["nom"]=>
string(7) "example"
["prenom"]=>
string(7) "example"
["submit"]=>
string(7) "ajouter"
}

最佳答案

$_POSTsuperglobal并且必须为大写。

将所有 $_post 更改为 $_POST

另外,正如Alon所述,您需要命名您的输入元素:

<input type="text" id="nom" name="nom" />

这要归功于阿隆。

我还建议您切换到mysqli_*功能与 prepared statementsPDOmysql_*函数已弃用,并将从 future 的 PHP 版本中删除。


编辑

您的某些输入元素未命名:

更改为:

nom : <input type="text" id="nom" name="name" />
prenom : <input type="text" id="prenom" name="prenom" />
<input type="submit" value="ajouter" name="submit" id="submit" />

关于php - 帖子内容的空白输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21865884/

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