siwelis Posted May 9, 2007 Share Posted May 9, 2007 if (!$_POST['uploaded'] = NULL){ //If what was posted was NOTHING then $treC = "0"; } else { $treC = "2"; } No matter what, it keeps making the variable equal to "0," even when something WAS posted. Does anyone know what I should be replacing "NULL" with? I tried with 0's, ||'s assigning initial values to the posting form such as 0, nothing has worked so far. Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/ Share on other sites More sharing options...
brianbehrens Posted May 9, 2007 Share Posted May 9, 2007 Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249364 Share on other sites More sharing options...
Barand Posted May 9, 2007 Share Posted May 9, 2007 if (isset($_POST['uploaded']) ) Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249365 Share on other sites More sharing options...
per1os Posted May 9, 2007 Share Posted May 9, 2007 First off you are using the assignment operator a single "=". Second off to check null values, php gives you a nice function www.php.net/is_null. Third you probably want to check if it was set. <?php if (isset($_POST['uploaded']) && !is_null($_POST['uploaded'])){ //If what was posted was NOTHING then $treC = "0"; } elseif (isset($_POST['uploaded']) { // it was set and was not null $treC = "2"; }else { // it wasn't set $treC = "0"; } Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249366 Share on other sites More sharing options...
brianbehrens Posted May 9, 2007 Share Posted May 9, 2007 Even better. Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249369 Share on other sites More sharing options...
siwelis Posted May 9, 2007 Author Share Posted May 9, 2007 <?php if (isset($_POST['uploaded']) && !is_null($_POST['uploaded'])){ //If what was posted was NOTHING then $treC = "0"; } elseif (isset($_POST['uploaded'])) { // it was set and was not null $treC = "2"; }else { // it wasn't set $treC = "0"; } //Thank you for your replies. The above needed an extra ")" - Even when the Form has data entered, it still returns from "else" (verified with echo- almost said TRACE, been taking flash in school). I'm going to try tweaking it some, if you have any more suggestions, please let me know, and when it's solved completely, I'll post that on here. Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249378 Share on other sites More sharing options...
Psycho Posted May 9, 2007 Share Posted May 9, 2007 You don't need the three cases: <?php if (!isset($_POST['uploaded']) || is_null($_POST['uploaded'])){ //If it was not posted or posted value is empty $treC = "0"; } else { // It was set and was not null $treC = "2"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249388 Share on other sites More sharing options...
per1os Posted May 9, 2007 Share Posted May 9, 2007 <?php if (isset($_POST['uploaded'])) { if (is_null($_POST['uploaded'])) { echo 'Uploaded is null'; }else { echo 'Uploaded is NOT null'; } }else { echo 'Post has not been set'; } ?> Let's try that approach and insert the $treC where you want them to be. Or you can do what mjdamato did, probably easier with his way. I am just posting this so you can kind of see the logic in a sense. Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249389 Share on other sites More sharing options...
siwelis Posted May 9, 2007 Author Share Posted May 9, 2007 I am sensing I am making a n00bie mistake. Since I am getting the "Post has not been set" ... It will execute other commands before and after that script using that $_POST['uploaded'] (ie it will upload files to the site) But still get the "Post has not been set" message. Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249397 Share on other sites More sharing options...
trq Posted May 9, 2007 Share Posted May 9, 2007 What is your current code? Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249410 Share on other sites More sharing options...
siwelis Posted May 9, 2007 Author Share Posted May 9, 2007 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; } else{ echo "<b>No image was uploaded.</b>"; } .. It works, I just only want it to work when there is a "uploaded" to upload. I just kind of rigged it up. I really appreciate all of your help! Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249416 Share on other sites More sharing options...
siwelis Posted May 10, 2007 Author Share Posted May 10, 2007 $target_path = "/".images."/".$_POST['cat_id']."/"; $target_path = $_SERVER['DOCUMENT_ROOT'].$target_path . basename( $_FILES['uploaded']['name']); if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; $folder = "website.com".$_POST['cat_id']."/".$_FILES['uploaded']['name']; } else{ //do nothing echo "No Image File was uploaded."; $folder = "0"; } -------------------- SOLVED! It seems two pieces of code may have been conflicting, so I combined the two. Once again I really appreciate your advice! Though this wasn't completed quite as I had planned, maybe it was my subconscious defeating my want for speed which would of created spaghetti code. Thank you!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/50724-solved-how-to-make-php-determine-if-post-variable-is-existant/#findComment-249438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.