来自html表的mysql帖子

use*_*483 0 html php mysql

我想让我的sql将html表单中的信息发布到我的数据库中但是请继续:

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: firstname in C:\wamp\www\insert.php on line 29
Call Stack
#   Time    Memory  Function    Location
1   0.0005  247624  {main}( )   ..\insert.php:0
Run Code Online (Sandbox Code Playgroud)

我使用的代码是:

<form action="insert.php" method="post">
   Name: <input type="text" name="firstname">
   <input type="submit" value="Submit">
</form>

<?php
// This is the connection to my database
$con = mysql_connect('127.0.0.1', 'shane', 'diamond89');
if (!$con){
   die('Could not Connect: ' . mysql_error());
}

// This selects which database i want to connect to
$selected = mysql_select_db("shane",$con);
if (!$con){
   die("Could not select data");
}

// This inserts new information to the Database
$name = $_POST['name'];

$query = "INSERT INTO test1 VALUES('id', '$name')";
mysql_query($query) or die('Error' . mysql_error());

// This closes my connection
mysql_close($con)
?>
Run Code Online (Sandbox Code Playgroud)

Ilj*_*lja 6

你的表单有一个名为firstnamenot 的输入name,所以$_POST['name']应该是$_POST['firstname']

更改

    // This inserts new information to the Database
    $name = $_POST['name'];
Run Code Online (Sandbox Code Playgroud)

   // This inserts new information to the Database
   $name = $_POST['firstname'];
Run Code Online (Sandbox Code Playgroud)