Click to See Complete Forum and Search --> : php date
piertiong
11-20-2003, 10:38 PM
was wondering whether i'm doing the right thing:
$datetime = date("D M Y \a\\t h:i a");
$datetime displays as Fri Nov 2003 at 12:2
without completing minutes and not showing "am"
Pittimann
11-21-2003, 05:26 AM
Hi!
On my machine your code does what you want it to do. Wonder why the stuff behaves differently in your case.
This will have to work:
$datetime = date("D M Y").' at '.date("h:i a");
echo $datetime;
Cheers - Pit
piertiong
11-21-2003, 07:58 AM
Originally posted by Pittimann
Hi!
On my machine your code does what you want it to do. Wonder why the stuff behaves differently in your case.
This will have to work:
$datetime = date("D M Y").' at '.date("h:i a");
echo $datetime;
Cheers - Pit
thanks i will try that.
and also, what's wrong with the following?
require("config.php");
mysql_connect($sqlhost,$sqluser,$sqlpass);# or die(mysql_error() . "<br>Could not connect to the database.");
mysql_select_db($sqldb);# or die(mysql_error() . "<br>Could not select the database.";
$sql = "SELECT * FROM fubonews_user WHERE poster = '".$PHP_AUTH_USER."' AND password = '".$PHP_AUTH_PW;
$result = mysql_query($sql) or die("<div align=\"center\">No such user.</div>");
mysql_close();
exit;
it doesn't seem to let me pass even if i enter in the correct username and password.
Do your die() functions give you anything, if you un-comment them? Also, unless there's more code than that, if everything works, all you'll get is a blank screen. ;)
piertiong
11-21-2003, 08:23 AM
this code is in a file which is included by the main page, so if the password can pass that if statement, the rest of the page would work.
this is the original hard code:
if($PHP_AUTH_USER != "username" && $PHP_AUTH_PW != "password"){ # Set your username and password here
$title = "Incorrect Login";
include("header.php");
echo " Incorrect Login.";
exit;
}
i want to edit it to search from a database.
this is possible?
if( !($result = mysql_query($sql)) )
{
$title = "Incorrect Login";
include("header.php");
echo "Incorrect Login.";
exit;
}
DaiWelsh
11-21-2003, 08:34 AM
I think you are confusing a query that fails and a query that brings back no results.
$sql = "SELECT * FROM fubonews_user WHERE poster = '".$PHP_AUTH_USER."' AND password = '".$PHP_AUTH_PW;
$result = mysql_query($sql) or die("<div align=\"center\">No such user.</div>");
$result will be valid even if there are 0 results, provided the query runs successfully. You need to test for matches with
if(mysql_num_rows($result))
HTH,
Dai
Also change this line: $sql = "SELECT * FROM fubonews_user WHERE poster = '".$PHP_AUTH_USER."' AND password = '".$PHP_AUTH_PW; to... $sql = "SELECT * FROM fubonews_user WHERE poster = '" . $PHP_AUTH_USER . "' AND password = '" . $PHP_AUTH_PW . "'"; You missed the last single quote.;)
piertiong
11-21-2003, 09:19 PM
Originally posted by YoN
Also change this line: $sql = "SELECT * FROM fubonews_user WHERE poster = '".$PHP_AUTH_USER."' AND password = '".$PHP_AUTH_PW; to... $sql = "SELECT * FROM fubonews_user WHERE poster = '" . $PHP_AUTH_USER . "' AND password = '" . $PHP_AUTH_PW . "'"; You missed the last single quote.;)
thanks for the reply, i have solved it.
the working code is this:
$sql = "SELECT * FROM fubonews_user WHERE poster = '$PHP_AUTH_USER' AND password = '$PHP_AUTH_PW'";
$result = @mysql_query($sql);
//$result = mysql_query($sql)
if( mysql_num_rows($result) == 0 )
{
$title = "Incorrect Login";
include("header.php");
echo "Incorrect Login.";
exit;
}