Error problems in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

In your View_news.php code, you have


while ($data == mysql_fetch_array ($result))
{
?>


What is this "while" statement actually doing? the { indicated you are wanting to start an operation, but nothing follows that you are wanting it to perform if the action is true. Was this intentional? If so, why?


PS, the while ($data == mysql_fetch_array ($result)) should be while ($data = mysql_fetch_array ($result)) as volka stated..
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

I have a statment to finish off the { it is at the bottom of the all of the code. it is...

Code: Select all

<?
&#125;
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

  • now you've
    while ($data == mysql_fetch_array ($result))
    in your code, too. In this case the loop-conditions checks wether the content of $data is equal to the result of mysql_fetch_array before entring the loop-body, which is highly improbable. So your loop isn't executed a single time.
    You will need something like

Code: Select all

<?php

while ($data = mysql_fetch_array ($result))
{ ?>
<fieldset>
	<legend>
		<h3><?php echo $data['headline']; ?></h3>
		by<?php echo $data['user']; ?>
	</legend>
	<?php echo $data['news']; ?>
</fieldset>
<?php
}

?>
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

I got it working. I forgot I had that extra = sign in the code when you guys told me to add it on there. I got rid of it and now it works. Thanks for lal the help!! :D
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

Ok, this same script, I have a logout link and that works, but when they exit out of the browser I want it to log them out because when I exit out here it doesn't log me out. It just keeps me logged in when I go back to the site.

This is what I have.

Code: Select all

<?
if ((!$username) || (!$password)) {
	header("Location: invalid_login.php");
	exit;
} 

$db_name = "table_name";
$table_name = "news_users";

$connection = @mysql_connect("localhost", "username", "password") 
	or die("Couldn't connect.");

$db = mysql_select_db($db_name, $connection)
	or die("Couldn't select database.");

$sql = "SELECT * FROM $table_name
	WHERE username = "$username" AND password = password("$password")
	"; 

$result = mysql_query($sql) 
        or die ("Can't execute query."); 

$num = mysql_numrows($result); 

if ($num != 0) { 

	$cookie_name_auth = "status";
	$cookie_value_auth = "ok";
	$cookie_expire_auth = time()+86400;
	$cookie_domain_auth = ".bve.32k.org";
	
	setcookie($cookie_name_auth, $cookie_value_auth, $cookie_expire_auth, "/" , $cookie_domain_auth, 0);

	$cookie_name_user = "user";
	$cookie_value_user = "$username";
	$cookie_expire_user = time()+86400;
	$cookie_domain_user = ".bve.32k.org";
	
	setcookie($cookie_name_user, $cookie_value_user, $cookie_expire_user, "/" , $cookie_domain_user, 0);

	header("Location: news.php");

} else { 

	header("Location: invalid_login.php");
	exit;
} 
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$cookie_expire_auth = time()+86400;
makes the cookie valid for one day. But $cookie_expire_auth=0; should delete the cookie when the user closes the current browser.
http://wp.netscape.com/newsref/std/cook ... pires=DATE
...
expires is an optional attribute. If not specified, the cookie will expire when the user's session ends.[/quote]
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

Thanks for all the help. That cookie thing works. I know I am being a pain in the a**. Just trying to fix the errrors that I have been trying to fix on my site. This script is the contact script, and it gives me this error...
Warning: Server Error in mail_form.php on line 23
this is "mail($to, $subject, $msg, $mailheaders);"

Code: Select all

<?php
if (($sender_name == "") && ($sender_email == "") && ($message == "")) {
	header("Location: mail_form.php");
	exit;
}


$msg = "Basic.Visual.Experiments. Mailform\n";
$msg .= "Sender's Name:    $sender_name\n";
$msg .= "Sender's E-Mail:  $sender_email\n";
$msg .= "Message:          $message\n\n";

$to = "kkurkowski@wideopenwest.com";
$subject = "Basic.Visual.Experiments. Mailform";
$mailheaders = "From: $sender_email <> \n";
$mailheaders .= "Reply-To: $sender_email\n\n";

mail($to, $subject, $msg, $mailheaders);
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

  • some questions
  • which version of php?
  • which OS?
  • what are the configuration-settings in [mail function] in your php.ini?
  • Is
    $mailheaders = "From: $sender_email <> \n";
    valid for your mail-server and/or ISP?
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

The server is

Windows.NET

and the PHP I think is

Version 4.1

the contact feedback forms do work on it because I have gotten other scripts working on it, but I am trying to get this one working it. It was working at one time but then I think thye updated the PHP on it and it started erroring out on me.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

but the questions remain:
what are the configuration-settings in [mail function] in your php.ini? (esp. sendmail_from=...) (do not post it, just think about the validity of the configuration)
and is an empty email-address (< >) accepted by your mail-server
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

[mail function]
SMTP= localhost ; for Win32 only
sendmail_from= default_email_of_server@whom.com ; for Win32 only
upload_tmp_dir = C:\PHP\uploadtemp ; temporary directory for HTTP uploaded files (will use system default if not specified)

That isn't the real email. There is a email in there though and it is a valid email for the server.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

then I'm clueless ;)
The last two things I suggest are:

Code: Select all

$mailheaders = "From: $sender_email <$sender_email>\n";
$mailheaders .= "Reply-To: $sender_email\n";
and taking a look into the smtp-server's error protocol.
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

Still gives you the same error. I will keep trying to see what is wrong with it. Probably something stupid.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

$mailheaders = "From: $sender_email <$sender_email>\n";
Should'nt From: be FROM:?

It think I had issues with the case sensitiveness of this part...
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

I figured out what it was. On the server they did not set the username and password for the smtp server on it. So once it is set then it should work. Thanks for the help guys.
Post Reply