Jump to content

lukew96

New Members
  • Posts

    9
  • Joined

  • Last visited

lukew96's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. cheers cheers cheers cheers cheers cheers cheers cheers cyber robot
  2. i had to get rid of some stuff still the same problem though
  3. im pretty sure ive set them correctly but i done no heres my whole 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 = $clientname = $address2 = $county = $city = $postcode = $email = $website = $clubphone = $homephone = $mobilephone = $typesofbusiness = $renewaldate = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $errors = array(); 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; $answer = (isset($_POST['answer'])) ? $_POST['answer'] : ''; } elseif(strlen($_POST['companyname']) > 220) { $errors['companyname'] = 'Company name must be less then 220 characters'; } if (empty($_POST["typesofbusiness"])) { $errors['typesofbusiness'] = "Please Enter Your type of business"; } elseif(strpos($_POST['typesofbusiness'], '/') !== false) { $errors['typesofbusiness'] = 'Cannot use /'; } else { $typesofbusiness = test_input($_POST["typesofbusiness"]); } if (empty($_POST["firstname"])){ $errors['firstname'] = "Please Enter Your First Name"; }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['firstname'],$matches)){ // list of invalid characters #echo '<pre>',print_r($matches),'</pre>'; $invalid_characters = implode($matches[0]); $errors['firstname'] = 'Cannot use '.$invalid_characters; } if (empty($_POST["clientname"])){ $errors['clientname'] = "Please Enter Your clientname"; }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['clientname'],$matches)){ // list of invalid characters #echo '<pre>',print_r($matches),'</pre>'; $invalid_characters = implode($matches[0]); $errors['clientname'] = 'Cannot use '.$invalid_characters; } ?> <h2>Add Leads</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <table border = "1" bordercolor = ""> <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> <select name="typesofbusiness"> <option value=''> - select type of business -</option> <?php $sql = "SELECT tbl_typesofbusiness.id, tbl_typesofbusiness.Agent FROM tbl_typesofbusiness;"; $res = mysqli_query($con, $sql) or die (mysqli_error($con)); while (list($id, $tob) = mysqli_fetch_row($res)){ echo "<option value='$id'>$tob</option>\n"; } ?> </select> </td> <td><span class="error">* <?php if (isset($errors['typesofbusiness'])) echo $errors['typesofbusiness']; ?></span></td> </tr> <tr> <td>Client name:</td> <input type="text" name="clientname" value="" <?php echo htmlspecialchars($_POST['clientname']); ?>> <td><span class="error">* <?php if (isset($errors['clientname'])) echo $errors['clientname']; ?></span></td> </tr> <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, clientname) VALUES ('$_POST[companyname]','$_POST[firstname]','$_POST[clientname]; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); } // end if $errors == 0 } ?> </form> </body> </html>
  4. changed that but now getting this ( ! ) Notice: Undefined index: clientname in C:\wamp\www\AddLeads\addeadstemplate.php on line 267 Call Stack # Time Memory Function Location 1 0.0000 186584 {main}( ) ..\addeadstemplate.php:0
  5. ( ! ) Notice: Undefined index: address1 in C:\wamp\www\AddLeads\addeadstemplate.php on line 268 Call Stack # Time Memory Function Location 1 0.0000 186656 {main}( ) ..\addeadstemplate.php:0 heres the error
  6. 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
  7. 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
  8. 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'
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.