Jump to content

[SOLVED] user identification problem


franknu

Recommended Posts

Ok, i want to create a control panel for some users to insert or update news

 

my problem is that it it saying that there is no user with the password and user name that i am inserting but there is a user that match that criteria

 

here is my code

 

 


$conn = mysql_connect($host, $username, $password)
or die ('there is ' .mysql_error());

$db = mysql_select_db($database, $conn) or die('Could not connect to database. ' .mysql_error());



$headline = addslashes ($_POST['headline']);
$body = addslashes($_POST['body']);
$writer = addslashes($_POST['writer']);
$date= addslashes($_POST['date']);
$picture = addslashes($_POST['$picture']);
$user = addslashes($_POST['$user']);
$password= addslashes($_POST['$password']);



if ( isset($_POST['user']) && isset($_POST['password']) )
{
    
     $query = mysql_query("SELECT * FROM news WHERE `user`='$user' AND `password` ='$password'");

 }  

 if (mysql_num_rows > 0)
{
      $row = mysql_fetch_assoc($result);
  
  $NewsID= $row['NewsID'];
      $headline = $row['headline'];
      $body =  $row['body'];
  $writer= $row['writer'];
      $date = $row['Keyword'];
      $picture =  $row['picture'];
  
  }
  
   else
	  
	  {
                    echo "<p><b>username and/or password not found. Try again?</b></p>";
                    exit;
          }
   

echo"$query";

?>

Link to comment
https://forums.phpfreaks.com/topic/61419-solved-user-identification-problem/
Share on other sites

ok with this code it does all the opposite it goes in without verifying the user and password

 


if ( isset($_POST['user']) && isset($_POST['password']) )
{
    
     $query = mysql_query("SELECT * FROM news WHERE `user`='$user' AND `password` ='$password'");

 } 


 if ($result = mysql_query($query))
  { 
  
  if (mysql_num_rows($result)) {
  
 $row = mysql_fetch_assoc($result);
  
  $NewsID= $row['NewsID'];
      $headline = $row['headline'];
      $body =  $row['body'];
  $writer= $row['writer'];
      $date = $row['Keyword'];
      $picture =  $row['picture'];
  
  }
  
  
   else
	  
	  {
                    echo "<p><b>username and/or password not found. Try again?</b></p>";
                    exit;
          }
}

echo"$query";

?>

On this line:

if (mysql_num_rows > 0) {

You didn't tell it which query to use with the mysql_num_rows.

 

Try this code:

<?php

$conn = mysql_connect($host, $username, $password)
    or die('there is ' .mysql_error());
$db = mysql_select_db($database, $conn) or die('Could not connect to database. ' .mysql_error());

$headline = addslashes($_POST['headline']);
$body = addslashes($_POST['body']);
$writer = addslashes($_POST['writer']);
$date= addslashes($_POST['date']);
$picture = addslashes($_POST['$picture']);
$user = addslashes($_POST['$user']);
$password= addslashes($_POST['$password']);



if (isset($_POST['user']) && isset($_POST['password']) ) {
    $query = mysql_query("SELECT * FROM news WHERE `user`='$user' AND `password` ='$password'");
    
    if (mysql_num_rows($query) > 0) {
        $row = mysql_fetch_assoc($result);
        
        $NewsID= $row['NewsID'];
        $headline = $row['headline'];
        $body =  $row['body'];
        
        $writer= $row['writer'];
        $date = $row['Keyword'];
        $picture =  $row['picture'];
        
    } else {
        echo "<p><b>username and/or password not found. Try again?</b></p>";
        exit;
    }
    
}

?>

<?php

$conn = mysql_connect($host, $username, $password)
    or die('there is ' .mysql_error());
$db = mysql_select_db($database, $conn) or die('Could not connect to database. ' .mysql_error());

$headline = addslashes($_POST['headline']);
$body = addslashes($_POST['body']);
$writer = addslashes($_POST['writer']);
$date= addslashes($_POST['date']);
$picture = addslashes($_POST['$picture']);
$user = addslashes($_POST['$user']);
$password= addslashes($_POST['$password']);



if (isset($_POST['user']) && isset($_POST['password']) ) {
    $query = mysql_query("SELECT * FROM news WHERE `user`='$user' AND `password` ='$password'");
    
    if (mysql_num_rows($query) > 0) {
        
while($row = mysql_fetch_assoc($result)){
        
        $NewsID= $row['NewsID'];
        $headline = $row['headline'];
        $body =  $row['body'];
        
        $writer= $row['writer'];
        $date = $row['Keyword'];
        $picture =  $row['picture'];
        
    } else {
        echo "<p><b>username and/or password not found. Try again?</b></p>";
        exit;
    }
    
}

}
?>

well, it is just going through without doing user identification

 

here is my code

 


<?
$host = "localhost";
$username = "d";
$password = "asas";
$database = "asdasd";

$conn = mysql_connect($host, $username, $password)
    or die('there is ' .mysql_error());
$db = mysql_select_db($database, $conn) or die('Could not connect to database. ' .mysql_error());

$headline = addslashes($_POST['headline']);
$body = addslashes($_POST['body']);
$writer = addslashes($_POST['writer']);
$date= addslashes($_POST['date']);
$picture = addslashes($_POST['$picture']);
$user = addslashes($_POST['user']);
$password= addslashes($_POST['password']);


if (isset($_POST['user']) && isset($_POST['password']) ) {
    $query = mysql_query("SELECT * FROM news WHERE `user`='$user' AND `password` ='$password'");
    
    if (mysql_num_rows($query) > 0) {
        
while($row = mysql_fetch_assoc($result))
{
        
        $NewsID= $row['NewsID'];
        $headline = $row['headline'];
        $body =  $row['body'];
        
        $writer= $row['writer'];
        $date = $row['Keyword'];
        $picture =  $row['picture'];
        
    } 
}
else 

{
        echo "<p><b>username and/or password not found. Try again?</b></p>";
        exit;
    }
    
}


?>

try this ok.

 

editted ok

<?php

$host = "localhost";
$username = "d";
$password = "asas";
$database = "asdasd";

$conn = mysql_connect($host, $username, $password)
    or die('there is ' .mysql_error());
$db = mysql_select_db($database, $conn) or die('Could not connect to database. ' .mysql_error());

$headline = addslashes($_POST['headline']);
$body = addslashes($_POST['body']);
$writer = addslashes($_POST['writer']);
$date= addslashes($_POST['date']);
$picture = addslashes($_POST['picture']);
$user = addslashes($_POST['user']);
$password= addslashes($_POST['password']);



if (isset($_POST['user']) && isset($_POST['password']) ) {

    $query = "SELECT * FROM news WHERE `user`='$user' AND `password` ='$password'";
    
    $result=mysql_query($query)or die("mysql_error()");
    
    if (mysql_num_rows($result) > 0) {
        
while($row = mysql_fetch_assoc($result)){
        
        $NewsID= $row['NewsID'];
        $headline = $row['headline'];
        $body =  $row['body'];
        
        $writer= $row['writer'];
        $date = $row['Keyword'];
        $picture =  $row['picture'];
        
    }
    
}else {
        echo "<p><b>username and/or password not found. Try again?</b></p>";
        exit;
  }
}
  

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.