wheres the error??

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

Post Reply
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

wheres the error??

Post by Wldrumstcs »

Hi, I am made a page that sends out email with the message of whatever i typed into the textarea, but when i tried to put a simple password on the page, it didnt work. I just wanna make it so you have to type in a password, and if its correct, then echo the other textarea where i can send out the email. Heres what I have got (There's no parse error, it just doesnt work)

Code: Select all

<body>

<form method="post" action="admin.php">
<p>Password:&nbsp; <input type="password" name="password" size="20"></p>
<p><input type="submit" value="submit" name="submit"></p>
</form>

<?
if($submit){
if($_POST[$password] == "poop"){
	echo '
<form method="post" action="admin.php">
<p><textarea rows="5" name="tidbit" cols="20"></textarea>
<p><input type="submit" value="Submit" name="B1"></p>
<p><input type="reset" value="Reset" name="B2"></p>
</form>
';
}
if($_POST[tidbit] != "") {
mysql_connect("localhost","username","password") or die ("Unable to connect to MySQL server."); 
$db = mysql_select_db("database") or die ("Unable to select requested database.");

$result = mysql_query("SELECT email FROM members") or die("Invalid query: " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
if(mail($line[email], "Your weekly TidBit", $_POST["tidbit"], "From: webmaster@tidbitfacts.com")){
echo "sent";
}
 else
echo "not sent";
}}
else
echo 'That password is incorrect!';
}
?>

</body>
sanyuan
Forum Newbie
Posts: 10
Joined: Sat Nov 22, 2003 8:55 pm
Location: australia

Post by sanyuan »

You need to change the echo string at the top from :

$_POST[$password]

to

$_POST['password']

You can also change your $submit condition to

($_POST['submit'] == 'Submit')
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I want to mention;

Code: Select all

if($submit){
if($_POST['password'] == "poop"){ // rewritten correctly
You use $_POST at one of them, but not the other? 'submt' is also something that was 'posted' so you should $_POST['submit'] that also to avoid future errors.
Post Reply