PHP - Form Input Null And Zero
Hello again. I need help for a PHP project I'm working on for school.
I need it to do the following: 1) When nothing is entered, it will echo "Please enter a number." 2) When "0" is entered, it will echo "Please enter a number that is not zero." My code is as follows... <form action="hwpositive.php" method="post"> Enter number <input type="text" name="number"/><br /> </form> <?php $input = $_POST['number']; // if number entered is less than 0 if ($input<0) { echo "Enter a positive number."; } // if number entered is greated than 1000 elseif ($input>1000) { echo "Enter a number less than 1000."; } // if number entered is not a number (ie, a letter, a character) elseif (!is_numeric($input)) { echo "<br><img src=\"squidward.jpg\"><br><br>Enter a valid number. "; } // if number entered is between 1-999 elseif (($input>0) && ($input<1000)) { echo "hello world " . $i . "<br />"; } // if number entered is zero elseif ($input===0) { echo "Please enter a number that is not zero."; } // if no number is entered elseif ($input=null) { echo "Please enter a number."; } else { echo "Please enter a number."; } ?> However, it's not working. What am I doing wrong? Everytime I enter this page, it should show me "Please enter a number" because I haven't entered anything yet, but it doesn't. It's showing me the image right away. I don't understand... Help me, please! Thank you so much in advance. I appreciate the help. Similar TutorialsI have got another of those problems that should be easy to solve but I cannot get my head round it! I have a form to enter data into a table and one of the fields can be left blank. However, I'd data is entered in the field it can be a Zero. This is leaving me a problem as I cannot find a way to get the script to insert NULL if the field is blank but actually put the Zero in if that is what is entered. I have tried several permutations of nested if's using empty or isset, but whatever I try, the same result is inserted in both scenarios. The arguments I need to pass are...... If field is empty INSERT null If field is 0 INSERT 0 If field is not empty and not 0 INSERT field Thanks in advance for any suggestions. Steve I have one field which is set up as a Text field in my database. What I'm wanting is if the field is blank in the form to just leave the field alone in the database. I need it to be NULL. OR...is there a way to query a database to recognize a field is blank? I am trying to update the database with isset to set the value of the variable to either null or the value entered by the user. Currently, if no value has been entered null is being set as a string causing the date field to populate with zeros. How do I code it so that it populates or sets the value as null and not as string null?
Here's my code: (yes I know sql injections it's still in development )
<?php Hello, I'm trying to take the value from an HTML form and insert it into a database on a button click. It inserts a null value into the database. The script is called submitColumnDetails.php. This is where I create the text field that I want to take the information from. This is in a separate file. Code: [Select] echo <<<END <form action = "submitColumnDetails.php" method = "POST"> <input type = "text" name = "columnField"/> </form> END; This is the submitColumnDetails.php file Code: [Select] <?php //Submit Column Data //-----------------------------------------------------// //Connect to localhost server $connector = mysql_connect("localhost", "root", "root"); if(!$connector){ //If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } //-----------------------------------------------------// mysql_select_db("colin_db", $connector); $newValue = $_POST["columnField"]; //Data from column field. THIS IS WHAT RETURNS NULL $newColumnQuery = "INSERT INTO `colin_db`.`allColumnFields` (`DATA`) VALUES ('$newValue')"; mysql_query($newColumnQuery); //Query to add form to main table $newColumnIntoMainTableQuery = "ALTER TABLE colin_table ADD ('$newValue' varchar(50))"; mysql_query($newColumnIntoMainTableQuery); //Query to add column to main table mysql_close($connector); //Close database connection echo "<script type = 'text/javascript'> window.location = 'index.php'</script>"; //Go back to original page ?> Even when I print out the $newValue, it does not print anything. What am I doing incorrectly? I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> Hello friends i need to make the following idea Code: [Select] <form method="post"> Enter ID : <input type="text" name="id" /> <input type="submit" value="Submit" /> </form> and the input id should goes to php code on same page as $id $ORGtext= file_get_contents('NewsID=$id'); how to write it correct thanks Whit my code it only appear a list of 1 or 0 and the id but I don't know how to get to show only the id Like so: submit 0 60/ 0 59/ 0 58/ 0 57/ 0 56/ 0 45/ 0 38/ 1 37/ on my first page: Code: [Select] <table border="2"> <tr> <th>Id</th> <th>User</th> <th>Comment</th> <th>Yes</th> <th>No</th> </tr> <form method="post" action="admincommentdelete.php" id="formc"> <?php $vv = array(); $st = Comment::test($result['article']->id,0,999); $vv['comment'] = $st['comment']; $i = 0; foreach($vv['comment'] as $p) { $i++; echo "<tr>"; echo "<td>".$p->id."</td>"; echo "<td>".$p->usern."</td>"; echo "<td>".$p->com."</td>"; echo "<td><input name=$i type=radio value='1'/></td>"; echo "<td><input name=$i type=radio value='0'/></td>"; echo "<input type=hidden name=h".$i." value=$p->id/>"; echo "</tr>"; } ?> <input type="submit" value="submit" name="submit"> </form> </table> second: Code: [Select] <?php $id = array(); if(isset($_POST['submit'])) { $data = array(); $data = $_POST; foreach($data as $key) { echo $key."</br>"; } } ?> Hi, everyone. I need help with a PHP project on which I'm currently working. I need to create a form which does the following: 1) When you insert a negative number, it echoes: "Please insert a positive number." 2) When you insert a number greater than 1000, it echoes: "Please insert a number less than 1000." 3) When you insert anything else that's not a number (ie: a letter), it echoes: "Please insert a valid number." 4) If it doesn't do any of the above, it'll take the number that you entered and loop "Hello World" as many times as that number. The code that I have so far looks something like below. (I had to type it from the top of my head.) <?php <form action="hwpositive.php" method="post"> Enter number: <input type="text" name="number" /> </form> $input = $_POST["number"]; if ($input<0) { echo "Please insert a positive number."; } else if ($input>1000) { echo "Please insert a number less than 1000."; } else if ($input!=is_numeric) { echo "Please insert a valid number."; } else { for {$i; $i<=$_POST["number"]; $i++;} } ?> I can get this code to do the first three tasks listed above, but not the last. I'm a high school Programming 12 student, and this is my first year of learning PHP coding. Please help me out. Would it be better to use the case-switch option? I'm not too familiar on how to use it. Thank you in advance! I appreciate your help greatly. Hey Everyone, My website asks for an email address when one registers but I want to put a limit it on it (like to register you gotta have an email address from a specific domain). How can I edit the form input to do this? Any help will be greatly appreciated, thanks -STG I have a form:
<input id="house" name="element_1" class="element radio" type="radio" value="Daniel" />
<input id="car" name="element_2" class="element radio" type="radio" value="Joe" />
How can I give to "element_1" multiple value instead of only one?
Welcome <?php echo $_GET["element_1"]; ?><br> ==== Welcome Daniel
element_1 = element_12 = element_13
WHERE
element_1 = Daniel
element_12 = car
element_13 = key
Welcome <?php echo $_GET["element_12"]; ?><br> ==== Welcome car
I need to create a structure for a 10 different values. I heard that will be easy to use array or object, I don t really now how to structure it.
Hello Codingforums, yet again I desire some help to my coding, this time regarding a paypal button. I have a number of Forms which I want to control the input, for example prevent people from using numbers or ensure that people use specific characters. For example "Your password must contain a capital letter and at least one number". Does anyone know what code I should use to do this. I want to redirect my visitors to a certain page after validating their form input to be correct. I have 3 codes which are named code1, code2 and code 3. these are just 6 digit numbers. After a user has filled out the correct 3 codes I want to forward them to specific page but as of now I get no errors but the page that opens up is my handle_form.php which is the file that is only supposed to be validating the inputs. Here's is the code to the form: <form action="handle_form.php" method="post"> <div class="class6"> <b> <table border="1" width="500" height="60" bgcolor="#898989" bordercolor="black"> <tr> <td align="center" width="150"> <a href="/step1.php" target="_blank">Link 1</a> </td> <td align="center" width="150"> Code 1 </td> <td width="200" align="center"> <input type="text" name="code1" size="6"/> </td> </tr> <tr> <td align="center" width="150"> <a href="/step2.php" target="_blank">Link 2</a> </td> <td align="center" width="150"> Code 2 </td> <td width="200" align="center"> <input type="text" name="code2" size="6"/> </td> </tr> <tr> <td align="center" width="150"> <a href="/step3.php" target="_blank">Link 3</a> </td> <td align="center" width="150"> Code 3 </td> <td width="200" align="center"> <input type="text" name="code3" size="6"/> </td> </tr> </table></b><br> <input type="submit" name="submit" value="Take me to the Download Page"/> </div> </form> Now here is the code within the handle_form.php <?php if (isset($_POST['submitted'])) { $realcode1 = 723598; $realcode2 = 193598; $realcode3 = 887362; if (!empty($_POST['code1'])) { $code1 = escape_data (htmlspecialcharacters($_POST['code1'])); } else { echo '<p><font color="red"> You forgot to enter code1.</font></p>'; $code1 = FALSE; } if (!empty($_POST['code2'])) { $code2 = escape_data (htmlspecialcharacters($_POST['code2'])); } else { echo '<p><font color="red"> You forgot to enter code2.</font></p>'; $code2 = FALSE; } if (!empty($_POST['code3'])) { $code3 = escape_data (htmlspecialcharacters($_POST['code3'])); } else { echo '<p><font color="red"> You forgot to enter code1.</font></p>'; $code3 = FALSE; } if ($code1 = $realcode1 && $code2 = $realcode2 && $code3 = $realcode3) { $url .= '/software/Express_Paste.zip'; header('Location: $url'); } else { echo "You haven't entered the correct codes."; } } exit(); ?> When i submit the form using the correct data my handle_form.php page opens??? Where am I going wrong? Hi, I have a page with a long list of names (c1000) each with an id. On that page I would like to have a form into which i put the id number, when the form is submitted it will take me to the anchor point for that id. The question I have is, how, when i press submit and reload the page, how can I then have that form input as a anchor in the url that will then take me to the place I want to go on the list when the page loads. I can do it manually no problem by adding the hash tag and id to the url myselft it takes me there but It's a pain to do this every time. I would like to use a form. Is this possible? any help appreciated. Thanks Hello everyone, I want my input to stay after I have clicked submit so that if the input is wrong, a message is presented and the input stays so they don't have to write everything again. Is this the way to do it?: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head xmlns='http://www.w3.org/1999/xhtml'> <title>registration</title> <link rel="stylesheet" type="text/css" href="opmaak.css" /> </head> <body> <?php function __autoload($class){ require('classes/' . strtolower($class) . '.class.php'); } if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if(isset($_POST['firstname'])){ $firstname = $_POST['firstname']; } if(isset($_POST['lastname'])){ $lastname = $_POST['lastname']; } if(isset($_POST['address'])){ $address = $_POST['address']; } if(isset($_POST['postcode'])){ $postcode = $_POST['postcode']; } if(isset($_POST['city'])){ $city = $_POST['city']; } if(isset($_POST['username'])){ $username = $_POST['username']; } if(isset($_POST['password'])){ $password = $_POST['password']; } if(isset($_POST['email'])){ $email = $_POST['email']; } if(isset($_POST['kvk'])){ $kvk = $_POST['kvk']; } try{ $user = new User; $user->createUser($firstname, $lastname, $address, $postcode, $city, $username, $password, $email, $kvk); } catch(Mysql_Exception $error){ echo $error->getError(); } echo "<html>"; echo "<head xmlns='http://www.w3.org/1999/xhtml'>"; echo "<title>registration</title>"; echo "<link rel='stylesheet' type='text/css' href='opmaak.css' />"; echo "</head>"; echo "<body>"; echo "<div id='registration_container'>"; echo "<form class='registration' method='post' action='registration.php'>"; echo "<div id='registration_left'>"; echo "<label class='user'>Voornaam: *</label> <input class='registration' type='text' size='10' maxlength='40' name='firstname' value='".$firstname."'/>"; echo "<label class='user'>Achternaam: *</label> <input class='registration' type='text' size='10' maxlength='40' name='lastname' value='".$lastname."'/>"; echo "<label class='user'>Adres: *</label> <input class='registration' type='text' size='10' maxlength='40' name='address' value='".$address."'/>"; echo "<label class='user_postcode_plaats'>Postcode / Plaats: *</label> <input class='registration_postcode' type='text' size='10' maxlength='40' name='postcode' value='".$postcode."'/>"; echo " "; echo "<input class='registration_city' type='text' size='10' maxlength='40' name='city' value='".$city."'/>"; echo "</div>"; echo "<div id='registration_right'>"; echo "<label class='user'>Gebruikersnaam: *</label> <span class='inputeisen'>4 of meer</span><input class='registration' type='text' size='10' maxlength='40' name='username' value='".$username."'/>"; echo "<label class='user'>Wachtwoord: *</label> <span class='inputeisen'>6 of meer</span><input class='registration' type='text' size='10' maxlength='40' name='password' value='".$password."'/>"; echo "<label class='user'>E-mail: *</label> <input class='registration' type='text' size='10' maxlength='40' name='email' value='".$email."'/>"; echo "<label class='user'>KvK nummer:</label> <input class='registration' type='text' size='10' maxlength='40' name='kvk' value='".$kvk."'/>"; echo "</div>"; echo "<div id='registration_bottom'>"; echo "<p>Het KvK nummer is alleen verplicht indien u wilt adverteren met uw bedrijf.<br/> U kunt dit ook later toevoegen.</p>"; echo "<input class='submit_registration_user' type='submit' value='Registreren'/>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</body>"; echo "</html>"; }else{ ?> <div id="registration_container"> <form class="registration" method="post" action="registration.php"> <div id="registration_left"> <label class="user">Voornaam: *</label> <input class="registration" type="text" size="10" maxlength="40" name="firstname"/> <label class="user">Achternaam: *</label> <input class="registration" type="text" size="10" maxlength="40" name="lastname"/> <label class="user">Adres: *</label> <input class="registration" type="text" size="10" maxlength="40" name="address"/> <label class="user_postcode_plaats">Postcode / Plaats: *</label> <input class="registration_postcode" type="text" size="10" maxlength="40" name="postcode"/> <input class="registration_city" type="text" size="10" maxlength="40" name="city"/> </div> <div id="registration_right"> <label class="user">Gebruikersnaam: *</label><span class="inputeisen">4 of meer</span> <input class="registration" type="text" size="10" maxlength="40" name="username"/> <label class="user">Wachtwoord: *</label><span class="inputeisen">6 of meer</span> <input class="registration" type="text" size="10" maxlength="40" name="password"/> <label class="user">E-mail: *</label> <input class="registration" type="text" size="10" maxlength="40" name="email"/> <label class="user">KvK nummer:</label> <input class="registration" type="text" size="10" maxlength="40" name="kvk"/> </div> <div id="registration_bottom"> <p>Het KvK nummer is alleen verplicht indien u wilt adverteren met uw bedrijf.<br/> U kunt dit ook later toevoegen.</p> <input class="submit_registration_user" type="submit" value="Registreren"/> </div> </form> </div> </body> </html> <?php } ?> Hi guys, I want to create a piece of script that takes my users to a website based of there input in a form. Basiaclly what they input into a text field will become part of the URL used in action at the top of the form. So it would look like this: http://www."their input from form".mydomain.com does anyone have any suggestions on how to accomplish this? Thanks hello phpfreaks! first off i have zero knowledge of php. it's just that i need this in my project. what i would want to do is all the values input in the form "tracker.html" when the SUBMIT button is clicked will be saved in my desktop folder named "LOGS". the saved values will be save as an html file name "logs.html" then it can be viewed also by clicking on the PREVIEW button in the tracker. and also if can be done, each will be save separately according to it's CATEGORY. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <div> <label for="name3">Name: </label> <input type="text" name="name" id="name3" /> </div> <div> <label for="phone">Phone Number</label> <input type="text" name="phone" id="phone" /> </div> <div> <label for="ticket">Ticket Number</label> <input type="text" name="ticket" id="ticket" /> </div> <div> <label for="issue">Issue:</label> <select name="issue" id="issue"> <option value="no sync">no sync</option> <option value="no route">no route</option> <option value="resched">resched</option> <option value="cancel">cancel</option> </select> </div> <div> <label for="category">Category:</label> <select name="category" id="category"> <option value="level 1">level 1</option> <option value="level 2">level 2</option> <option value="level 3">level 3</option> </select> </div> <div><input type="file" name="upload" id="upload" /> </div> <div> <label for="summary">Summary:</label> <textarea name="summary" id="summary" cols="45" rows="5"></textarea> </div> <div> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="submit" name="preview" id="preview" value="Review" /> <input type="submit" name="clear" id="clear" value="Clear" /> </div> </form> </body> </html> I have a textarea feild in my form where the user can type in several keywords such as Textarea Box Below Cars Trains Buses I have a database with the meanings of the words entered and want to be able to get the three definitions from the database on for submission. In a normal input box where i only type one word i can grab no problem like so $word = $_POST['word']; $sql = "SELECT meaning FROM table WHERE word='$word'"; Though i am trying to get multiple values from the same textarea box So if a user types in 3 words the query would query the database on thoses three words, the problem is i dont know how to get the diffrent words from the form for example $first = $_POST['word']; which would be the first word $sec = $_POST['word']; which would be the second word etc. Any help here would be great thanks. im wanting to change the sql in my query based on if a field is empty or not. if the field is empty then i dont want it to post anything, but if its not empty then it can post the content. heres what i have so far but it does post the content even if the field is empty. (!empty($password)) ? $pass_sql = "u_password = '$password'," : $pass_sql = null; $link->query("UPDATE ".TBL_PREFIX."users SET $pass_sql u_allow_user_pm = '".$_POST['allow_user_pm']."' WHERE u_username = '".$_POST['user_name']."'") or die(print_link_error()); how can i stop it from updating if the field is empty? |