Jump to content

trying to greet the user by first name and lastname when they log in??


cluce

Recommended Posts

here is the code I am using but it will not echo their name.  Does anybody have any suggestions on how to do this correctly?

 

<?php

 

$sql = "SELECT f_name, l_name FROM auth_users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";

 

?>

 

 

<?php 

echo "Welcome", $sql; 

?>

 

 

Please read this for your site safety: http://en.wikipedia.org/wiki/Sql_injection

 

Are you passing this SQL string to the database and looking at the results?

 

<?php

$sql = "SELECT f_name, l_name FROM auth_users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";

$query = mysql_query( $sql, $connection );
if( $row = mysql_fetch_array( $query ) )
{
echo 'Welcome '. $row['f_name'] .' '. $row['l_name'];
}
?>

 

monk.e.boy

You really ought to do some tutorials on fetching data from a database. Your code does nothing but sets a string to a variable.

 

<?php

<?php

  $sql = "SELECT f_name, l_name FROM auth_users WHERE username = '{$_POST["username"]}' AND password = '{$_POST["password"]}'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo "Welcome {$row['f_name']} {$row['l_name']}<br />";
    } else {
      echo "No user found";
    }
  } else {
    echo "Query failed<br />$sql<br />" . mysql_error();
  }

?>

 

PS: I removed the use of the PASSWORD function form your query as it should NOT be used to store passwords. It is an internal mysql function, not intended for use.

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.