PHP ve MySQL kullanarak son giriş zamanı güncellemek için veritabanı alınamıyor?

2 Cevap php

İşte burada çalışmak için görünmüyor benim son giriş parçasıdır. Ben bir yerde berbat düşünüyorsun?

    // Query the database:
    $q = "SELECT user_id, first_name, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL";      
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));


    if (@mysqli_num_rows($r) == 1) { // A match was made.

        // Register the values & redirect:
        $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); 
        $q = "UPDATE users SET last_login = NOW() WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; 
        // save the info to the database
        $r= mysqli_query( $dbc );
        mysqli_free_result($r);
        mysqli_close($dbc);

İşte tam yazısıdır.

<?php
if (isset($_POST['submitted'])) {
	require_once (MYSQL);

	// Validate the email address:
	if (!empty($_POST['email'])) {
		$e = mysqli_real_escape_string ($dbc, $_POST['email']);
	} else {
		$e = FALSE;
		echo '<p class="error">You forgot to enter your email address!</p>';
	}

	// Validate the password:
	if (!empty($_POST['pass'])) {
		$p = mysqli_real_escape_string ($dbc, $_POST['pass']);
	} else {
		$p = FALSE;
		echo '<p class="error">You forgot to enter your password!</p>';
	}

	if ($e && $p) { // If everything's OK.

		// Query the database:
		$q = "SELECT user_id, first_name, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL";		
		$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));


		if (@mysqli_num_rows($r) == 1) { // A match was made.

			// Register the values & redirect:
			$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); 
			$q = "UPDATE users SET last_login = NOW() WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; 
			// save the info to the database
			$r= mysqli_query( $dbc );
			mysqli_free_result($r);
			mysqli_close($dbc);

			$url = BASE_URL . 'index.php'; // Define the URL:
			ob_end_clean(); // Delete the buffer.
			header("Location: $url");
			exit(); // Quit the script.

		} else { // No match was made.
			echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>';
		}

	} else { // If everything wasn't OK.
		echo '<p class="error">Please try again.</p>';
	}

	mysqli_close($dbc);

} // End of SUBMIT conditional.
?>

2 Cevap

Muhtemelen bile sorguyu çalıştıran değil,

$q = "UPDATE users SET last_login = NOW() WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; 
                        // save the info to the database
                        $r= mysqli_query( $dbc );

olmalıdır

$q = "UPDATE users SET last_login = NOW() WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; 
                        // save the info to the database
                        $r= mysqli_query( $dbc ,$q);

ve ben güncelleme kullanarak gerçekleşti olsun affected_rows kontrol etmek için tavsiye ediyorum

Belki vahşi bir tahmin biraz, ama bu garip görünüyor:

$q = "UPDATE users SET last_login = NOW() WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; 
// save the info to the database
$r= mysqli_query( $dbc );

Güncelleştirme sorgusu $q depolanır, ancak $q değişken mysqli_query bir parametre olarak geçirilir değil mi?

Should it not be passed as a second parameter ?
ie :

$r= mysqli_query( $dbc, $q );

(That's what is done for the select sorgu - ama update biri için)