NEWBIE to php

NEWBIE to php

am 24.12.2005 05:11:14 von vncntj

I apologize for asking such an easy question but I'm trying to check if
the recordcount is "1". If so, it should redirect the page.

// Connecting, selecting database
$link=mysql_connect ("localhost", "user", "password") or die ('I cannot
connect to the database because: ' . mysql_error());
mysql_select_db ("dbData");
$slogin = trim($HTTP_POST_VARS["tlogin"]);
// Performing SQL query
$query = "SELECT Count(*) FROM tusernames WHERE logins = '$slogin'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());


if ($HTTP_POST_VARS["postback"]=="y") {
// Printing results in HTML

echo "

\n";
echo "\t\n";
echo "\t\n";

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t\n";
foreach ($line as $col_value) {
echo "\t\t\n";
}
echo "\t\n";
}
echo "
$col_value
\n";
}

// This is where I'm having difficulty....

if ($col_value) == "1" {
header("www.espn.com"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
}

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>








Re: NEWBIE to php

am 24.12.2005 12:43:57 von Jonathan

vncntj@hotmail.com wrote:

> if ($HTTP_POST_VARS["postback"]=="y") {
> // Printing results in HTML
>
> echo "

\n";
> echo "\t\n";
> echo "\t\n";
>
> while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
> echo "\t\n";
> foreach ($line as $col_value) {
> echo "\t\t\n";
> }
> echo "\t\n";
> }
> echo "
$col_value
\n";
> }
>
> // This is where I'm having difficulty....
>
> if ($col_value) == "1" {
> header("www.espn.com"); /* Redirect browser */
>
> /* Make sure that code below does not get executed when we redirect. */
> exit;
> }

I think the problem might be that you use the header() function
incorrect. If you would like to redirect the user to the english version
of the header() function description you should do that like this:

header ("Location: http://www.php.net/manual/en/function.header.php");

The second problem could be that you try to access the $col_value
outside the foreach loop... it might be that there is really no value or
there is no value anymore...

You might want to change your code like this:

if ($HTTP_POST_VARS["postback"]=="y") {
// Printing results in HTML

echo "\n";

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t\n";
foreach ($line as $col_value) {
if ($col_value) == "1" {
header("Location: www.espn.com"); /* Redirect browser */
echo "\t\t\n";
} else {
echo "\t\n";
}
}
echo "
$col_value
\n";
}
exit;
}

Some other tips... don;t hardcode your passwords in your files, use
include files (preferrably in a subdirectory) which you can only allow
access to by the webserver/php user. This way your username and password
are saver from the outside world.

Jonathan

Re: NEWBIE to php

am 25.12.2005 18:50:25 von vncntj

Jonathan...
thanks for the tips...
everything worked perfect.
happy holidays.

Re: NEWBIE to php

am 10.01.2006 02:41:50 von Jim Michaels

there is a function in the PHP manual under MySQL functions called
mysql_num_rows(resource result)
for example, mysql_num_rows($result)
Jim
wrote in message
news:1135397474.371278.241950@z14g2000cwz.googlegroups.com.. .
>I apologize for asking such an easy question but I'm trying to check if
> the recordcount is "1". If so, it should redirect the page.
> >
> // Connecting, selecting database
> $link=mysql_connect ("localhost", "user", "password") or die ('I cannot
> connect to the database because: ' . mysql_error());
> mysql_select_db ("dbData");
> $slogin = trim($HTTP_POST_VARS["tlogin"]);
> // Performing SQL query
> $query = "SELECT Count(*) FROM tusernames WHERE logins = '$slogin'";
> $result = mysql_query($query) or die('Query failed: ' . mysql_error());
>
>
> if ($HTTP_POST_VARS["postback"]=="y") {
> // Printing results in HTML
>
> echo "

\n";
> echo "\t\n";
> echo "\t\n";
>
> while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
> echo "\t\n";
> foreach ($line as $col_value) {
> echo "\t\t\n";
> }
> echo "\t\n";
> }
> echo "
$col_value
\n";
> }
>
> // This is where I'm having difficulty....
>
> if ($col_value) == "1" {
> header("www.espn.com"); /* Redirect browser */
>
> /* Make sure that code below does not get executed when we redirect. */
> exit;
> }
>
> // Free resultset
> mysql_free_result($result);
>
> // Closing connection
> mysql_close($link);
> ?>
>

>
>
>

>
>

>
>
>

Re: NEWBIE to php

am 10.01.2006 02:46:59 von Jim Michaels

I guess I am not sure why the while loop on a COUNT(*). threw me off for a
bit. You don't really need it do you?
"Jim Michaels" wrote in message
news:JdSdneNhEa99jV7eRVn-ug@comcast.com...
> there is a function in the PHP manual under MySQL functions called
> mysql_num_rows(resource result)
> for example, mysql_num_rows($result)
> Jim
> wrote in message
> news:1135397474.371278.241950@z14g2000cwz.googlegroups.com.. .
>>I apologize for asking such an easy question but I'm trying to check if
>> the recordcount is "1". If so, it should redirect the page.
>> >>
>> // Connecting, selecting database
>> $link=mysql_connect ("localhost", "user", "password") or die ('I cannot
>> connect to the database because: ' . mysql_error());
>> mysql_select_db ("dbData");
>> $slogin = trim($HTTP_POST_VARS["tlogin"]);
>> // Performing SQL query
>> $query = "SELECT Count(*) FROM tusernames WHERE logins = '$slogin'";
>> $result = mysql_query($query) or die('Query failed: ' . mysql_error());
>>
>>
>> if ($HTTP_POST_VARS["postback"]=="y") {
>> // Printing results in HTML
>>
>> echo "

\n";
>> echo "\t\n";
>> echo "\t\n";
>>
>> while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
>> echo "\t\n";
>> foreach ($line as $col_value) {
>> echo "\t\t\n";
>> }
>> echo "\t\n";
>> }
>> echo "
$col_value
\n";
>> }
>>
>> // This is where I'm having difficulty....
>>
>> if ($col_value) == "1" {
>> header("www.espn.com"); /* Redirect browser */
>>
>> /* Make sure that code below does not get executed when we redirect. */
>> exit;
>> }
>>
>> // Free resultset
>> mysql_free_result($result);
>>
>> // Closing connection
>> mysql_close($link);
>> ?>
>>

>>
>>
>>

>>
>>

>>
>>
>>
>
>