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
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";

?>

Link to comment
Share on other sites

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;
    }
    
}

?>

Link to comment
Share on other sites

<?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;
    }
    
}

}
?>

Link to comment
Share on other sites

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;
    }
    
}


?>

Link to comment
Share on other sites

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;
  }
}
  

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.