解決済み:PHP MYSQLとIF文内のクエリ
私の変数の宣言には矛盾があります。それは私のconnect_database内の$パスワードを宣言することがわかりますが、私のアカウントのスクリプトでも$パスワードは常に設定されているため、常に最後にpasをスキップすることを意味します...そして、これは進行中の作業なので、アカウントのログイン...
ORIGINALとして:
私はPHPでのif文の内側のクエリに問題があります。私はアカウントの更新スクリプトをやっています。
私はデータベースのトップへの接続が必要で、POSTの結果に応じて、いくつかのif文で異なるクエリを実行します。
すべてのIF文を渡して実行すると、最後にクエリが実行されます。
ifが検出された場合、クエリが行われ、スクリプトでメッセージコードをリダイレクトして終了コードを終了させます。
問題は、実行後にスクリプトが終了しないことです。クエリは実行されますが、最後まで実行されます。リダイレクトや終了はありません。
if文の中でデータベースを必要とする回避策が見つかりました。しかし、私の最初のアイデアは、それを一番上に含め、ifステートメントで、そして一番下で接続を使用することでした。
なぜ誰かがうまくいくのか、他の人がうまくいかないのか説明できますか? 大きな問題ではありません。 は、内部データベースを必要(これは動作します
<?php
session_start();
if(!isset($_SESSION["user"])) {
header("location: ../../../login/login_form.php");
exit;
}
$user = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$id = $_SESSION['user_id'];
//Display if user and email is blank - try again---------------
if($user==NULL || $email==NULL){
header('location: ../../../index.php?show=account&message=1');
exit;
}
require_once('../../connect_database.php');
//Check if password is blank - meaning only updating user and email -----
if ($password==NULL){
$query = "UPDATE user SET user='$user', email='$email' WHERE id=".$id;
mysql_query($query) or die(mysql_error());
header('location: ../../../index.php?show=account&message=0');
mysql_close();
exit;
}
//Display if password less than 8 characers----------------
if(strlen($password)<8 && $password!=NULL){
header('location: ../../../index.php?show=account&message=2');
mysql_close();
exit;
}
//Run this if everything is to be changed incl. password-------
$query = "UPDATE user SET user='$user', password=md5('$password'), email='$email' WHERE id=".$id;
mysql_query($query) or die(mysql_error());
mysql_close();
header('location: ../../../index.php?show=account&message=0');
?>
:私はちょうど...なぜ
どうもありがとう
このdoesntの仕事を(は、IF文の外のデータベースを必要と)理解していませんIFの声明の最後にもう一度):
<?php
session_start();
if(!isset($_SESSION["user"])) {
header("location: ../../../login/login_form.php");
exit;
}
$user = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$id = $_SESSION['user_id'];
//Display if user and email is blank - try again---------
if($user==NULL || $email==NULL){
header('location: ../../../index.php?show=account&message=1');
exit;
}
//Check if password is blank - meaning only updating user and email ----
if ($password==NULL){
require_once('../../connect_database.php');
$query = "UPDATE user SET user='$user', email='$email' WHERE id=".$id;
mysql_query($query) or die(mysql_error());
header('location: ../../../index.php?show=account&message=0');
mysql_close();
exit;
}
//Display if password less than 8 characers------------------
if(strlen($password)<8 && $password!=NULL){
header('location: ../../../index.php?show=account&message=2');
exit;
}
//Run this if everything is to be changed incl. password----------
require_once('../../connect_database.php');
$query = "UPDATE user SET user='$user', password=md5('$password'), email='$email' WHERE id=".$id;
mysql_query($query) or die(mysql_error());
mysql_close();
header('location: ../../../index.php?show=account&message=0');
?>
あなたのページはエラーを表示するように設定されていますか? 'if($ password == NULL){'はユーザをページの一番下と同じ場所にも送ります。あなたの内側に 'echo 'inside if 1'のようないくつかのブレークポイントを設定します。出口;それが捕らえられるところを見てください。 –