douduiyun6125 2014-09-26 21:45
浏览 65
已采纳

我无法使用HTML表单和PHP将记录插入数据库

No records show up in my MyPHP Database when I run these scripts.

I am running: APACHE 2.4.7 MYSQL 5.6.15 PHP 5.5.8

First the HTML Code...

<html>

<center>
  <font face="Helvetica">

<u><b>Matthew Gieger's Guestbook</b></u>

<form action="link.php" method="post"/>
<p>Name: </p>
<input type="text" name="Name" required/>
<p>Email: </p>
<input type="email" name="Email" required />
<p>Message: </p>
<p><textarea rows="4" cols="50" name="Message"> </textarea></p>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</center>
</html>

And the PHP Script. This is where I think the problem is...

 <?php

$username='root';
$password='';
$database='guestbook';

$name= $_POST['Name'];
$email= $_POST['Email'];
$message= $_POST['Message'];

new mysqli('localhost',$username,$password,$database) or die("could not connect to localhost");

echo"connected";

mysqli:"insert into contacts (Name,Email,Message,Timestamp) values ($name,$email,$message,date())";

?>

I get no error when I run the code. I just get the expected "connected"

  • 写回答

3条回答 默认 最新

  • doufubian3479 2014-09-26 21:55
    关注

    You don't have a mysqli object defined anywhere. And you're not using mysqli_query() anywhere.

    Here are the docs to mysqli.

    Try something like this:

    $mysqli = new mysqli('localhost', $username, $password, $database);
    
    /* check connection */
    if ($mysqli->connect_errno) {
        printf("Connect failed: %s
    ", $mysqli->connect_error);
        exit();
    }
    
    $mysqli->query("INSERT INTO `contacts`(`Name`, `Email`, `Message`, `Timestamp`) VALUES ('". $name ."', '". $email ."', '". $message ."', '". $timestamp ."')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?