-1

3列の単純なテーブルがあります:

testID は INT(11) 自動インクリメント プライマリ インデックスです。

name は VARCHAR テキストフィールドです

位置は INT(11) フィールドです

<?php
error_reporting(E_ALL);
require("mysqli.test.inc"); 

$name1="Rhonda Hotop"; $position1=456;
$name2="Perry Shafran"; $position2 = 789;
$sqlupdate = "UPDATE test SET name = ?, position =?"; 
$sqlinsert = "INSERT INTO test (name, position) VALUES (name = ?, position = ?)";
//create the connection to the database
$con = new mysqli($hostname,$username,$password,$database);
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }
//test an UPDATE
$statement = $con->prepare($sqlupdate);
$statement->bind_param("si", $name1, $position1);
$statement->execute();
$statement->close();
//test an INSERT
$statement = $con->prepare($sqlinsert);
$statement->bind_param('si', $name2, $position2);
$statement->execute();
$statement->close();
exit();

接続は機能します。

更新は機能します。

ただし、INSERT はそうではありません。正しい testID フィールドを持つ新しいレコードが作成されますが、name2 フィールドと position2 フィールドは両方とも 0 に設定されています。

いくつかの助けをいただければ幸いです。

4

2 に答える 2

1

変化する

$sqlinsert = "INSERT INTO test (name, position) VALUES (name = ?, position = ?)";

$sqlinsert = "INSERT INTO test (name, position) VALUES (?, ?)";
于 2013-06-09T02:21:22.770 に答える
0

この行を変更します

$sqlinsert = "INSERT INTO test (name, position) VALUES (?, ?)";
于 2013-06-09T02:22:44.707 に答える