Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   isset() help (http://www.programmingforums.org/showthread.php?t=15007)

kishou Jan 23rd, 2008 10:23 AM

isset() help
 
im just wondering but why won't this isset() function not working? it still inerts the values nito my MySQL database even if the comment box isnt filled out. and thanks!
here's my code:

:

<?php
if (!isset($_POST['comment'])
{
die("Please out whole form.");
}
else
$con = mysql_connect("localhost","kishou","0973059457");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("aaabatt_mainwebsite", $con);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$comment = mysql_real_escape_string($_POST['comment']);
$sql=("INSERT INTO Comments (name, email, comment)
VALUES
('$name','$email','$comment')");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)


?>
<?php
//Redirect Browser
header("Location: http://www.kishouvision.com/tutorials/commentshow.php");
?>
<html>
<head>
<title>
</title>
</head>
<body>
</body>
</html>


kruptof Jan 23rd, 2008 10:29 AM

Re: isset() help
 
The variable is set but it's empty. Try using the is_empty function

Sane Jan 23rd, 2008 1:06 PM

Re: isset() help
 
Someone should probably edit his post to censor his MySQL password. Just because it's localhost doesn't necessarily mean its safe.

kishou Jan 23rd, 2008 1:30 PM

Re: isset() help
 
Quote:

Originally Posted by Sane (Post 140128)
Someone should probably edit his post to censor his MySQL password. Just because it's localhost doesn't necessarily mean its safe.

oh thats no my username or password. :P

Sane Jan 23rd, 2008 1:37 PM

Re: isset() help
 
Thank goodness. ^_^

You had me worried. And while I'm here, to elaborate on kruptof's well-spotted catch: isset only checks to see if the variable exists. It's useful to stop a user from directly accessing the .php script (where no post data is being sent). In such an event, isset will return false for any corresponding $_POST keys.

kishou Jan 23rd, 2008 4:45 PM

Re: isset() help
 
Quote:

Originally Posted by Sane (Post 140134)
Thank goodness. ^_^

You had me worried. And while I'm here, to elaborate on kruptof's well-spotted catch: isset only checks to see if the variable exists. It's useful to stop a user from directly accessing the .php script (where no post data is being sent). In such an event, isset will return false for any corresponding $_POST keys.

lol. i think i'll just use if (empty ($_POST['comment')
ok now wth? i cant use print,echo, or die... :(

kishou Jan 23rd, 2008 8:26 PM

Re: isset() help
 
ok i figured out why lol. all i had to do was just change it to: if ($_POST['comment']==false)
hahhah wow.

titaniumdecoy Jan 23rd, 2008 8:50 PM

Re: isset() help
 
Quote:

Originally Posted by kishou (Post 140133)
oh thats no my username or password.

It's not his, it's his client's. :P

kishou Jan 23rd, 2008 9:03 PM

Re: isset() help
 
Quote:

Originally Posted by titaniumdecoy (Post 140160)
It's not his, it's his client's. :P

uh oh speghatti ohs!


All times are GMT -5. The time now is 3:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC