私のデータベースでは、 "authorid"列の "article"テーブルと "id"列の "author"テーブルがあります。 2つの表はこれらの列で結合されているので、ユーザーが記事を送信すると、「authorid」列に作成者のIDを表示しながら「article」表が記事を受信します。しかし、私は "authorid"カラムを現在のユーザIDで更新することはできません。ユーザーが記事を送信するたびに、「authorid」列は、「author」の「id」列に定義されたIDを表示する代わりに、0を返します。ログインしている現在のユーザーのデータを取得
**PHP**
if (isset($_GET['add']))
if (!userIsLoggedIn())
include $_SERVER['DOCUMENT_ROOT'] . '/includes/login.inc.html.php';
exit();
}
include 'form.html.php';
exit();
if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
$text = mysqli_real_escape_string($link, $_POST['text']);
$author = mysqli_real_escape_string($link, $_POST['author']);
$sql = "INSERT INTO article SET
articletext='$text',
articledate=CURDATE(),
authorid='$author'";
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted article: ' . mysqli_error($link);
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}
は、私は、配列内のユーザーデータとストアを選択$著者変数に配列を格納する必要があると思うが、私は現在ログインしているユーザーのユーザーデータを取得する方法がわからないよ。ここに私のuserIsLoggedIn
です機能:
function userIsLoggedIn()
{
if (isset($_POST['action']) and $_POST['action'] == 'login')
{
if (!isset($_POST['email']) or $_POST['email'] == '' or
!isset($_POST['password']) or $_POST['password'] == '')
{
$GLOBALS['loginError'] = 'Please fill in both fields';
return FALSE;
}
$password = md5($_POST['password'] . 'chainfire db');
if (databaseContainsAuthor($_POST['email'], $password))
{
session_start();
$_SESSION['loggedIn'] = TRUE;
$_SESSION['email'] = $_POST['email'];
$_SESSION['password'] = $password;
return TRUE;
}
else
{
session_start();
unset($_SESSION['loggedIn']);
unset($_SESSION['email']);
unset($_SESSION['password']);
$GLOBALS['loginError'] =
'The specified email address or password was incorrect.';
return FALSE;
}
}
if (isset($_POST['action']) and $_POST['action'] == 'logout')
{
session_start();
unset($_SESSION['loggedIn']);
unset($_SESSION['email']);
unset($_SESSION['password']);
header('Location: ' . $_POST['goto']);
exit();
}
session_start();
if (isset($_SESSION['loggedIn']))
{
return databaseContainsAuthor($_SESSION['email'], $_SESSION['password']);
}
}
二つのテーブルは、あなたが見ることができるように、私はので、「ID」を更新するために、「authorid」を得るカント、「作者」の「記事」と「ID」に「authorid」によって結合されています私は上記のように、私はログインしている現在のユーザーのユーザーIDを取得し、そのIDを$authors
に格納する方法を知らない。
**article table**
id articletext articledate authorid
1 Test article 2011-08-05 0
**author table**
id name email password
1 user [email protected] d8a6582c02d188df9ad89a6affa412f7
ご協力いただきありがとうございます!
を打つ前にあなたは、たとえば、authorIdが正常に掲載されてよろしいでしょう$ _POST ['author']は実際にこの値を含んでいますか? – Pelshoff
私はあなたの儀式と思う、私の質問は、現在ログインしているユーザーのIDを取得する方法ですか?あなたのUserIsLoggedIn()関数の – rumspringa00
を$ _SESSION ['loggedIn'] = TRUEに近づけて$ _SESSION ['userid'] = $ idを作成します(idのdbルックアップを行う必要があります)。次の "else"ステートメントの$ _SESSION ['userid']を設定解除することを忘れないでください。 – neokio