ironmaiden666 Posted August 31, 2007 Share Posted August 31, 2007 I've got this script: <html> <head> <title>Hi User</title> </head> <body> <h1>Hi User</h1> <?php if (empty($userName)){ print <<<HERE <form> Please enter your name: <input type = "text" name = "userName"><br> <input type = "submit"> </form> HERE; } else { print "<h3>Hi there, $userName!</h3>"; } //end ?> </body> </html> I've got apache 2.2.4 and php 5.2.3 I type in my name but nothing happens and my name disappears... usually I have to write $_POST[something] Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/ Share on other sites More sharing options...
scottybwoy Posted August 31, 2007 Share Posted August 31, 2007 For a start you need to have <form action='yourscript.php' method='post'> that deals with recieving the data. Then you need to assign the data to the $var like $username = $_POST['username']; in your script and make it global so your html can find it by putting global $username at the top of yourscript.php Please go and read w3c schools on html forms and php so you will understand Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338455 Share on other sites More sharing options...
jitesh Posted August 31, 2007 Share Posted August 31, 2007 <html> <head> <title>Hi User</title> </head> <body> <h1>Hi User</h1> <?php $userName = $_GET['userName']; if (empty($userName)){ print "contents"; ?> <form> Please enter your name: <input type = "text" name = "userName"> <input type = "submit"> </form> <? } else { print "<h3>Hi there, $userName!</h3>"; } //end ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338458 Share on other sites More sharing options...
ironmaiden666 Posted August 31, 2007 Author Share Posted August 31, 2007 jitesh thank you but there's one problem word 'contents' appears Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338463 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Share Posted August 31, 2007 remove the 'print "contents";' then... Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338465 Share on other sites More sharing options...
ironmaiden666 Posted August 31, 2007 Author Share Posted August 31, 2007 marvellous!!! Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338467 Share on other sites More sharing options...
LemonInflux Posted August 31, 2007 Share Posted August 31, 2007 yw Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338468 Share on other sites More sharing options...
ironmaiden666 Posted August 31, 2007 Author Share Posted August 31, 2007 I tried these also but they don't work out I tried your tips but in vain... this one is ok <html> <head> <title>Checkbox Demo</title> </head> <body> <h1>Checkbox Demo</h1> <h3>Demonstrates checkboxes</h3> <form method ="post" action ="checkDemo.php"> <h3>What would you like with your order?</h3> <ul> <li><input type ="checkbox" name ="chkFries" value ="1.00">Fries </li> <li><input type ="checkbox" name ="chkSoda" value =".85">Soda </li> <li><input type ="checkbox" name ="chkShake" value ="1.30">Shake </li> <li><input type ="checkbox" name ="chkKetchup" value =".05">Ketchup </li> </ul> <input type ="submit"> </form> </body> </html> but this one not... <html> <head> <title>Checkbox Demo</title> </head> <body> <h3>Demonstrates reading checkboxes</h3> <?php print <<<HERE chkFries: $chkFries <br> chkSoda: $chkSoda <br> chkShake: $chkShake <br> chkKetchup: $chkKetchup <br> <hr> HERE; $total = 0; if (!empty($chkFries)){ print ("You chose Fries <br> \n"); $total = $total + $chkFries; } // end if if (!empty($chkSoda)){ print ('You chose Soda <br> \n"); $total = $total + $chkSoda; } // end if if (!empty($chkShake)){ print ('You chose Shake <br> \n'); $total = $total + $chkShake; } // end if if (!empty($chkKetchup)){ print ("You chose Ketchup <br> \n'); $total = $total + $chkKetchup; } // end if print "The total cost is \$$total \n"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338471 Share on other sites More sharing options...
jitesh Posted August 31, 2007 Share Posted August 31, 2007 use if (isset($_POST['chkFries'])){ insted of if (!empty($chkFries)){ Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338474 Share on other sites More sharing options...
jitesh Posted August 31, 2007 Share Posted August 31, 2007 <?php $total = 0; if (isset($_POST['chkFries'])){ print ("You chose Fries \n"); $total = $total + $_POST['chkFries']; } // end if if (isset($_POST['chkSoda'])){ print ("You chose Soda \n"); $total = $total + $_POST['chkSoda']; } // end if if (isset($_POST['chkShake'])){ print ("You chose Shake \n"); $total = $total + $_POST['chkShake']; } // end if if (isset($_POST['chkKetchup'])){ print ("You chose Ketchup \n"); $total = $total + $_POST['chkKetchup']; } // end if print "The total cost is \$ ".$total ." \n"; ?> Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338476 Share on other sites More sharing options...
ironmaiden666 Posted August 31, 2007 Author Share Posted August 31, 2007 thank you this forum and the users are the best!!! Polish ones are not so good Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338480 Share on other sites More sharing options...
ironmaiden666 Posted August 31, 2007 Author Share Posted August 31, 2007 can you tell me what to do to have it in this shape: chkFries: 1.00 chkSoda: You chose fries The total is: 1.00 Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338484 Share on other sites More sharing options...
ironmaiden666 Posted August 31, 2007 Author Share Posted August 31, 2007 anyone will help me? Link to comment https://forums.phpfreaks.com/topic/67419-solved-php-i-cant-execute-this-script-something-wrong-with-variables/#findComment-338724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.