Search the Community
Showing results for tags 'help'.
-
Greetings <? mysql_connect("xxx","xxx","xxx"); mysql_select_db("name"); if (!isset($_POST['submit'])) { print "<h1>"; print "Welcome"; print "</h1>"; print "<br><br><br>"; echo "<center>"; print "<form action=\"\" method=\"POST\">"; print "<input name=\"dgt\" id=\"Join\" style=\"width:400px\" type=\"text\"> "; print "<input name=\"submit\" value=\"Join\" type=\"submit\">"; print "</form>"; } else { $name = $_POST['dgt']; if(strlen($name) != "10") { print "Name is incorrect."; } else { $query = mysql_query("SELECT * FROM contacts WHERE name ='$name';"); if(mysql_num_rows($query) > 0){ $row = mysql_fetch_assoc($query); print "True"; print "$row[no]"; }else{ print "False"; } } } ?> This script is vulnerable to SQLi I need help in fixing the vulnerability please.
- 14 replies
-
- sql
- sqlinjection
-
(and 3 more)
Tagged with:
-
So this is my 2nd PHP class ever. And this right here is part of my final. I'm sure you all know what the "shuffle" function does. What I thought I could make it do was randomize a bunch of echoes I have. Is that possible? Any help would be greatly appreciated. KCCO! Here's the code I need tweaked: <html> <head> <title>Characters</title> <link rel="stylesheet" href="assets/css/bootstrap.css" media="screen"> <link rel="stylesheet" href="assets/css/bootstrap-responsive.css" media="screen"> <link rel="stylesheet" href="assets/css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="assets/css/style.css" media="screen"> </head> <body> <div class="navbar"> <div class="navbar-inner"> <a class="brand" href="#"></a> <ul class="nav"> <li class="active"><a href="Characters.php">Previous Clients</a></li> <li><a href="workForSupers.php">Work for Supers</a></li> </ul> </div> </div><!-- END of navbar--> <div align="center"> <h1>Supers we've helped locate</h1> <? date_default_timezone_set("America/Los_Angeles"); # set default timezone $imageDir = "images/"; # Comics is a PARENT class - Emily, Jenny, and so forth all are CHILDREN of Comics, meaning: They inherit the properties and methods included inside Comics. # For example: echo $joker->comiccharacters; will print out the $comiccharacters stored in Comics class Comics { const IMAGEDIR = "images/"; public $comiccharacters = "Comics"; } class Spiderman extends Comics { public $name = "Spiderman"; public $location = "New York City"; public $superpower = "his spider-sense, augmented speed and strength and his web shooters."; public $sex = "male"; public $published = "1963-03-01."; public $hero = true; public $asseskicked = 37; public $personscaught = [12,16,19,29,51]; public $powerlevel= '++++++'; public $email = "SpiderMan4Reals@gmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "spiderman.jpg"; } } $spiderman = new Spiderman(); class Magneto extends Comics { public $name = "Magneto"; public $location = "New York City."; public $superpower = "power of magnetism."; public $sex = "male"; public $published = "1963-10-15."; public $hero = false; public $asseskicked = 52; public $personscaught = [21,11,21,43,31]; public $powerlevel= '+++++++'; public $email = "ElMagneto@yahoo.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "magneto.jpg"; } } $magneto = new Magneto(); class Nightwing extends Comics { public $name = "Nightwing"; public $location = "Gotham City"; public $superpower = "is his peak physical conditioning, gadgets, and detective skills."; public $sex = "male"; public $published = "1985-01-06"; public $hero = true; public $asseskicked = 76; public $personscaught = [32,41,53,48,63]; public $powerlevel= '++++++'; public $email = "NightwingIsAwesome@hotmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "nightwing.jpg"; } } $nightwing = new Nightwing(); class GreenArrow extends Comics { public $name = "Green Arrow"; public $location = "Starling City"; public $superpower = "is his peak physical conditioning and accuracy with his gadgets."; public $sex = "male"; public $published = "1941-11-19"; public $hero = true; public $asseskicked = 62; public $personscaught = [17,17,29,31,49]; public $powerlevel= '++++++'; public $email = "ImTheGreenArrow@gmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "greenarrow.jpg"; } } $greenArrow = new GreenArrow(); class TheJoker extends Comics { public $name = "The Joker"; public $location = "Gotham City"; public $superpower = "being completely insane and psychotic."; public $sex = "male"; public $published = "1940-04-11"; public $hero = false; public $asseskicked = 112; public $personscaught = [61,79,103,94,52]; public $powerlevel= "++++++++"; public $email = "KillingForAJoke@gmail.com"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "joker.jpg"; } } $thejoker = new TheJoker(); # Create an array containing all the members classes $members = array($spiderman, $magneto, $nightwing, $greenArrow, $thejoker); # Calculate Ages - this cycles through all of the classes, and calculates the age for each band member, and places it in a property named "$age" foreach($members as $obj) { $obj->age = calculateAge($obj->published); } # Display our Jump Menu echo "<form name=\"jump\"> <p align=\"center\"> <select name=\"menu\" onchange='window.location.href=this.options[this.selectedIndex].value'> <option selected>All Characters</option> <option value=\"?sort=name\">Sort by Name</option> <option value=\"?sort=ageLoToHi\">Sort by Age (youngest to oldest)</option> <option value=\"?sort=ageHiToLo\">Sort by Age (oldest to youngest)</option> </select></p> </form>"; # Access the sort value from the url: blah.com/?sort=blam $sort = ''; if (isset($_GET['sort'])) { $sort = $_GET['sort']; } # Let's introduce all our members echo "<h2>Heroes and Villains Alike</h2>"; for ($i=0; $i < count($members); $i++) { switch ( $sort ) { # sort=name -- sorts alphabetically by 'name' in the member array case "name" : usort($members, 'sortByName_ascend'); displayProfile($members[$i]); break; case "nameRev" : usort($members, 'sortByName_descend'); displayProfile($members[$i]); break; # sort=ageLoToHi -- sorts alphabetically by 'age' ascending case "ageLoToHi" : usort($members, 'sortClassesByAgeLoHi'); displayProfile($members[$i]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "ageHiToLo" : usort($members, 'sortClassesByAge_HiLo'); displayProfile($members[$i]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "asseskicked" : uksort($members, 'sortAsseskicked'); displayProfile($members[$i]); break; # default -- spit out all band members according to their order in the array default : displayProfile($members[$i]); break; } } # This is a custom sorting function that works with usort(). # If you provide usort() with either an array or a set of objects, # it goes through all the items and compares them, and puts them in order # according to the rules below. function sortClassesByAgeLoHi($a, $b) { if ( $a->published == $b->published ) { #return 0; # this makes equivalent aged folks disappear return 1; } elseif ( $a->published > $b->published ) { return -1; } else { return 1; } } function sortClassesByAge_HiLo($a, $b) { return sortClassesByAgeLoHi($b, $a); # just reverse the arguments } function sortByName_ascend($a, $b) { if ( $a->name == $b->name ) { #return 0; # this makes equivalent aged folks disappear return 1; } elseif ( $a->name > $b->name ) { return 1; } else { return -1; } } function sortByName_descend($a, $b) { return sortByName_ascend($b, $a); # just reverse the arguments } # FUNCTIONS - Store all functions down here - I could also store them in another file function displayProfile($memberClass) { echo "<div class='memberProfile'><p>"; # spit out the image of our character # <img src="images/spiderman.jpg" /><br /> echo "<img src=\"".$memberClass->imagePath."\" width=200px /><br />"; #should make it so that when you refresh the page, it randomizes the order of the elements in the array shuffle($memberProfile); THE FOLLOWING IS SPECIFICALLY WHAT I WANT TO RANDOMIZE # spit out our caption echo "This is ".$memberClass->name.".<br>"; //counts the "+" for the power level echo "He has a power level of ".strlen($memberClass->powerlevel)." <br> "; echo "He resides in ".$memberClass->location.". <br>"; echo "He was first published in ".displayBirthdate($memberClass->published).".<br>"; echo "Making him ".calculateAge($memberClass->published)." years old! <br>"; //wraps the string after the specified # of characters echo "His superpower is ".wordwrap($memberClass->superpower,35,"<br>\n")."<br>"; echo "And in that time he's kicked the asses of ".$memberClass->asseskicked." people! <br>"; //finds the average & wraps the string after the specified # of characters echo "They normally capture their respective enemy ".average($memberClass->personscaught)." times a year.<br>"; echo "You can reach them at <a href=\"#\"> ".$memberClass->email.".</a>. <br> </p></div> "; } function displayBirthdate($bandmateBirthdate) { # January 1, 1984 $birthDateFormatted = date('F j, Y', strtotime($bandmateBirthdate)); return $birthDateFormatted; } function calculateAge($bandmateBirthdate) { #$currentTime = time(); # as a Unix timestamp list($year, $month, $day) = explode("-",$bandmateBirthdate); $elapsedYears = date('Y') - $year; $age = $elapsedYears; # calculates number of years elapsed # If current date < birthdate (i.e. Oct01 < Dec01), then subtract 1 year if ( date('n') < $month || ( date('n') == $month && date('j') < $day ) ) { $age = $age - 1; } return $age; } //example how to get the average in an array function average($average) { if (!is_array($average)) return false; return array_sum($average)/count($average); } ?> </body> <script type="text/javascript" src="js/bootstrap.js"></script> </html> Characters.php
-
hi i was just wondering how i would go about keeping user input in a field if an error occurs e.g. if i accidentally type in a special character into my form it will display a message saying : is not aloud or something like that but once this is shown all user input is lost so they would have to type it in again, ive tryed going online and i cant seem to find anything that works as it comes up with undifiened index <input type="text" name="clientname" value="<?php echo htmlspecialchars($_post['clientname']);?> > aswell as this im really in need of a message that says success, ive got no clue how i would go about doing it. what i need is a message that says 'form submitted'once you press submit and when no errors occur. greatly apreciate anyone that can help
-
Hey guys. I am Looking for some help here, dunno where else to ask, but im sure someone will know where my problem is. I got this wordpress theme and cant work out whats wrong with the display image. on front end i can set the image as main image heres the php of it <?php ini_set( 'display_errors', 0 ); require( '../../../../wp-load.php' ); if (!is_user_logged_in()) { die(); } $attachmentid = (int)$_GET['id']; if ($attachmentid == 0) { die(); } global $current_user; get_currentuserinfo(); $userid = $current_user->ID; $post = get_post($attachmentid); $photo = $post->post_title; $post_parent = get_post($post->post_parent); $upload_folder = get_post_meta($post_parent->ID, "upload_folder", true); $author_id = $post_parent->post_author; //if the current user is the one who added the post if ($author_id == $userid || current_user_can('level_10')) { update_post_meta($post->post_parent, "main_image_id", $upload_folder."/".$photo); echo _d('Default image has been set',779)."<br />"._d('Refresh the page to see it change',780); } ?> and im not quite sure whats happening here, im a total ROOKIE at php as a matter of fact so yeah... the second part... the loop where its supposed call for the image, i cant really find it in all those files... maybe if somebody explains to me what happens in the last 4 liines i might figure out whats wrong?
-
Hello I was wondering how could i autofill a form based on a drop down list using raw php and mysql . I know that the connection to database would have to be established but what next ? Any Pointers would be helpful Also check the attached photo to maybe understand more than I'm explaining
-
Hey, I have created a contact us form which works nicely with my site, however I have some backup PHP validation code, which all works apart from the last name section, how can I set it up to it checks to see if there is a first name and a last, maybe even another name? This is what I have so far and it only works if you put in a first name and nothing else: $string_exp = "/^[A-Za-z.'-]+\$/"; if(!preg_match($string_exp, $name)) { $error_message .= 'The Name you entered does not appear to be valid.<br/>'; } Thank you
- 2 replies
-
- string
- form validation
-
(and 2 more)
Tagged with:
-
im trying to get my trim function to work is this right, im pretty new to this so sorry if its a stupid question. <tr> <td>Name:</td><td> <input type="text" name="name"><?trim($str);?></td> <td><span class="error">* <?php if (isset($errors['name'])) echo $errors['name']; ?></span></td> </tr> and im getting an error like this Undefined variable: str
-
hi i was just wondering how i would stop spaces at the start of a field ive looked all over and i cant find anything. what i need is to stop people from putting spaces at the beginning e.g. an error will occur if i type ' Dave'
-
Hello I got a question , Im trying to add balance after each transaction ,what I tried to do is to echo $account Balance and then use function to deduct the row amount Im really confused and can't figure it out how i would i achieve such thing : The code I've used <td>£ <?php echo number_format ($account['balance'] + $row['amount'], 2); ?></td>
-
hi just wondering how i would go about checking if a companys name is already in use and if it is show a message at the side saying u cant use this name as its already in use, i know how i would do the error message but i got no clue on how to do the check im guessing you use a sql query but i dont really know. this is the format ive been doing my code in. if (empty($_POST["companyname"])) { $errors['companyname'] = "Please Enter Your companyname"; }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['companyname'],$matches)){ // list of invalid characters #echo '<pre>',print_r($matches),'</pre>'; $invalid_characters = implode(",",$matches[0]); $errors['companyname'] = 'Cannot use '.$invalid_characters; } elseif(strlen($_POST['companyname']) > 220) { $errors['companyname'] = 'Company name must be less then 220 characters'; } elseif(strpos($_POST['companyname'], 'The') !== false) { $errors['companyname'] = 'Company Names cant start with The'; } elseif(strpos($_POST['companyname'], 'the') !== false) { $errors['companyname'] = 'Company Names cant start with the'; } elseif(strpos($_POST['companyname'], 'THE') !== false) { $errors['companyname'] = 'Company Names cant start with THE'; } else { $companyname = test_input($_POST["companyname"]); }
-
another beginners question from yours truly but i was just wondering how i would code a character limit on one of my fields iv been around the internet but i cant find what i need cause i usually come up with the same error code each time. if anyone knows what to do that would be great, hears the code iv been using. <?php $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // define variables and set to empty values $companyname = $firstname = $address1 = $address2 = $area = $city = $postcode = $email = $website = $clubphone = $homephone = $mobilephone = $typeofbusiness = $renewaldate = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $errors = array(); if (empty($_POST["companyname"])) { $errors['companyname'] = "Please Enter Your companyname"; } <input type='text' name='keywords' size='60' value='companyname' maxlength='10' /> elseif(strpos($_POST['companyname'], '/') !== false) { $errors['companyname'] = 'Cannot use /'; } elseif(strpos($_POST['companyname'], 'The') !== false) { $errors['companyname'] = 'Company Names cant start with The'; } elseif(strpos($_POST['companyname'], 'the') !== false) { $errors['companyname'] = 'Company Names cant start with the'; } elseif(strpos($_POST['companyname'], 'THE') !== false) { $errors['companyname'] = 'Company Names cant start with THE'; } else { $companyname = test_input($_POST["companyname"]); } and heres the error code ive been getting. ( ! ) Parse error: syntax error, unexpected '<' in C:\wamp\www\AddLeads\addeadstemplate.php on line 29 aswell as this if i remove this symbol i get one to do with the else if statement witch i kinda need. again if anyone has a solution please get back to me soon as
-
Hi again , Im trying to create form which allows the users to edit their data , I've created the form ,added the sql i think is right but its not working and giving me sql erro that the data can't be inserted . this is my code for the form details.php : <?php include '../header.php'; include '../config2.php'; session_start(); $id = $_POST['ID']; ?> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/parsley.js"></script> <script> $(document).ready(function() { // submit data on click and check if valid $('#sendData').click(function(e) { //check if valid with parsley var valid = $('#detailform').parsley ( 'validate' ); if ( valid === false ) { e.preventDefault(); } else { $.post("updateprocess.php", $("#detailform").serialize()); } }); }); </script> <div id="title"> <div class="inner"> <h1>Changing Your Account Details</h1> </div> </div> <div id="content" class="right-sidebar"> <div class="container inner"> <div id="main" role="main"> <div class="container"> <h3>Please Choose Which information Your would like to change</h3> <form data-validate="parsley" method="POST" action="updateprocess.php" id="detailform" > <label>Email Address</label> <input type="text" name="login_email" data-required="true" value="<?php echo $account['login_email']; ?>"/> <label>Change a password</label> <input type="password" name="login_password" data-notblank="true"/> <label>Re-enter new password</label> <input type="password" name="confirm" data-notblank="true"/> <label>First Name</label> <input type="text" name="first_name" data-required="true" value="<?php echo $account['first_name']; ?>" disabled="disabled" /> <label>Last Name</label> <input type="text" name="last_name" data-notblank="true" /> <label>Address line 1</label> <input type="text" name="address_one" data-required="true" value="<?php echo $account['address_one']; ?>"/> <label>Address line 2</label> <input type="text" name="address_two" data-required="true" value="<?php echo $account['address_two']; ?>"/> <label>Town/City</label> <input type="text" name="town_city" data-required="true" value="<?php echo $account['town_city']; ?>" /> <label>County</label> <input type="text" name="county_option" data-required="true" value="<?php echo $account['county_option']; ?>"/> <label>Postcode</label> <input type="text" name="post_code" data-required="true" value="<?php echo $account['post_code']; ?>"/> <label>Phone number</label> <input type="text" name="phone_number" data-required="true" value="<?php echo $account['phone_number']; ?>"/> <p></p> <p></p> <p></p> <p></p> <p></p> <input type="checkbox" class="checkbox" id="agree" name="agree" /> I Agree With Terms & Conditions</p> <td> <input type="submit" name="submit" class="button" value= "Save"/></td> </form> </div> <div class="space"></div> </div> <ul class="sidebar" role="complementary"> <li> <h2>Navigation</h2> <ul class="link-list"> <li><a href="/account/dashboard.php">Dashboard</a></li> <li><a href="/account/transfer.php">Transfer Money</a></li> <li><a href="/account/transactions.php">Transactions</a></li> <li><a href="/account/withdrawal.php">Withdraw Funds</a></li> <li><a href="/account/upload.php">Upload Funds</a></li> <li><a href="/account/details.php">Change My details</a></li> </ul> </li> </ul> </div> </div> <?php include '../footer.php'; ?> this is the update.php script <?php include "config2.php"; $id = $_POST['ID']; $sql="SELECT * FROM users WHERE id='$id'"; $result=mysql_query($sql); $id = $_POST['ID']; $rows=mysql_fetch_array($result); $email = $_POST['login_email']; $pass = md5($_POST['login_password']); $confirm = md5($_POST['confirm']); $fname = $_POST['first_name']; $lname = $_POST['last_name']; $addressone = $_POST['address_one']; $addresstwo = $_POST['address_two']; $towncity = $_POST['town_city']; $countyoption = $_POST['county_option']; $postcode = $_POST['post_code']; $phone = $_POST['phone_number']; $update = 'UPDATE users SET( login_email, login_password, confirm, first_name, last_name, address_one, address_two, town_city, county_option, post_code, phone_number) VALUES("'.$email.'","'.$pass.'","'.$confirm.'","'.$fname.'","'.$lname.'","'.$addressone.'","'.$addresstwo.'","'.$towncity.'","'.$countyoption.'","'.$postcode.'","'.$phone.'")WHERE id="'.$id.'""'; //$insert = 'UPDATE users SET login_email="'.$email.'", login_password="'.$pass.'", confirm="'.$confirm.'", first_name="'.$fname.'", last_name="'.$lname.'", address_one="'.$addressone.'", address_two="'.$addresstwo.'", town_city="'.$towncity.'", county_option="'.$countyoption.'", post_code="'.$postcode.'", phone_number="'.$phone.'" WHERE id="'.$id.'""'; mysql_query($update) or die("Failed Updating Your Data,check SQL"); header( 'Location: ../account/success.php' ) ; ?>
-
hi i want one of my fields to only be a-z and for a message to show saying this if someone types in numbers or special characters, ive tried putting it on the field company name but it dosent work so i was just wondering what you think?? <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // define variables and set to empty values $companyname = $firstname = $address1 = $address2 = $area = $city = $postcode = $email = $website = $clubphone = $homephone = $mobilephone = $typeofbusiness = $renewaldate = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $errors = array(); // a / was found if (empty($_POST["companyname"])) { $errors['companyname'] = "please enter your companys name"; } elseif if ( !preg_match ("/^[a-zA-Z\s]+$/",$companyname)) { $errors[] = "Name must only contain letters!"; else { $companyname = test_input($_POST["companyname"]); } if (empty($_POST["typeofbusiness"])) {$errors['typeofbusiness'] = "please enter your TypeofBusiness";} else {$typeofbusiness = test_input($_POST["typeofbusiness"]);} if (empty($_POST["firstname"])) { $errors['firstname'] = "Please Enter Your First Name"; } else { $firstname = test_input($_POST["firstname"]); } if (empty($_POST["address1"])) {$errors['address1'] = "Please Enter Address 1";} else {$address1 = test_input($_POST["address1"]);} if (empty($_POST["address2"])) {$address2 = test_input($_POST["address2"]);} if (empty($_POST["area"])) {$errors['area'] = "Please enter Area";} else {$area = test_input($_POST["area"]);} if (empty($_POST["city"])) {$errors['city'] = "Please Enter City";} else {$city = test_input($_POST["city"]);} if (empty($_POST["postcode"])) {$errors['postcode'] = "Please enter your PostCode";} else {$postcode = test_input($_POST["postcode"]);} if (empty($_POST["email"])) {$errors['email'] = "Please enter your Email";} else {$email = test_input($_POST["email"]);} if (empty($_POST["website"])) {$errors['website'] = "Please Enter your Website";} else {$Website = test_input($_POST["website"]);} if (empty($_POST["clubphone"])) {$errors['clubphone'] = "Please enter your club number";} else {$clubphone = test_input($_POST["clubphone"]);} if (empty($_POST["homephone"])) {$errors['homephone'] = "Please enter your home number";} else {$homephone = test_input($_POST["homephone"]);} if (empty($_POST["mobilephone"])) {$errors['mobilephone'] = "Please enter your mobile number";} else {$mobilephone = test_input($_POST["mobilephone"]);} if (empty($_POST["renewaldate"])) {$errors['renewaldate'] = "Please enter your mobile number";} else {$renewaldate = test_input($_POST["renewaldate"]);} function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } } ?> <h2>Add Leads</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table border = "0"> <tr> <td>Company Name:</td><td> <input type="text(220)" name="companyname"></td> <td><span class="error">* <?php if (isset($errors['companyname'])) echo $errors['companyname']; ?></span></td> </tr> <tr> <td>Type of Business:</td><td> <input type="text" name="typeofbusiness"></td> <td><span class="error">* <?php if (isset($errors['typeofbusiness'])) echo $errors['typeofbusiness']; ?></span></td> </tr> <tr> <td>First Name:</td><td> <input type="text" name="firstname"></td> <td><span class="error">* <?php if (isset($errors['firstname'])) echo $errors['firstname']; ?></span></td> </tr> <tr> <td>Address 1:</td><td> <input type="text" name="address1"></td> <td><span class="error">* <?php if (isset($errors['address1'])) echo $errors['address1']; ?></span></td> </tr> <tr> <td>Address 2:</td><td><input type="text" name="address2"></td> </tr> <tr> <td>Area:</td> <td><input type="text" name="area"></td> <td><span class="error">* <?php if (isset($errors['area'])) echo $errors['area']; ?></span></td> </tr> <tr> <td>Post Code:</td> <td><input type="text" name="postcode"></td> <td><span class="error">* <?php if (isset($errors['postcode'])) echo $errors['postcode']; ?></span></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city"></td> <td><span class="error">* <?php if (isset($errors['city'])) echo $errors['city']; ?></span></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email"></td> <td><span class="error">* <?php if (isset($errors['email'])) echo $errors['email']; ?></span></td> </tr> <tr> <td>Website:</td> <td><input type="text" name="website"></td> <td><span class="error">* <?php if (isset($errors['website'])) echo $errors['website']; ?></span></td> </tr> <tr> <td>Club phone:</td> <td><input type="integer" name="clubphone"></td> <td><span class="error">* <?php if (isset($errors['clubphone'])) echo $errors['clubphone']; ?></span></td> </tr> <tr> <td>Home phone:</td> <td><input type="integer" name="homephone"></td> <td><span class="error">* <?php if (isset($errors['homephone'])) echo $errors['homephone']; ?></span></td> </tr> <tr> <td>Mobile Phone:</td> <td><input type="integer" name="mobilephone"></td> <td><span class="error">* <?php if (isset($errors['mobilephone'])) echo $errors['mobilephone']; ?></span></td> </tr> <tr> <td>Renewal Date:</td> <td><input type="date" name="renewaldate"></td> <td><span class="error">* <?php if (isset($errors['renewaldate'])) echo $errors['renewaldate']; ?></span></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> <?php if($_SERVER['REQUEST_METHOD'] == "POST" && count($errors) == 0) { // Do it { $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City, PostCode, Email, Website, ClubPhone, HomePhone, MobilePhone, TypeofBusiness, RenewalDate ) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]','$_POST[postcode]','$_POST[email]','$_POST[website]','$_POST[clubphone]','$_POST[homephone]','$_POST[mobilephone]','$_POST[typeofbusiness]','$_POST[renewaldate]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); echo "record added"; } mysqli_close($con); } // end if $errors == 0 } ?> </form> </body> </html>
-
hi ive been researching this all morning but i cant seem to find much, what i want to do is disable special characters and if anybody trys to type one in a message box will appear saying "special characters are not available" or something like that. i know that you cant do message boxes in php so i was wondering how i would do it in javascript/visual basic, i roughly no how to do it in visual basic but i dont know where i would put it in the code. <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // define variables and set to empty values $companyname = $firstname = $address1 = $address2 = $area = $city = $postcode = $email = $website = $clubphone = $homephone = $mobilephone = $typeofbusiness = $renewaldate = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $errors = array(); if (empty($_POST["companyname"])) {$errors['companyname'] = "please enter your companys name";} else {$companyname = test_input($_POST["companyname"]);} if (empty($_POST["typeofbusiness"])) {$errors['typeofbusiness'] = "please enter your TypeofBusiness";} else {$typeofbusiness = test_input($_POST["typeofbusiness"]);} if (empty($_POST["firstname"])) {$errors['firstname'] = "Please Enter Your First Name";} else {$firstname = test_input($_POST["firstname"]);} if (empty($_POST["address1"])) {$errors['address1'] = "Please Enter Address 1";} else {$address1 = test_input($_POST["address1"]);} if (empty($_POST["address2"])) {$address2 = test_input($_POST["address2"]);} if (empty($_POST["area"])) {$errors['area'] = "Please enter Area";} else {$area = test_input($_POST["area"]);} if (empty($_POST["city"])) {$errors['city'] = "Please Enter City";} else {$city = test_input($_POST["city"]);} if (empty($_POST["postcode"])) {$errors['postcode'] = "Please enter your PostCode";} else {$postcode = test_input($_POST["postcode"]);} if (empty($_POST["email"])) {$errors['email'] = "Please enter your Email";} else {$email = test_input($_POST["email"]);} if (empty($_POST["website"])) {$errors['website'] = "Please Enter your Website";} else {$Website = test_input($_POST["website"]);} if (empty($_POST["clubphone"])) {$errors['clubphone'] = "Please enter your club number";} else {$clubphone = test_input($_POST["clubphone"]);} if (empty($_POST["homephone"])) {$errors['homephone'] = "Please enter your home number";} else {$homephone = test_input($_POST["homephone"]);} if (empty($_POST["mobilephone"])) {$errors['mobilephone'] = "Please enter your mobile number";} else {$mobilephone = test_input($_POST["mobilephone"]);} if (empty($_POST["renewaldate"])) {$errors['renewaldate'] = "Please enter your mobile number";} else {$renewaldate = test_input($_POST["renewaldate"]);} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>Add Leads</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table border = "0"> <tr> <td>Company Name:</td><td> <input type="text(220)" name="companyname"></td> <td><span class="error">* <?php if (isset($errors['companyname'])) echo $errors['companyname']; ?></span></td> </tr> <tr> <td>Type of Business:</td><td> <input type="text" name="typeofbusiness"></td> <td><span class="error">* <?php if (isset($errors['typeofbusiness'])) echo $errors['typeofbusiness']; ?></span></td> </tr> <tr> <td>First Name:</td><td> <input type="text" name="firstname"></td> <td><span class="error">* <?php if (isset($errors['firstname'])) echo $errors['firstname']; ?></span></td> </tr> <tr> <td>Address 1:</td><td> <input type="text" name="address1"></td> <td><span class="error">* <?php if (isset($errors['address1'])) echo $errors['address1']; ?></span></td> </tr> <tr> <td>Address 2:</td><td><input type="text" name="address2"></td> </tr> <tr> <td>Area:</td> <td><input type="text" name="area"></td> <td><span class="error">* <?php if (isset($errors['area'])) echo $errors['area']; ?></span></td> </tr> <tr> <td>Post Code:</td> <td><input type="text" name="postcode"></td> <td><span class="error">* <?php if (isset($errors['postcode'])) echo $errors['postcode']; ?></span></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city"></td> <td><span class="error">* <?php if (isset($errors['city'])) echo $errors['city']; ?></span></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email"></td> <td><span class="error">* <?php if (isset($errors['email'])) echo $errors['email']; ?></span></td> </tr> <tr> <td>Website:</td> <td><input type="text" name="website"></td> <td><span class="error">* <?php if (isset($errors['website'])) echo $errors['website']; ?></span></td> </tr> <tr> <td>Club phone:</td> <td><input type="integer" name="clubphone"></td> <td><span class="error">* <?php if (isset($errors['clubphone'])) echo $errors['clubphone']; ?></span></td> </tr> <tr> <td>Home phone:</td> <td><input type="integer" name="homephone"></td> <td><span class="error">* <?php if (isset($errors['homephone'])) echo $errors['homephone']; ?></span></td> </tr> <tr> <td>Mobile Phone:</td> <td><input type="integer" name="mobilephone"></td> <td><span class="error">* <?php if (isset($errors['mobilephone'])) echo $errors['mobilephone']; ?></span></td> </tr> <tr> <td>Renewal Date:</td> <td><input type="date" name="renewaldate"></td> <td><span class="error">* <?php if (isset($errors['renewaldate'])) echo $errors['renewaldate']; ?></span></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> <?php if($_SERVER['REQUEST_METHOD'] == "POST" && count($errors) == 0) { // Do it { $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City, PostCode, Email, Website, ClubPhone, HomePhone, MobilePhone, TypeofBusiness, RenewalDate ) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]','$_POST[postcode]','$_POST[email]','$_POST[website]','$_POST[clubphone]','$_POST[homephone]','$_POST[mobilephone]','$_POST[typeofbusiness]','$_POST[renewaldate]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); echo "record added"; } mysqli_close($con); } // end if $errors == 0 } ?> </form> </body> </html>
- 10 replies
-
- special
- characters
-
(and 3 more)
Tagged with:
-
hi ive encountered around 15 problems at once but just about all of them are on the same row <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // define variables and set to empty values $companyname = $firstname = $address1 = $address2 = $area = $city = $postcode = $email = $website = $clubphone = $homephone = $mobilephone = $typeofbusiness = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["companyname"])) {$errors['companyname'] = "please enter your companys name";} else {$companyname = test_input($_POST["companyname"]);} if (empty($_POST["typeofbusiness"])) {$errors['typeofbusiness'] = "please enter your TypeofBusiness";} else {$typeofbusiness = test_input($_POST["typeofbusiness"]);} if (empty($_POST["firstname"])) {$errors['firstname'] = "Please Enter Your First Name";} else {$firstname = test_input($_POST["firstname"]);} if (empty($_POST["address1"])) {$errors['address1'] = "Please Enter Address 1";} else {$address1 = test_input($_POST["address1"]);} if (empty($_POST["address2"])) {$address2 = test_input($_POST["address2"]);} if (empty($_POST["area"])) {$errors['area'] = "Please enter Area";} else {$area = test_input($_POST["area"]);} if (empty($_POST["city"])) {$errors['city'] = "Please Enter City";} else {$city = test_input($_POST["city"]);} if (empty($_POST["postcode"])) {$errors['postcode'] = "Please enter your PostCode";} else {$postcode = test_input($_POST["postcode"]);} if (empty($_POST["email"])) {$errors['email'] = "Please enter your Email";} else {$email = test_input($_POST["email"]);} if (empty($_POST["Website"])) {$errors['Website'] = "Please Enter your Website";} else {$Website = test_input($_POST["Website"]);} if (empty($_POST["ClubNumber"])) {$errors['clubnumber'] = "Please enter your club number";} else {$website = test_input($_POST["clubphone"]);} if (empty($_POST["HomeNumber"])) {$errors['homenumber'] = "Please enter your home number";} else {$website = test_input($_POST["homephone"]);} if (empty($_POST["MobileNumber"])) {$errors['mobilenumber'] = "Please enter your mobile number";} else {$website = test_input($_POST["mobilephone"]);} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>Add Leads</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table border = "0"> <tr> <td>Company Name:</td><td> <input type="text" name="companyname"></td> <td><span class="error">* <?php if (isset($errors['companyname'])) echo $errors['companyname']; ?></span></td> </tr> <tr> <td>type of business:</td><td> <input type="text" name="typeofbusiness"></td> <td><span class="error">* <?php if (isset($errors['companyname'])) echo $errors['companyname']; ?></span></td> </tr> <tr> <td>First Name:</td><td> <input type="text" name="firstname"></td> <td><span class="error">* <?php if (isset($errors['firstname'])) echo $errors['firstname']; ?></span></td> </tr> <tr> <td>Address 1:</td><td> <input type="text" name="address1"></td> <td><span class="error">* <?php if (isset($errors['address1'])) echo $errors['address1']; ?></span></td> </tr> <tr> <td>Address 2:</td><td><input type="text" name="address2"></td> </tr> <tr> <td>Area:</td> <td><input type="text" name="area"></td> <td><span class="error">* <?php if (isset($errors['area'])) echo $errors['area']; ?></span></td> </tr> <tr> <td>PostCode:</td> <td><input type="text" name="postcode"></td> <td><span class="error">* <?php if (isset($errors['postcode'])) echo $errors['postcode']; ?></span></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city"></td> <td><span class="error">* <?php if (isset($errors['city'])) echo $errors['city']; ?></span></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email"></td> <td><span class="error">* <?php if (isset($errors['email'])) echo $errors['email']; ?></span></td> </tr> <tr> <td>Website:</td> <td><input type="text" name="website"></td> <td><span class="error">* <?php if (isset($errors['website'])) echo $errors['website']; ?></span></td> </tr> <tr> <td>Club phone:</td> <td><input type="text" name="clubphone"></td> <td><span class="error">* <?php if (isset($errors['clubphone'])) echo $errors['clubphone']; ?></span></td> </tr> <tr> <td>home phone:</td> <td><input type="text" name="homephone"></td> <td><span class="error">* <?php if (isset($errors['homephone'])) echo $errors['homephone']; ?></span></td> </tr> </tr> <tr> <td>mobile phone:</td> <td><input type="text" name="mobilephone"></td> <td><span class="error">* <?php if (isset($errors['mobilephone'])) echo $errors['mobilephone']; ?></span></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> <?php if (count($errors)==0) { $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City, PostCode, Email, Website, ClubPhone, HomePhone, MobilePhone ) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]','$_POST[postcode]','$_POST[email]','$_POST[website]','$_POST[clubphone]','$_POST[homephone]','$_POST[mobilephone]','$_POST[typeofbusiness]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); echo "record added"; } mysqli_close($con); } // end if $errors == 0 ?> </form> </body> </html> and the errors ( ! ) Notice: Undefined variable: errors in C:\wamp\www\AddLeads\addeadstemplate.php on line 161 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: companyname in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: firstname in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: address1 in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: address2 in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: area in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: city in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: postcode in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: email in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: website in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: clubphone in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: homephone in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: mobilephone in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 ( ! ) Notice: Undefined index: typeofbusiness in C:\wamp\www\AddLeads\addeadstemplate.php on line 172 Call Stack # Time Memory Function Location 1 0.0000 166344 {main}( ) ..\addeadstemplate.php:0 Error: Column count doesn't match value count at row 1 if anyone can help please get back to me soon as
-
I am on the first year at college studying computer science and they sent me to write a php program that can change a decimal number to IEEE754 standard on 16bits. I know most of you will laugh because it is very easy but I need help. this is what i got so far. ALL i need is how to control the mantissa.. you know, save 10 numbers.. and how to control the while loop so he stops when i have 10 spots on mantissa.. <?php echo "Enter any number\n"; $number=trim(fgets(STDIN)); $low=floor($number); $decimal=$number - $low; $real=decbin($low); while(0<$decimal<1) { $mantissa[]=$decimal*2; } echo "\n"; ?>
-
Hello, there. I've been messing around with this stuff recently and ran across this error when trying to output a message when not all login fields are filled in, as well as an error when trying to output a successful login message.. These parts of the code are: Check all fields filled: //get the form data $myusername = ($_POST['username']); $mypassword = ($_POST['password']); //check if all fields are filled in if ( (!$myusername) || (!mypassword) ) ) { echo "Please fill in all fields"; exit; } Check if user exists & log in: //check if user exists if ($account ==1) { $_SESSION["username"] = $myusername; $_SESSION["password"] = $mypassword; $_SESSION["userrecord"] = mysql_fetch_assoc($result); echo "You have been logged in successfully. Please click <a href=account.php>here</a> to continue."; } As you can probably tell from the title, the echo does not output onto the webpage. Any help is very much appreciated. Thanks.
-
<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // define variables and set to empty values $companynameErr = $firstnameErr = $genderErr = $address1Err = $address2Err = $areaErr = $cityErr = ""; $companyname = $firstname = $gender = $comment = $address1 = $address2 = $area = $city = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["companyname"])) {$companynameErr = "companyname is required";} else {$companyname = test_input($_POST["companyname"]);} if (empty($_POST["firstname"])) {$firstnameErr = "firstname is required";} else {$firstname = test_input($_POST["firstname"]);} if (empty($_POST["address1"])) {$address1 = "";} else {$address1 = test_input($_POST["address1"]);} if (empty($_POST["address2"])) {$address2 = "";} else {$address2 = test_input($_POST["address2"]);} if (empty($_POST["area"])) {$area = "";} else {$area = test_input($_POST["area"]);} if (empty($_POST["city"])) {$city = "";} else {$city = test_input($_POST["city"]);} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table border = "0"> <tr> <td>company name:</td><td> <input type="text" name="companyname"></td> <td><span class="error">* <?php echo $companynameErr;?></span></td> <tr> <tr> <td>First Name:</td><td> <input type="text" name="firstname"></td> <td><span class="error">* <?php echo $firstnameErr;?></span></td> </tr> <tr> <td>address1:</td><td> <input type="text" name="address1"></td> <td><span class="error">*<?php echo $address1Err;?></span></td> </tr> <tr> <td>address2:</td><td><input type="text" name="address2"></td> <td><span class="error">* <?php echo $address2Err;?></span></td> </tr> <tr> <td>area:</td> <td><input type="text" name="area"></td> <td><span class="error">* <?php echo $areaErr;?></span></td> </tr> <tr> <td>city:</td> <td><input type="text" name="city"></td> <td><span class="error">* <?php echo $cityErr;?></span></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> <?$sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); ?> </form> </body> </html> right ive been doing this for a while now and i really wana get this out the way what i wana do is check fields if they are empty if they are empty a message will appear saying that all fields need to be filled and if all are filled it will send the data filled in to a database please help im getting bored of this now.
- 5 replies
-
- php
- validation
-
(and 1 more)
Tagged with:
-
hi all ive been trying to do this validation thing for ages now where i want to check if the field is empty and if so ask them to fill it and then once its filled go to the next page but ive been having problems with this i had loads of errors but i got it down to one which im confused to hell about and even once i get this error out the way i still don't no if it does validate please help. <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <? $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO tbl_club_contacts (companyname, FirstName, Address1, Address2, Area, City); VALUES ('nelsons', 'luke', '', 'IT', '5 HIGHFIELD ROAD', 'LITTLEOVER', 'DERBY')"); mysqli_close($con); // define variables and set to empty values $companynameErr = $FirstNameErr = $Address1Err = $Address2Err = $AreaErr = $CityErr = ""; $companyname = $FirstName = $Address1 = $Address2 = $Area = $City = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") if($_POST['companyname']==null || $_POST['companyname']==""); { $allValid = false; } ?> <form action="insertaddleads.php" method="post"> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table border = "0"> <tr> <td>companyname:</td> <td><input type="text" name="companyname"> <span class="error">* <?php echo $companynameErr;?></span></td> </tr> <tr> <td>FirstName:</td> <td><input type="text" name="firstname"> <span class="error">* <?php echo $FirstNameErr;?></span></td> </tr> <tr> <td>Address 1:</td> <td><input type="text" name="address1"> <span class="error">* <?php echo $Address1Err;?></span></td> </tr> <tr> <td>Address 2:</td><td><input type="text" name="address2"> <span class="error">* <?php echo $Address2Err;?></span></td> </tr> <tr> <td>Area:</td><td><input type="text" name="area"> <span class="error">* <?php echo $AreaErr;?></span></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city"> <span class="error">* <?php echo $CityErr;?></span></td> </tr> <tr> <td><input type="submit" name="submit" value="Submit"></td> </tr> </form> <? echo $companyname; echo "<br>"; echo $FirstName; echo "<br>"; echo $Address1; echo "<br>"; echo $Address2; echo "<br>"; echo $Area; echo "<br>"; echo $City; echo "<br>"; ?> <?php foreach($_POST as $companyname=>$companyname) { if($fieldValue == '') { print "<div>$companyname is blank</div>"; } } ?> </body> </html> this is the second page <?php $con=mysqli_connect("localhost","root","","nib"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City) VALUES ('$_POST[test]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "record added"; mysqli_close($con); ?> <html> <body> <form action="addleads2.php" method="post"> <input type="submit", value = "go back"> </form> </body> </html> and then the error code ive been getting ( ! ) Notice: Undefined index: companyname in C:\wamp\www\AddLeads\addleads2.php on line 30
- 6 replies
-
- errorsundefined index
- row 30
-
(and 2 more)
Tagged with:
-
hi i want to put a validation in my code so it will check all fields if they have been used ive got the code pretty much sorted but they i think they is one problem with it on line 30 <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <? $con = mysqli_connect("","","",""); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City); VALUES ('nelsons', 'luke', '', 'IT', '5 HIGHFIELD ROAD', 'LITTLEOVER', 'DERBY')"); mysqli_close($con); // define variables and set to empty values $companynameErr = $FirstNameErr = $Address1Err = $Address2Err = $AreaErr = $CityErr = ""; $companyname = $FirstName = $Address1 = $Address2 = $Area = $City = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") $allValid = true; if(validation fails); { $allValid = false; } if($allValid) { // connect to db, create query, execute query } As for checking the values you could if($_POST['companyname']==null || $_POST['companyname']=="") { $allValid = false; } ?> <form action="insertaddleads.php" method="post"> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> CompanyName: <input type="text" name="companyname"> <span class="error">* <?php echo $CompanyNameErr;?></span> <br><br> FirstName: <input type="text" name="firstname"> <span class="error">* <?php echo $FirstNameErr;?></span> <br><br> Address 1: <input type="text" name="address1"> <span class="error">* <?php echo $Address1Err;?></span> <br><br> Address 2: <input type="text" name="address2"> <span class="error">* <?php echo $Address2Err;?></span> <br><br> Area: <input type="text" name="area"> <span class="error">* <?php echo $AreaErr;?></span> <br><br> City: <input type="text" name="city"> <span class="error">* <?php echo $CityErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <? echo $CompanyName; echo "<br>"; echo $FirstName; echo "<br>"; echo $Address1; echo "<br>"; echo $Address2; echo "<br>"; echo $Area; echo "<br>"; echo $City; echo "<br>"; ?> <?php foreach($_POST as $fieldName=>$fieldValue) { if($fieldValue == '') { print "<div>$fieldName is blank</div>"; } } ?> </body> </html> heres the insert just incase <?php $con=mysqli_connect("","","",""); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "record added"; mysqli_close($con); ?> <html> <body> <form action="addleads2.php" method="post"> <input type="submit", value = "go back"> </form> </body> </html>
-
hi all im trying to colour the money in and out .Bascally if the money was sent to someone i want to colour the balance or money sent in red and if the money was received i would want the received balance to be green with a plus sigh any ideas my code is below
-
hi i really need your help what im trying to do is check if form fields are empty and then if so stop users from going any further i got the jist sorted e.g. send data to a database and this is the main code <?php $con=mysqli_connect("","","",""); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName) VALUES ('$_POST[CompanyName]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "record added"; mysqli_close($con); ?> <html> <body> <form action="copyofaddleads2.php" method="post"> <input type="submit", value = "go back"> </form> </body> </html> heres the insert document <?php $con=mysqli_connect("","","",""); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[area]','$_POST[city]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "record added"; mysqli_close($con); ?> <html> <body> <form action="addleads2.php" method="post"> <input type="submit", value = "go back"> </form> </body> </html>
- 5 replies
-
- help
- blank field
-
(and 1 more)
Tagged with:
-
I need the random cd-key from this site when email entered in textbox http://a9.comze.com/2.php to automatically send to email
-
Basically I want to make very simple .php website success.php When person is redirected they have to input email address then (60char) code shows up they can copy it and a copy is sent to thier email address and my email address
-
Hello! l was wondering if you might be able to help me. l am trying to find out how to make PHP read a file, and then check if that text is already there, and if so don't re-write it. l'll give out my code for an example. <?php //text file that counts the peeps that visit the site $lne = "line.txt"; $File = "counter.txt"; $handle = fopen($File, 'r+') ; //file open $data = fread($handle, 512) ; //file read $count = $data + 1; //Adds one person :DDDDD fseek($handle, 0) ; fwrite($handle, $count) ; //saves the new person echo 'Count #'.$count; // // // // // // $File2 = "ips.txt"; fclose($handle) ; if (isset($_POST['ip'])) { $ip = $_POST['ip']; $port = $_POST['port']; echo 'Connecting to ' . $ip . ':' . $port; exit(); } $ip = getenv("REMOTE_ADDR"); echo '<br>'.$ip; $handle2 = fopen($File2, 'r+') ; //file open $data2 = fread($handle2, 512) ; //file read fwrite($handle2,"\n" . $ip .':' . $count); //saves the new ip ?> <html> <form method="POST"> <input type="hidden" name="ip"> <input type="hidden" name="port"> </html> lt just re-writes the lP with the new counter, very annoying. l can filter it out with VB but l want it all to be server sided. Thank you for your time ~Papa Beans