I want the user to post a comment into the database through the textarea and then the database should put the information back onto the site. But this isn't working!
我希望用户通过textarea将注释发布到数据库中,然后数据库应该将信息重新放回到站点上。但这不起作用!
index.php:
<textarea rows="2" cols="71" wrap="physical" placeholder = "Post Something!" name="rant_box"></textarea>
<input type="submit" value="Post" name="post_btn"/>
<?php
$getquery = mysql_query("SELECT data FROM status ORDER BY id DESC");
while($rows = mysql_fetch_array($getquery)){
$id = $rows['id'];
$status = $rows['status'];
echo $status . '<br />' . '<br />';
}
?>
The data is being correctly entered into the database. But calling it back and posting it back onto the index.php page isn't working.
数据正确输入数据库。但是回调它并将其发回到index.php页面是行不通的。
2 个解决方案
#1
0
First you have to connect to the database, and second you are supposed to say what you are going to use in the SQL statement so : SELECT id,status FROM status OREDER BY ID DESC
Try this :
首先你必须连接到数据库,然后你应该在SQL语句中说明你要使用的内容如下:SELECT id,status FROM status OREDER BY ID DESC试试这个:
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
id,statu
$reponse = $bdd->query('SELECT id,status FROM status ORDER BY ID DESC ');
while ($donnees = $reponse->fetch())
{
echo $donnees['status'];
}
$reponse->closeCursor();
?>
#2
0
Your query is selecting a column called 'data' yet you are trying to inspect a column called 'status' in your resultset. If the column is indeed called 'data', then this line
您的查询正在选择一个名为“data”的列,但您正在尝试检查结果集中名为“status”的列。如果该列确实称为“数据”,那么这一行
$status = $rows['status'];
Based on your select query, should be
根据您的选择查询,应该是
$status = $rows['data'];
But if the column is actually called 'status', then you need the replace 'data' with 'status' in your SQL statement.
但是如果该列实际上被称为“status”,那么您需要在SQL语句中将'data'替换为'status'。
You're also attempting to access $rows['id']
which is not in your select list. But since you're not using that value in your code, is this required? If it is required, you also need to update your select list to include this column, ie
您还尝试访问不在您的选择列表中的$ rows ['id']。但是,由于您没有在代码中使用该值,这是否需要?如果需要,您还需要更新选择列表以包含此列,即
SELECT data FROM status ORDER BY id DESC
Should be
SELECT id, data FROM status ORDER BY id DESC
NB As others have suggested, you shouldn't be using the deprecated mysql_ functions. Refer Choosing an API
NB正如其他人所建议的那样,您不应该使用已弃用的mysql_函数。请参阅选择API
#1
0
First you have to connect to the database, and second you are supposed to say what you are going to use in the SQL statement so : SELECT id,status FROM status OREDER BY ID DESC
Try this :
首先你必须连接到数据库,然后你应该在SQL语句中说明你要使用的内容如下:SELECT id,status FROM status OREDER BY ID DESC试试这个:
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
id,statu
$reponse = $bdd->query('SELECT id,status FROM status ORDER BY ID DESC ');
while ($donnees = $reponse->fetch())
{
echo $donnees['status'];
}
$reponse->closeCursor();
?>
#2
0
Your query is selecting a column called 'data' yet you are trying to inspect a column called 'status' in your resultset. If the column is indeed called 'data', then this line
您的查询正在选择一个名为“data”的列,但您正在尝试检查结果集中名为“status”的列。如果该列确实称为“数据”,那么这一行
$status = $rows['status'];
Based on your select query, should be
根据您的选择查询,应该是
$status = $rows['data'];
But if the column is actually called 'status', then you need the replace 'data' with 'status' in your SQL statement.
但是如果该列实际上被称为“status”,那么您需要在SQL语句中将'data'替换为'status'。
You're also attempting to access $rows['id']
which is not in your select list. But since you're not using that value in your code, is this required? If it is required, you also need to update your select list to include this column, ie
您还尝试访问不在您的选择列表中的$ rows ['id']。但是,由于您没有在代码中使用该值,这是否需要?如果需要,您还需要更新选择列表以包含此列,即
SELECT data FROM status ORDER BY id DESC
Should be
SELECT id, data FROM status ORDER BY id DESC
NB As others have suggested, you shouldn't be using the deprecated mysql_ functions. Refer Choosing an API
NB正如其他人所建议的那样,您不应该使用已弃用的mysql_函数。请参阅选择API