-
Posts
827 -
Joined
-
Last visited
-
Days Won
9
Everything posted by fastsol
-
Well that would make sense for the error, where are you getting a value of $valid from. The code you provided doesn't have a $valid defined anywhere before trying to compare it's value in the if(). Maybe it's supposed to be something like $_SESSION['valid'], but it's all dependent on how you defined $valid in the first place and where. Scratch that, I didn't see you were checking isset($valid) which shouldn't cause an error like that. Try removing the space between the isset and the ($valid), it's most likely not reading the isset properly.
-
If you are posting the form like normal, the "name" attribute is ALWAYS required or the script won't interpret the input at all.
-
Well yeah they are undefined cause you aren't posting any of those, at least based on the code you have provided to us. The only form input you have in the code is for the quantity and that's posting as an array which is why it shows ARRAY in your db. You don't have any inputs for name or price in the form being posted.
-
retain selected item from drop down list after php validation
fastsol replied to laxi's topic in PHP Coding Help
Ok seriously, if you would just read and follow the code in the tutorial your would have had this working. Most of the issues were in the foreach(). I also moved the array of countries to the top of the page so you don't have to define it twice, which is stupid. Here is a working code based on your code. I didn't focus on anything else, so there maybe other issues, but the select box now retains is selection. <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php $country_options= array("select","Afghanistan", "Ã…Land Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia And Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, The Democratic Republic Of The", "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island And Mcdonald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic Of", "Iraq", "Ireland", "Isle Of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People'S Republic Of", "Korea, Republic Of", "Kuwait", "Kyrgyzstan", "Lao People'S Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States Of", "Moldova, Republic Of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Helena", "Saint Kitts And Nevis", "Saint Lucia", "Saint Pierre And Miquelon", "Saint Vincent And The Grenadines", "Samoa", "San Marino", "Sao Tome And Principe", "Saudi Arabia", "Senegal", "Serbia And Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia And The South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard And Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province Of China", "Tajikistan", "Tanzania, United Republic Of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad And Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks And Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis And Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe" ); // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = $countryErr = ""; $name = $email = $gender = $comment = $website = ""; $country =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address syntax is valid if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } $country = $_POST['country']; if (!in_array($country, $country_options)) { $country1 = "Please select your country";} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>contact us</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Country: <?php $item = 'India'; echo '<select name="country">'; foreach($country_options as $c) { $sel=''; // Set $sel to empty initially $tag = 'selected="selected"'; if(isset($_POST['country']) && $_POST['country'] == $c) // Here we check if the form has been posted so an error isn't thrown and then check it's value against $c { $sel = $tag; } elseif(!isset($_POST['country']) && $item == $c) // So that the $item doesn't override the posted value we need to check to make sure the form has NOT been submitted also in the { $sel = $tag; } echo '<option value="'.$c.'" '.$sel.'>'.$c.'</option>'; } echo '</select>'; ?> <span class="error">*<?php echo (isset($country1)) ? $country1 : '';?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html> -
retain selected item from drop down list after php validation
fastsol replied to laxi's topic in PHP Coding Help
I didn't go through the whole code but the main issue is that you forgot to put the $sel in the <option> tag like the tutorial says. Needs to be this echo '<option value="'.$c.'" '.$sel.'>'.$c.'</option>'; -
Do this and it will tell you why the query failed. mysql_query($sql_insert) or die(mysql_error());
-
Those line numbers don't really match up to the codes you have provided. Is the form and the validation on the same page? Eitehr way, you need to wrap the validation code in an if(isset($_POST['submit'])) // possibly $_POST['Submit'] depending on if you changed it like I said previously. { // Validation code here. } That will keep the errors from showing at least until the form is submitted. Here is a tutorial on a much better way to validate a form and the logic behind it. http://amecms.com/article/How-to-validate-a-form-the-right-way
-
Why not working in IE or on MAC (FF or Safari)?
fastsol replied to n1concepts's topic in Javascript Help
Well I don't think it totally your code that is making this not work. I just tried the W3's example page they have and it doesn't work for me on WIndows 7 w/Firefox 30. The one thing I noticed between your code and theirs though is they don't have a ; after the function call in the unload block. And all examples I find show the name to be onunload not onUnload, not sure if that will make a difference here as I am not super at js. -
retain selected item from drop down list after php validation
fastsol replied to laxi's topic in PHP Coding Help
I have a tutorial on this very thing http://amecms.com/article/Retaining-Drop-down-Selection-After-Form-Submit -
Works fine for me when I test on my server. Maybe provide the rest of your css, there could be something overriding it in a different css rule. The best thing to do when a styling issue happens and you need to see what the browser is actually applying to the div, use firefox firebug or chromes developer tools. Either can be opened via the F12 key on your keyboard. Just select the element in question and the tool will show you a hierarchy list of the styles being applied and what part of each style is applied or overriden.
-
Well there are lots of things wrong with this script but to help with your issue at hand, you need to put `backticks` (it's the key next to the 1 on your keyboard) around the table names and table columns in the query. The word "order" is a mysql reserved keyword and is making the query think something else besides the table names. So like this $sql_insert = "INSERT INTO `order` (`name`, `quantity`, `price`) values('$name', '$quantity', '$price')"; In all honesty you may need to remove the backticks around the column names inside the () and just have the column names only. I haven't used that particular syntax for a query string in quite a while.
-
Can we get a link to the page in question?
-
Put this just after your $message = $_REQUEST['message']; $message = "Name: ".$name."\nPhone: ".$phone."\nMessage: ".$message;
-
Most efficient way to set php variable through a link
fastsol replied to Aizen06's topic in PHP Coding Help
So you're trying to retain their selection while they visit all other pages? Just put their selection in a $_SESSION var and echo it from there. If you're trying to do something else, you'll need to explain a bit better cause that didn't make much sense. -
Well after seeing so many forum posts about this subject and the difficulties that people seem to have with it, I decided to build a Pagination Page Generator. It will take your specs and generate code that is ready to use. You can copy and modify the code to your needs to make it fit your design. http://amecms.com/article/Pagination-Page-Generator I just posted this a little bit ago, so let me know if you come across any real issues or suggestions. I try to dummy proof anything I build and make it logical to use but sometimes things are missed.
-
Include code works on one page but not another
fastsol replied to eGate-Network's topic in PHP Coding Help
Another thing, your html is absolutely horrible. You need to get away from using tables for layout, it hasn't been good to do that for over 10 years now. Use divs and css. Also you have dual <title> tags and they aren't even inside <html> or <head> tags. You have dual <head> tags too and lots of html before you open the <body> which is where ALL your html markup should be inside. So you really need to fix all that before moving forward or you're asking more problems when you try to put things where you want and wonder why they aren't working n the browser. -
Include code works on one page but not another
fastsol replied to eGate-Network's topic in PHP Coding Help
You do need somthing similar to the / like mensioned above, but with a slight difference cause you're dealing with server side rather than client side for this particular issue. Put this piece of code towards the top of your main include so that it can be used on everypage. define("ROOT", $_SERVER['DOCUMENT_ROOT'].'/'); Then for your includes you woudl do something like this include(ROOT.'yourpage.php'); That will tell php to find the included page starting from the domain root rather than the root of "sections" -
Ok the problem is what I kind of originally thought, it's cause you are sending the ajax request to the same page you're already on. The reponse is the entire page code not just the 123 that you are expecting. You should always send a ajax request to a separate page that only does the request and nothing else. Also you have a 404 error for one of your fonts. NetworkError: 404 Not Found - http://wytraining.net/css/fonts/Roboto-Thin.woff
-
In a word, NO, it's not secure at all. There seems to be a lot of debate about how to secure file uploads from a client. The important steps to help ensure it's safe to upload and actually use, generally require you to have full access to the server file system and are able to store files outside the root of the website. That tends to be difficult cause most paid hosting places don't allow you such access. So in that case all you can really do is the basic stuff and hope for the best. Here is a good tutorial on the subject https://www.youtube.com/watch?v=PRCobMXhnyw . Basically your code is easily bypassed and should not be used on a live site.
-
Well I have never actually used the base64 method, but from all the searching I can't find anything that says how to use it in a sprite type situation. My best guess is that you would define the placement of the image just like you would using a normal css sprite. You don't actually need to decode it and why would you, it's encoded for a reason.
-
Sorry I misspelled the function, honestly you should know that It's strtotime()
- 9 replies
-
- php
- validation
-
(and 1 more)
Tagged with:
-
Assuming your date is being posted in a format like 2013-12-31 you could use this. if( $subBirthday > date("Y-m-d", strototime("-18 years", date()))){ $form->setError($field, "* You are too young!"); }
- 9 replies
-
- 1
-
- php
- validation
-
(and 1 more)
Tagged with:
-
This is not what you think it is for the date() value. $date = date('yyyy-mm-dd'); You want this instead $date = date('Y-m-d'); Your way would have produced a date string like this 1999199919991999-0101-3131
- 9 replies
-
- php
- validation
-
(and 1 more)
Tagged with: