php - 信息不显示在数据库中。 XAMPP

标签 php mysql database xampp connect

这个问题不太可能帮助任何 future 的访客;它只与一个小地理区域、一个特定时刻或一个非常狭窄的情况相关,而这些情况通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visit the help center .




9年前关闭。




我正在尝试制作一个简单的 RSVP 程序,用户只需输入他们的名字和姓氏,然后单击是或否。然后将信息带入数据库。我被困在用户可以输入名字和姓氏并单击"is"或“否”的位置,但它没有显示在数据库中。这是我到目前为止所拥有的。任何帮助将不胜感激。我仍然是 php 的菜鸟。我也在为我的数据库使用 xampp。谢谢

这是上半年

<H1><div align="center">RSVP</div></H1>

<H3>Enter in the information that is requried</H3>

<form method ="POST" action = "RSVP.php">

Please type in your first name</br>

<input type = "text" name="fname"/></br>

Please type in your last name</br>

<input type = "text" name="lname"/>

</br></br></br></br>

<H2>Will you be attending?</h2>

<input type="radio" name="yorn" value="Yes">Yes

<input type="radio" name="yorn" value="No">No</br>


<input type="submit" value="Submit">

</form>

这是 php 的一半
<?php

if(empty($_POST['fname']) || empty($_POST['lname']))

print "Please type in BOTH first name and last name";
else{

$DBConnect = @mysql_connect("localhost", "Jordan", "bigboy");

if ($DBConnect === FALSE){

    print "<p>Unable to connect to the database server.<p>". "<p>Error code " 
                .mysql_errno(). ": ". mysql_error() . "</p>";

}else{

    $DBName = "jdatabase";

    mysql_select_db("jdatabase") or die(mysql_error());

    $TableName = "RSVP";

    $firstname = $_POST['fname'];

    $lastname = $_POST['lname'];

    $YorN = $_POST['yorn'];

    $SQLsting = "INSERT INTO '$TableName' VALUES(NULL, 

                   '$firstname','$lastname','$YorN')";

$QueryResult = @mysql_connect($SQLsting, $DBConnect);

}if ($QueryResult === FALSE){

    print "<p>Unable to execute query.<p>". "<p>Error code " 
                .mysql_errno($DBConnect). ": ". mysql_error($DBConnect) . "</p>";

}else{

    print "Thank You for RSVP";

}

mysql_close($DBConnect);    

}   

?>

最佳答案

这是输入转义的基本 mysqli 用法。

$DBName = "jdatabase";
$TableName = "RSVP";
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$YorN = $_POST['yorn'];

/* Connection info for PHP/MySQL test database. */
defined('DB_HOST') ? NULL : define('DB_HOST', 'localhost');
defined('DB_USER') ? NULL : define('DB_USER', 'testUzer');
defined('DB_PWD') ? NULL : define('DB_PWD', 'xYzT@9123');
defined('DB_NAME') ? NULL : define('DB_NAME', $DBName);

/* Connect to database */
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PWD, DB_NAME);
if ($mysqli->connect_errno) exit("ERROR: Could not connect to database.");

/* Build the query string and escape input. */
$query = sprintf("INSERT INTO $TableName (first_name, last_name, yorn) VALUES('%s', '%s', '%s')", 
$mysqli->real_escape_string($firstname), 
$mysqli->real_escape_string($lastname), 
$mysqli->real_escape_string($YorN));

/* Insert the record. */
$result = $mysqli->query($query);
if(! $result) exit("ERROR: Database query failed.");

关于php - 信息不显示在数据库中。 XAMPP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938556/

相关文章:

php - 通过 csv 文件更新 MySQL 中的表

Android开发-Unknown Host异常问题

php - mysql 按天过滤

database - pg_restore : [compress_io] could not uncompress data: invalid code lengths set

mysql - 查询任意相关表时的 JOIN 与 SELECT IN

php - nginx + PHP-FPM : Doing away with fastcgi params

php - mysql - sql select 从id开始

php - 用于从单个数据库中的多个表中进行选择的 SQL 查询

php - 按钮上的 Ajax 监听事件单击然后运行 ​​Php 文件

mysql - 我如何始终从一个表中提取数据,但如果它在 MySQL 中,还从第二个表中提取数据?