Jump to content

spanner206

Members
  • Posts

    82
  • Joined

  • Last visited

Posts posted by spanner206

  1. the view source is 

    <select name="typeofbusiness">
            <option value=''> - select type of business -</option>
            <option value=''></option>
            </select> 

    so they is quite a bit missing

     

    this is my current code 

        <td>Type of Business:</td>
        <td>
            <select name="typeofbusiness">
            <option value=''> - select type of business -</option>
            <?php 
            $sql = "SELECT tbl_typeofbusiness.id, tbl_typeofbusiness.Agent FROM tbl_typeofbusiness;";
           $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>
    
  2. right ive done that and ive realised ive made the most rookie mistake ever by searching for the wrong table.... 3 DAYS IVE BEEN LOOKING AT THE SAME PROBLEM. anyway last problem the data is still not being pulled from the database into the drop down box any ideas?

  3. yh ive tried that and for some reason everything under or die will stop working e.g. ive got about 5 -6 other fields under type of business and they will not appear, in the form. when i do this no error occurs aswell and still nothing is being pulled from the database any ideas???

  4. hopefully this will be the end of this little project but ive been trying to do this for a while now i need to get 2 different collumns one of which is hidden which will be the ID one has the value of the field e.g. test, im hopefully down to the last error.

    ( ! ) Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\AddLeads\addeadstemplate.php on line 254 Call Stack # Time Memory Function Location 1 0.0000 186408 {main}( ) ..\addeadstemplate.php:0 2 0.0156 194880 mysqli_fetch_row ( ) ..\addeadstemplate.php:254
    	<tr>
        <td>Type of Business:</td>
        <td>
            <select name="typeofbusiness">
            <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 (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['typeofbusiness'])) echo $errors['typeofbusiness']; ?></span></td>
    		
    	</tr>
    

    i can get rid of the error bie adding 'or die' on line 253 other than just or but what this does is stop everything under or die stops working cause ive got another 6 or 7 fields under type of business aswell as this no error occurs so im confused to hell, hopefully its not to complicated any help will be greatly appreciated :) 

  5. <!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
     
    $id = $companyname = $firstname = $address1 = $address2 = $county = $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";
    }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';
    }
    
    
     if (empty($_POST["typeofbusiness"]))
    {
        $errors['typeofbusiness'] = "Please Enter Your type of business";
    }
    elseif(strpos($_POST['typeofbusiness'], '/') !== false)
    {
        $errors['typeofbusiness'] = 'Cannot use /';
    }
    else
    {
       $typeofbusiness = test_input($_POST["typeofbusiness"]);
    }     
        
    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["address1"])){
    
        $errors['address1'] = "Please Enter Your address1";
    
    
    }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['address1'],$matches)){ // list of invalid characters
    
        #echo '<pre>',print_r($matches),'</pre>';
        $invalid_characters = implode($matches[0]);
        $errors['address1'] = 'Cannot use '.$invalid_characters;
    
    }    
       
        if (empty($_POST["address2"]))
    
         {$address2 = test_input($_POST["address2"]);}
     
    if (empty($_POST["county"])){
    
        $errors['county'] = "Please Enter Your county";
    
    }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['county'],$matches)){ // list of invalid characters
    
        #echo '<pre>',print_r($matches),'</pre>';
        $invalid_characters = implode($matches[0]);
        $errors['county'] = 'Cannot use '.$invalid_characters;
    
    }    
    	 
    if (empty($_POST["city"])){
    
        $errors['city'] = "Please Enter Your county";
    
    }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['city'],$matches)){ // list of invalid characters
    
        #echo '<pre>',print_r($matches),'</pre>';
        $invalid_characters = implode($matches[0]);
        $errors['city'] = 'Cannot use '.$invalid_characters;
    
    }    
        
    if (empty($_POST["postcode"])){
    
        $errors['postcode'] = "Please Enter Your postcode";
    
    }elseif(preg_match_all("/[(?\/<>*:.@)]/i",$_POST['postcode'],$matches)){ // list of invalid characters
    
        #echo '<pre>',print_r($matches),'</pre>';
        $invalid_characters = implode($matches[0]);
        $errors['postcode'] = 'Cannot use '.$invalid_characters;
    }    
    else
    {
        $postcode = test_input($_POST["postcode"]);
    }
    $sql = sprintf("SELECT COUNT(*) as total
        FROM tbl_club_contacts
        WHERE postcode = '%s' ", $con->real_escape_string($postcode));
    
    $result = $con->query($sql);
    $row = $result->fetch_assoc();
    if ($row['total'] > 0) {
        $errors['postcode'] = "The name '$postcode' already exists.";
    }
    
    if (empty($_POST["email"]))
    {
        $errors['email'] = "Please Enter Your email";
    }
    elseif(strpos($_POST['email'], '/') !== false)
    {
        $errors['email'] = 'Cannot use /';
    }
    else
    {
       $email = test_input($_POST["email"]);
    }    
    if (empty($_POST["website"]))
    {
        $errors['website'] = "Please Enter Your website";
    }
    elseif(strpos($_POST['website'], '/') !== false)
    {
        $errors['website'] = 'Cannot use /';
    }
    else
    {
       $website = test_input($_POST["website"]);
    }    
    	
    if (empty($_POST["clubphone"]))
    {
        $errors['clubphone'] = "Please Enter Your clubphone";
    }
    elseif(preg_match_all("/[(?\/<>*:.@a-z)]/i",$_POST['clubphone'],$matches)){ // list of invalid characters
    
        
        $invalid_characters = implode($matches[0]);
        $errors['clubphone'] = 'Cannot use '.$invalid_characters;
    } 
    else
    {
       $clubphone = test_input($_POST["clubphone"]);
    }  
    	   
    if (empty($_POST["homephone"]))
    {
        $errors['homephone'] = "Please Enter Your home phone";
    }
    elseif(preg_match_all("/[(?\/<>*:.@a-z)]/i",$_POST['homephone'],$matches)){ // list of invalid characters
    
        #echo '<pre>',print_r($matches),'</pre>';
        $invalid_characters = implode($matches[0]);
        $errors['homephone'] = 'Cannot use '.$invalid_characters;
    }  
    else
    {
       $homephone = test_input($_POST["homephone"]);
    }
    
    if (empty($_POST["mobilephone"]))
    {
        $errors['mobilephone'] = "Please Enter Your mobilephone";
    }
    elseif(preg_match_all("/[(?\/<>*:.@a-z)]/i",$_POST['mobilephone'],$matches)){ // list of invalid characters
    
        #echo '<pre>',print_r($matches),'</pre>';
        $invalid_characters = implode($matches[0]);
        $errors['mobilephone'] = 'Cannot use '.$invalid_characters;
    } 
    else
    {
       $mobilephone = test_input($_POST["mobilephone"]);
    }  
    	
    if (empty($_POST["renewaldate"]))
    {
        $errors['renewaldate'] = "Please Enter Your renewaldate";
    }
    elseif(strpos($_POST['renewaldate'], '/') !== false)
    {
        $errors['renewaldate'] = 'Cannot use /';
    }
    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" 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="typeofbusiness">
            <option value=''> - select type of business -</option>
            <?php 
            $sql = "SELECT id, Agent FROM tbl_typesofbusiness";
            $res = mysqli_query($con, $sql);
            while (list($con, $id, $typeofbusiness) = mysqli_fetch_row($res)) {
                echo "<option value='$id'>$typeofbusiness</option>\n";
            }
            ?>
            </select>
        </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>
    		<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>County:</td>
    		<td> <select name="county">
    			<option>-- please select one --</option>
    			<option>Bedfordshire</option>
    			<option>Berkshire</option>
    			<option>Bristol</option>
    			<option>Buckinghamshire </option>
    			<option>Cambridgeshire </option>
    			<option>Cheshire</option>
    			<option>City of London</option>
    			<option>Cornwall</option>
    			<option>Cumbria </option>
    			<option>Devon</option>
    			<option>Derbyshire </option>
    			<option>Dorset</option>
    			<option>County Durham</option>
    			<option>East Riding of Yorkshire</option>
    			<option>East Sussex</option>
    			<option>Essex</option>
    			<option>Gloucestershire </option>
    			<option>Greater London</option>
    			<option>Greater Manchester</option>
    			<option>Hampshire</option>
    			<option>Herefordshire</option>
    			<option>Hertfordshire</option>
    			<option>Isle of Wight</option>
    			<option>Kent</option>
    			<option>Lancashire</option>
    			<option>Leicestershire</option>
    			<option>Lincolnshire</option>
    			<option>Merseyside</option>
    			<option>Norfolk</option>
    			<option>North Yorkshire</option>
    			<option>Northamptonshire </option>
    			<option>Northumberland </option>
    			<option>Nottinghamshire </option>
    			<option>Oxfordshire </option>
    			<option>Rutland </option>
    			<option>Shropshire </option>
    			<option>Somerset </option>
    			<option>South Yorkshire </option>
    			<option>Staffordshire </option>
    			<option>Suffolk </option>
    			<option>Surrey </option>
    			<option>Tyne and Wear</option>
    			<option>Warwickshire </option>
    			<option>West Midlands </option>
    			<option>West Sussex</option>
    			<option>West Yorkshire </option>
    			<option>Wiltshire</option>
    			<option>Worcestershire</option>
    
    	</td>
    		<td><span class="error">* <?php if (isset($errors['county'])) echo $errors['county']; ?></span></td>
       </tr>
    
    	<tr>
    		<td>City:</td>
    		<td> <select name="city">
    			<option>-- please select one --</option>
    			<option>Derby</option>
    			<option>test2</option>
    			<option>test3</option>
    			<option>test4</option>
    			<option>test5</option>
    			<option>test6</option>
    			<option>test7</option>
    			<option>test8</option>
    			<option>test9</option>
    			<option>test10</option>
    		</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 (ID, CompanyName, FirstName, Address1, Address2, County, City, PostCode, Email, Website, ClubPhone, HomePhone, MobilePhone, TypeofBusiness, RenewalDate ) VALUES ('$_POST[id]''$_POST[companyname]','$_POST[firstname]','$_POST[address1]','$_POST[address2]','$_POST[county]','$_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>
    

    lol forgot code

  6. right ive tryed i dont no what to do knowing me ive done it in the wrong format but its basically doing exactly the same as last time this is the code i got, i need to put it all in a drop down box and the box is just empty with no sign of any fields 

    		<td>Type of Business:</td><td> 
    		<select name="typeofbusiness">
    		<?php $sql = sprintf("SELECT tbl_typesofbusiness.id, tbl_typesofbusiness.Agent FROM tbl_typesofbusiness");
    		if ($result = mysqli_query($con, $sql))
    		
    		while($row = mysqli_fetch_array($result))
      {
    		echo '<form action="addeadstemplate.php" method="post">';
    		echo '<tr>';
    		echo '<td><input type="text" name="name" value="' . $row['testcollumn'] . '" /></td>'; 
    		echo '<td><input type="hidden" name="hidden" value="' . $row['id'] . '" /></td>';
    		echo '</tr>';
      }
      
    ?>
      
      </td>
    		<td><span class="error">* <?php if (isset($errors['typeofbusiness'])) echo $errors['typeofbusiness']; ?></span></td>
    		
    	</tr>
    

    i'm crap at this i know but i'm still learning please help cause it seems that every time i try righting code it doesn't seem to work :D

  7. right what i need to do is create 2 collumns for a html form, one of these is the ID and needs to be hidden and one collumn is full of options associated with these ID's the table which these two collumns are located on the database is called tbl_typesofbusiness and i just cant figure this out ive got the option box up but thats as far as i got i cant get two collumns up and they is no options in the option box, i just cant hack it ive been trying for a while and im confused to hell.

    	<tr>
    		<td>Type of Business:</td><td> 
    		<select name="typeofbusiness">
    		<?php $sql = sprintf("SELECT tbl_typesofbusiness.id, tbl_typesofbusiness.Agent FROM tbl_typesofbusiness")?></td>
    		<td><span class="error">* <?php if (isset($errors['typeofbusiness'])) echo $errors['typeofbusiness']; ?></span></td>
    		
    	</tr>
    

    they is no errors on this code but i still cant seem to find a solution to it aswell theres only one record in the table at the moment which is called test1 with an id of 1.

     

    please help i just cant seem to hack it.

  8. what my boss wants is for there to be 2 different columns one id column which is hidden and one for the values e.g. in type of business there would be something like trade or somet like that he wants this done because the values are already on his websites which have id's so i can just call the the values by there ids but im just getting confused.

  9. yh my boss sent it to me heres the original code all i changed was change the name from agent to typeofbusiness.

    <select name="agentIndex" id="agentIndex">
    						<?php 
    						$count = count($_SESSION['agents']);
    						for ($i = 0; $i < $count; $i++) {
    							if($_SESSION['agentsid'][$i]!=$_SESSION['current_Agent_Id']){
    ?>
    						  <option value="<?php echo $_SESSION['agentsid'][$i];?>" <?php if (isset($_REQUEST['agentIndex'])&&$_REQUEST['agentIndex']==$_SESSION['agentsid'][$i]) { echo'selected="selected"'; }?>><?php echo $_SESSION['agents'][$i];?></option>
    <?php 
    }
    
    
×
×
  • 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.