我使用XAMPP在mysql中创建了一个名为test226333的数据库我正在尝试将数据发送到这样的表中
“http://localhost/write_data.php?value=100”
for database and table details screenshot click here
我的PHP代码是
<?php
$dbusername = "ganesh";
$dbpassword = "varma";
$server = "localhost";
$dbconnect = mysql_connect($server, $dbusername, $dbpassword);
$dbselect = mysql_select_db("test226333",$dbconnect);
$sql = "INSERT INTO test226333.data VALUES ('".$_GET["value"]."')";
mysql_query($sql);
?>
进入链接时没有显示任何内容,数据也没有存储在数据库中
请帮助我 提前谢谢..
答案 0 :(得分:-1)
试试这个:
$servername = "localhost";
$username = "ganesh";
$password = "varma";
$dbname = "test226333";
$mysqli = new mysqli($servername, $username, $password, $dbname);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO <your table name>(col1, col2, col3) VALUES (?, ?, ?)"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
/* Prepared statement, stage 2: bind and execute */
if (!$stmt->bind_param("i", $val1)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->bind_param("s", $val2)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->bind_param("i", $val3)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
/* explicit close recommended */
$stmt->close();