我创建了名为user_tndrequest
的数据库命名的想法和表,连接部分也已完成,我已经完成了以下编码部分,但是当我在文本框中输入任何文本时,单击后输出提交按钮导致错误,请帮助我。
<?php
require_once('auth.php');
?>
<html>
<h2 align="center"> TND REQUEST </h2>
<h3 align="center">
<form method="post" action="database2.php">
<p><textarea name="inputtxt" cols=40 rows=8></textarea></p>
<input type="submit" value="submit" />
<p align="center"><a href="index.php">logout</a></p>
</form>
</h3>
</body >
数据库2的代码:
<?php
define('db_name','idea');
define('db_user','root');
define('db_password','');
define('db_host','localhost');
$link=mysql_connect(db_host,db_user,db_password);
if (!$link)
{
die('couldnot connetc:'.mysql_error());
}
$db_selected=mysql_select_db(db_name,$link);
if (!$db_selected)
{
die('cant connect to db');
}
$value=$_POST['inputtxt'];
$sql="INSERT INTO user_tndrequest (inputtxt) VALUES ('$value')";
if (!mysql_query($sql)) {
die('error');
# code...
}
$dbc = mysqli_connect(db_host, db_user, db_password, 'inputtxt');
$query = "SELECT * FROM user_tndrequest";
$result = mysqli_query($dbc, $query);
//echo var_dump($result);
$temp = 0;
$colour = "blue";
$array_len = mysqli_num_rows($result);
//echo $array_len;
while ($row = mysqli_fetch_array($result)) {
if ($temp == $array_len - 1) {
echo '<p>'.'<center>'.'<font face="Helvetica">'.'<font size="7">' . $row['inputtxt'] .'</font>'. '</font>'.'</center>' . '</p>';
}
$temp++;
}
mysql_close();
?>