私はAdobe Flexを使用して、PHPを使用してデータベースにユーザを正常に投稿しています。今私は私のPHPを修正する必要があります。まず、ユーザーがデータベースにいるかどうかを確認し、フィールドのいくつかを更新します。新しいものであれば、ユーザーを完全に作成する必要があります。存在しないユーザーを作成するためにはすでに動作しているコード部分についてはコメントしました。私はどこが間違っているのか分からない。私はデータベースへの接続についての部分を削除しました。それはうまく動作します。新規ユーザーの作成または既に存在する場合の更新
public function createUser (User $item)
{
//Checking to see if user exists
$checkdb = mysqli_prepare($this->connection, "SELECT firstname FROM users WHERE id =?");
mysqli_stmt_bind_param($checkdb, "s", $item->id);
mysqli_stmt_execute($checkdb);
mysqli_stmt_fetch($checkdb);
if ($checkdb == 0)
{
// If user exists, create record. This code definitely works.
$stmt = mysqli_prepare($this->connection,
"INSERT INTO users (
id,firstname,lastname,gender,dob,latitude,longitude,datesubmitted)
VALUES (?,?,?,?,?,?,?,?)");
$this->throwExceptionOnError();
mysqli_bind_param($stmt, 'sssssdds', $item->id, $item->firstname,
$item->lastname, $item->gender, $item->dob, $item->latitude,
$item->longitude, $item->datesubmitted);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
//If user does exist, then update record
$stmt = mysqli_prepare($this->connection,
"UPDATE users SET latitude=?,longitude=?,datesubmitted=? WHERE id=?");
$this->throwExceptionOnError();
mysqli_bind_param($stmt, 'dds', $item->latitude,
$item->longitude, $item->datesubmitted);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
コードに一貫しているのか、時間を無駄にするのですか? 1分ほど前に、あなたはこれをクラス形式で持っていました。これで個々の関数を作成しています。それはどちらになるのですか? – pthurmond
また、なぜ疑問符に変数を設定していないのですか?我々はあなたのためにすべてを書くことは期待できません。 – pthurmond
あなたのデータベーステーブルはどのように見えますか? – pthurmond