webwired
-
Posts
16 -
Joined
-
Last visited
Never
Posts posted by webwired
-
-
Hi, does anyone know if it is possible to do a multiple count inside one query? Like say you want to separately count 3 different fields. The first one would be easy, to count the total, use mysql_num_rows, but the other two I'm not sure... like how many of those rows match this fields criteria and how many rows meet that fields criteria.
-
kenrbnsn, I put in that error code and changed the elseif to an else... Like txmedic03 said, "$row[] is not defined until you define it" was what I was getting... So I changed to his code, still nothing, no errors, no redirect... nothing, even when I put in a wrong username and password. So I made a hybrid of his code and my code, still doesn't redirect, it'll do anything you want it to do, but redirect...
[code]
<?php
session_start();
error_reporting(E_ALL);
if(isset($_POST['login'])) {
include_once "connection.php";
$query = mysql_query("select * from users where username = '{$_POST['username']}' and password = '{$_POST['password']}'") or die(mysql_error());
$count = mysql_num_rows($query);
if ($count == 1) {
$row = mysql_fetch_assoc($query);
$_SESSION['userid'] = $row['id'];
$_SESSION['condition'] = 'logged';
$_SESSION['username'] = $row['username'];
header("Location: index.php");
}else {
echo 'Invalid Username and/or Password';
}
}
?>
[/code] -
Ok, did all of those things... Still don't work. Here's my code.
[code]
<?php
session_start();
if(isset($_POST['login'])) {
include_once "connection.php";
$query = mysql_query("select * from users where username = '{$_POST['username']}' and password = '{$_POST['password']}'") or die(mysql_error());
$count = mysql_num_rows($query);
if ($count == '1') {
$_SESSION['userid'] = $row['userid'];
$_SESSION['condition'] = 'logged';
$_SESSION['username'] = $row['username'];
header("Location: index.php");
}elseif($count == '0') {
echo 'Invalid Username and/or Password';
}
}
?>
<br><br>
<center>
<h1>Login</h1>
<form method="POST" action="<?php echo $_SERVER['php_self']; ?>">
<table border="0" width="300">
<tr>
<td>Username</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="login" value="Submit"></center></td>
</tr>
</table>
</form>
</center>
[/code] -
I'm not sure about if error reporting is turned on, I'll have to ask dedicated server support,... but I did try another test, I put your code into mine and it worked fine, but when I changed the redirect URL back to loginaction.php it wouldn't work again... so it leads me to think something about my loginaction.php page isn't accepting the redirect somehow...
[code]
<?php
session_start();
$_SESSION['userid'] = $_GET[userid];
$_SESSION['condition'] = $_GET[condition];
$_SESSION['username'] = $_GET[username];
header("Location: index.php");
?>
[/code] -
The result of test is as follows:
Address: [a href=\"http://url.com/header_target.php?userid=1234&condition=logged&username=test1234\" target=\"_blank\"]http://url.com/header_target.php?userid=12...ername=test1234[/a]
Displays:
Array
(
[userid] => 1234
[condition] => logged
[username] => test1234
)
-
Sorry, yeah I missed that on the Header, I'll remember from now on the {}
Still doesn't work though, like you expected. Is there some kind of rule about header("Location: with register_globals off versus with register_globals on that I'm missing? -
I've made all of these changes as you can see from the following code, but it still doesn't redirect to the loginaction.php page with the register_globals off. I tried to change the task if login was successful, such as echo something and that works, so it's definately something about the header that register_globals doesn't like.[code]header("Location: loginaction.php?" . "userid=$row[userid]&" . "condition=logged&" . "username=$row[username]");[/code]
[code]
<?php
if(isset($_POST["login"])) {
include_once "connection.php";
$query = mysql_query("select * from users where username = '{$_POST['username']}' and password = '{$_POST['password']}'") or die(mysql_error());
$count = mysql_num_rows($query);
if ($count == '1') {
header("Location: loginaction.php?" . "userid=$row[userid]&" . "condition=logged&" . "username=$row[username]");
}elseif($count == '0') {
echo 'Invalid Username and/or Password';
}
}
?>
<br><br>
<center>
<h1>Login</h1>
<form method="POST" action="<?php echo $_SERVER[php_self]; ?>">
<table border="0" width="300">
<tr>
<td>Username</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="login" value="Submit"></center></td>
</tr>
</table>
</form>
</center>
[/code] -
Forgive me thorpe, but on your example I think you forgot to make your example change, was it supposed to be if(isset($_POST["login"])) ?
-
Well, it just doesn't redirect to the loginaction.php page... When you enter your username and password, it just comes back to the login screen... So its accessing the database and seeing that its a valid username and password, because if you enter a bad username and password, it'll perform: echo 'Invalid Username and/or Password'; It works fine with register_globals "ON".
-
I have researched and researched and read tutorial after tutorial and I just can't seem to get it... Could someone please tell me why the following login script won't work with register_globals off
[b]login.php[/b]
[code]
<?php
if(isset($_POST[login])) {
include_once "connection.php";
$query = mysql_query("select * from users where username = '$_POST[username]' and password = '$_POST[password]'")or die(mysql_error());
$count = mysql_num_rows($query);
if ($count == 1) {
header("Location: loginaction.php?" . "userid=$row[userid]&" . "condition=logged&" . "username=$row[username]");
}elseif($count == 0) {
echo 'Invalid Username and/or Password';
}
}
?>
<br><br>
<center>
<h1>Login</h1>
<form method="POST" action="<?php echo $_SERVER[php_self]; ?>">
<table border="0" width="300">
<tr>
<td>Username</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="login" value="Submit"></center></td>
</tr>
</table>
</form>
</center>
[/code]
[b]loginaction.php[/b]
[code]
<?php
session_start();
$_SESSION['userid'] = $_GET[userid];
$_SESSION['condition'] = $_GET[condition];
$_SESSION['username'] = $_GET[username];
header("Location: index.php");
?>
[/code] -
Thank you, it worked, but I'm sure you already knew that... Anyways, thanks again.
-
I have read through php.net and even the datetime help on phpfreaks, all of which tell me this is the correct format for my datetime... This is what is in the mysql database 2006-03-14 15:04:24 in a datetime field, called datetime... this is what I am using to show it, $datetime = date("F j, Y, g:i A", $row[datetime]); Can anyone give me a hint as to what I am doing wrong? It outputs December 31, 1969, 7:33 PM. Here's my code...
[code]
include_once "../cgi-bin/connection.php";
$query = mysql_query("SELECT * FROM paybycheck WHERE paid = '0' ORDER BY datetime DESC");
while ($row = mysql_fetch_array($query)) {
$datetime = date("F j, Y, g:i A", $row[datetime]);
echo '<a href="paidbycheck.php?id=', $row[id], '">', $datetime . ' ' . $row[name] . ' ' . $row[city] . ' ' . $row[state], '</a><p>';
}
[/code] -
After the four digit number is broken down into four separate numbers, can you then turn it into a letter as A=0, B=1 and so on? I thought this was supposed to work, but it didn't...
[code]
$digit1 = ($seg1digit1(Ord('A')));
[/code] -
Thank you, works like a charm.
-
Hi, I've tried several splitting techniques on php.net, but I can't seem to find one that will allow me to do something like this...
Split this 4 number variable into 4 different variables, in order.
$number = '3956';
Such as this.
$digit1 = '3';
$digit2 = '9';
$digit3 = '5';
$digit4 = '6';
Could anyone please help me?
Multiple count inside one query
in PHP Coding Help
Posted
[code]
$bdate = date('Y-m-d 00:00:00', mktime(0, 0, 0, $_POST[month], $_POST[day], $_POST[year]));
$edate = date('Y-m-d 23:59:59', mktime(0, 0, 0, $_POST[month], $_POST[day], $_POST[year]));
$query1 = mysql_query("select link from refererlog WHERE datetime BETWEEN '$bdate' AND '$edate'") or die(mysql_error());
$row = mysql_fetch_assoc($query1);
$total = mysql_num_rows($query1);
$query2 = mysql_query("select link from refererlog where link = 'advertiser1'" AND datetime BETWEEN '$bdate' AND '$edate') or die(mysql_error());
$row = mysql_fetch_assoc($query2);
$advertiser1= mysql_num_rows($query2);
$percentadvertiser1 = (($advertiser1 / $total) * 100);
$query3 = mysql_query("select link from refererlog where link = 'advertiser2' AND datetime BETWEEN '$bdate' AND '$edate'") or die(mysql_error());
$row = mysql_fetch_assoc($query3);
$advertiser2 = mysql_num_rows($query3);
$percentadvertiser2 = (($advertiser2 / $total) * 100);
$leftover = ($total - ($advertiser1 + $advertiser2));
$percentleftover = (($leftover / $total) * 100);
[/code]