私はテーブルに 'fuser'と記載されている各フィールドのデータベースを持っています。フィールド入力エリアを持つ.phpフォームを持っています。私は、& DUPLICATEKEY更新機能への入力を試してみましたが、それは次のようにERRORINSERTINTO You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near
ERROR ON duplicatekey UPDATE関数への挿入
私のコードのようないくつかのエラーを取得しているようだ:
<?php include('profile.php'); ?>
<?php
$servername = "localhost";
$dbusername = "root";
$dbpassword = "*******";
$dbname = "the_database";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$aboutme = $_POST['aboutme'];
$subject1 = $_POST['subject1'];
$subject2 = $_POST['subject2'];
$subject3 = $_POST['subject3'];
$country = $_POST['country'];
$birthday = $_POST['birthday'];
$occupation = $_POST['occupation'];
$mobile = $_POST['mobile'];
$websiteurl = $_POST['websiteurl'];
$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO fuser (firstname, lastname, aboutme, subject1, subject2, subject3, country, birthday, occupation, mobile, websiteurl)
VALUES ('$firstname', '$lastname', '$aboutme', '$subject1', '$subject2', '$subject3', '$country', '$birthday', '$occupation', '$mobile', '$websiteurl')
ON DUPLICATE KEY UPDATE
firstname = VALUES('$firstname'),
lastname = VALUES('$lastname'),
aboutme = VALUES('$aboutme'),
subject1 = VALUES('$subject1'),
subject2 = VALUES('$subject2'),
subject3 = VALUES('$subject3'),
country = VALUES('$country'),
birthday = VALUES('$birthday'),
occupation = VALUES('$occupation'),
mobile = VALUES('$mobile'),
websiteurl = VALUES('$websiteurl')";
if ($conn->query($sql) === TRUE) {
echo '<script language="javascript">';
echo 'alert("Your details have been updated succesfully..")';
echo '</script>';
echo '<a href="profile.php"></a>';
}
else {
echo "ERROR" . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
任意の提案が高く評価されている。..
あなたはsql-injectionにかなりオープンしています...あなたのクエリをダンプしてPHPMyAdminで実行しようとしましたか? – Naruto
@ MagnusEriksson – harishk
@magnus Dude、これで助けてくれる – harishk