spanner206 Posted December 2, 2013 Share Posted December 2, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/ Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 im pretty sure the code for pulling the data isent right cause all ive done in this one is put a sql query in Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460942 Share on other sites More sharing options...
Barand Posted December 2, 2013 Share Posted December 2, 2013 All you have done is define a string. ( and why the sprintf() for a simple string definition??? ) You need to submit the query then fetch the data. Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460945 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 lol forgot about that, its monday and a long weekend cheers Barand Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460950 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460961 Share on other sites More sharing options...
Barand Posted December 2, 2013 Share Posted December 2, 2013 (edited) try <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($id, $tob) = mysqli_fetch_row($res)) { echo "<option value='$id'>$tob</option>\n"; } ?> </select> </td> Edited December 2, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460964 Share on other sites More sharing options...
Ch0cu3r Posted December 2, 2013 Share Posted December 2, 2013 (edited) Edit oops.... To make a dropdown you need to output a <select> field with <options>'s. $sql = 'SELECT tbl_typesofbusiness.id, tbl_typesofbusiness.Agent FROM tbl_typesofbusiness'; if ($result = mysqli_query($con, $sql)) { echo '<form action="addeadstemplate.php" method="post">'; // start the form echo '<select name="businessAgents">'; // start a dropdown menu while($row = mysqli_fetch_array($result)) { echo '<option value="' . $row['id'] . '>' . $row['testcollumn'] . '</option>'; // add options to the menu } echo '</select>'; // close the dropdown menu echo '<input type="submit" />'; // submit button echo '</form>'; // close the form } Edited December 2, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460965 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 an error occured while testing your comment barand ( ! ) Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\AddLeads\addeadstemplate.php on line 253 Call Stack # Time Memory Function Location 1 0.0000 186104 {main}( ) ..\addeadstemplate.php:0 2 0.0625 194536 mysqli_fetch_row ( ) ..\addeadstemplate.php:253 Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460967 Share on other sites More sharing options...
Barand Posted December 2, 2013 Share Posted December 2, 2013 I used your connection variable, $con. You need to check your mysqli connection code Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460968 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 this is the whole code that ive been using since the start, i think the error is something to do with a query fault any ideas??? Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460969 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 <!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 Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460970 Share on other sites More sharing options...
Barand Posted December 2, 2013 Share Posted December 2, 2013 (edited) in my code, change $res = mysqli_query($con, $sql); to $res = mysqli_query($con, $sql) or die (mysqli_error($con)); Edited December 2, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460971 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 now i got the same error on 252 /: Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460972 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 ( ! ) Warning: mysql_error() expects parameter 1 to be resource, object given in C:\wamp\www\AddLeads\addeadstemplate.php on line 252 Call Stack # Time Memory Function Location 1 0.0000 186392 {main}( ) ..\addeadstemplate.php:0 2 0.0312 194824 mysql_error ( ) ..\addeadstemplate.php:252 Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460973 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 right scratch that i just figured that one out now theres no error at all and half of my html form is missing???? Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460974 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 o and theres nothing being pulled from the database :/ Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460975 Share on other sites More sharing options...
Barand Posted December 2, 2013 Share Posted December 2, 2013 Is mysqli_error($con) outputting an error message on 252? If so, what. Off-topic, looking at your current code I see you totally ignored my advice on the "the, The, THE" problem! Why do I bother? 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460976 Share on other sites More sharing options...
spanner206 Posted December 2, 2013 Author Share Posted December 2, 2013 yh sorry about that a couple of minuites before u sent that i put a space in and it kinda worked ile put this version in now Quote Link to comment https://forums.phpfreaks.com/topic/284446-2-collumns-1-hidden-pulled-from-a-table-help/#findComment-1460977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.