Adding CSS class in form that posts to PHP breaks query - php
I am a beginner to coding... Something strange happens when I enter a CSS class to a form that posts data to same php file that executes mysqli query. Everything goes well until I add to the form. When I do this, I don't get an error, but browser reads: search.php?submitted=true&category=firstname&criteria=hassan&submitted=Submit. I also don't get any results back.
When I don't have the css class added, it works fine, url doesn't read the above and database results come back. Any help as to why this happens and what I can do to fix it?
Apologies in advance for strange way of adding css. Using purecss.io but import from yahoo cdn doesn't work, also uploading to server doesn't work. Only way I get it to work is by adding the css code directly into file.
<html>
<head>
<title>pageName</title>
<style type="text/css">
table {
background-color: #ADD8E6;
border: 1px solid black;
font-family: Arial; font-size: 14px;
}
th {
text-align: left;
}
.pure-form input[type=text],.pure-form input[type=password],.pure-form input[type=email],.pure-form input[type=url],.pure-form input[type=date],.pure-form input[type=month],.pure-form input[type=time],.pure-form input[type=datetime],.pure-form input[type=datetime-local],.pure-form input[type=week],.pure-form input[type=number],.pure-form input[type=search],.pure-form input[type=tel],.pure-form input[type=color],.pure-form select,.pure-form textarea{padding:.5em .6em;display:inline-block;border:1px solid #ccc;box-shadow:inset 0 1px 3px #ddd;border-radius:4px;vertical-align:middle;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.pure-form input:not([type]){padding:.5em .6em;display:inline-block;border:1px solid #ccc;box-shadow:inset 0 1px 3px #ddd;border-radius:4px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.pure-form input[type=color]{padding:.2em .5em}.pure-form input[type=text]:focus,.pure-form input[type=password]:focus,.pure-form input[type=email]:focus,.pure-form input[type=url]:focus,.pure-form input[type=date]:focus,.pure-form input[type=month]:focus,.pure-form input[type=time]:focus,.pure-form input[type=datetime]:focus,.pure-form input[type=datetime-local]:focus,.pure-form input[type=week]:focus,.pure-form input[type=number]:focus,.pure-form input[type=search]:focus,.pure-form input[type=tel]:focus,.pure-form input[type=color]:focus,.pure-form select:focus,.pure-form textarea:focus{outline:0;border-color:#129FEA}.pure-form input:not([type]):focus{outline:0;border-color:#129FEA}.pure-form input[type=file]:focus,.pure-form input[type=radio]:focus,.pure-form input[type=checkbox]:focus{outline:thin solid #129FEA;outline:1px auto #129FEA}.pure-form .pure-checkbox,.pure-form .pure-radio{margin:.5em 0;display:block}.pure-form input[type=text][disabled],.pure-form input[type=password][disabled],.pure-form input[type=email][disabled],.pure-form input[type=url][disabled],.pure-form input[type=date][disabled],.pure-form input[type=month][disabled],.pure-form input[type=time][disabled],.pure-form input[type=datetime][disabled],.pure-form input[type=datetime-local][disabled],.pure-form input[type=week][disabled],.pure-form input[type=number][disabled],.pure-form input[type=search][disabled],.pure-form input[type=tel][disabled],.pure-form input[type=color][disabled],.pure-form select[disabled],.pure-form textarea[disabled]{cursor:not-allowed;background-color:#eaeded;color:#cad2d3}.pure-form input:not([type])[disabled]{cursor:not-allowed;background-color:#eaeded;color:#cad2d3}.pure-form input[readonly],.pure-form select[readonly],.pure-form textarea[readonly]{background-color:#eee;color:#777;border-color:#ccc}.pure-form input:focus:invalid,.pure-form textarea:focus:invalid,.pure-form select:focus:invalid{color:#b94a48;border-color:#e9322d}.pure-form input[type=file]:focus:invalid:focus,.pure-form input[type=radio]:focus:invalid:focus,.pure-form input[type=checkbox]:focus:invalid:focus{outline-color:#e9322d}.pure-form select{height:2.25em;border:1px solid #ccc;background-color:#fff}.pure-form select[multiple]{height:auto}.pure-form label{margin:.5em 0 .2em}.pure-form fieldset{margin:0;padding:.35em 0 .75em;border:0}.pure-form legend{display:block;width:100%;padding:.3em 0;margin-bottom:.3em;color:#333;border-bottom:1px solid #e5e5e5}.pure-form-stacked input[type=text],.pure-form-stacked input[type=password],.pure-form-stacked input[type=email],.pure-form-stacked input[type=url],.pure-form-stacked input[type=date],.pure-form-stacked input[type=month],.pure-form-stacked input[type=time],.pure-form-stacked input[type=datetime],.pure-form-stacked input[type=datetime-local],.pure-form-stacked input[type=week],.pure-form-stacked input[type=number],.pure-form-stacked input[type=search],.pure-form-stacked input[type=tel],.pure-form-stacked input[type=color],.pure-form-stacked input[type=file],.pure-form-stacked select,.pure-form-stacked label,.pure-form-stacked textarea{display:block;margin:.25em 0}.pure-form-stacked input:not([type]){display:block;margin:.25em 0}.pure-form-aligned input,.pure-form-aligned textarea,.pure-form-aligned select,.pure-form-aligned .pure-help-inline,.pure-form-message-inline{display:inline-block;*display:inline;*zoom:1;vertical-align:middle}.pure-form-aligned textarea{vertical-align:top}.pure-form-aligned .pure-control-group{margin-bottom:.5em}.pure-form-aligned .pure-control-group label{text-align:right;display:inline-block;vertical-align:middle;width:10em;margin:0 1em 0 0}.pure-form-aligned .pure-controls{margin:1.5em 0 0 11em}.pure-form input.pure-input-rounded,.pure-form .pure-input-rounded{border-radius:2em;padding:.5em 1em}.pure-form .pure-group fieldset{margin-bottom:10px}.pure-form .pure-group input,.pure-form .pure-group textarea{display:block;padding:10px;margin:0 0 -1px;border-radius:0;position:relative;top:-1px}.pure-form .pure-group input:focus,.pure-form .pure-group textarea:focus{z-index:3}.pure-form .pure-group input:first-child,.pure-form .pure-group textarea:first-child{top:1px;border-radius:4px 4px 0 0;margin:0}.pure-form .pure-group input:first-child:last-child,.pure-form .pure-group textarea:first-child:last-child{top:1px;border-radius:4px;margin:0}.pure-form .pure-group input:last-child,.pure-form .pure-group textarea:last-child{top:-2px;border-radius:0 0 4px 4px;margin:0}.pure-form .pure-group button{margin:.35em 0}.pure-form .pure-input-1{width:100%}.pure-form .pure-input-2-3{width:66%}.pure-form .pure-input-1-2{width:50%}.pure-form .pure-input-1-3{width:33%}.pure-form .pure-input-1-4{width:25%}.pure-form .pure-help-inline,.pure-form-message-inline{display:inline-block;padding-left:.3em;color:#666;vertical-align:middle;font-size:.875em}.pure-form-message{display:block;color:#666;font-size:.875em}#media only screen and (max-width :480px){.pure-form button[type=submit]{margin:.7em 0 0}.pure-form input:not([type]),.pure-form input[type=text],.pure-form input[type=password],.pure-form input[type=email],.pure-form input[type=url],.pure-form input[type=date],.pure-form input[type=month],.pure-form input[type=time],.pure-form input[type=datetime],.pure-form input[type=datetime-local],.pure-form input[type=week],.pure-form input[type=number],.pure-form input[type=search],.pure-form input[type=tel],.pure-form input[type=color],.pure-form label{margin-bottom:.3em;display:block}.pure-group input:not([type]),.pure-group input[type=text],.pure-group input[type=password],.pure-group input[type=email],.pure-group input[type=url],.pure-group input[type=date],.pure-group input[type=month],.pure-group input[type=time],.pure-group input[type=datetime],.pure-group input[type=datetime-local],.pure-group input[type=week],.pure-group input[type=number],.pure-group input[type=search],.pure-group input[type=tel],.pure-group input[type=color]{margin-bottom:0}.pure-form-aligned .pure-control-group label{margin-bottom:.3em;text-align:left;display:block;width:100%}.pure-form-aligned .pure-controls{margin:1.5em 0 0}.pure-form .pure-help-inline,.pure-form-message-inline,.pure-form-message{display:block;font-size:.75em;padding:.2em 0 .8em}}
</style>
</head>
<body>
<h1>MEMBERS SEARCH</h1>
<form class="pure-form">
<form method="post" action="search.php">
<input type="hidden" name="submitted" value="true"/>
<label> Search Category:
<select name="category">
<option value="firstname">First NAME</option>
<option value="lastname">Last NAME</option>
</select>
</label>
<label> Search Criteria:<input type="text" name="criteria" /></label>
<input type="submit" name="submitted" />
</form>
<?php
if (isset($_POST['submitted'])){
// connect to the DB
include('connect.php');
$category = mysqli_real_escape_string($con, $_POST['category']);
$criteria = mysqli_real_escape_string($con, $_POST['criteria']);
$query = "SELECT * FROM Customers WHERE firstname LIKE '%" . $criteria ."%'";
$result = mysqli_query($con, $query);
$num_rows = mysqli_num_rows($result);
echo "$num_rows results found";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
?>
<table>
<tr>
<td width="300" ><font face="Arial Black" size="2"><?php echo $row['firstname']?> <?php echo $row['lastname']?></font></td>
</tr>
</table>
<table>
<tr>
<td width="100"><b>Licence #</b></td>
<td width="3">:</td>
<td width="120"><?php echo $row['licencenr']?></td>
</tr>
<tr>
<td width="100"><b>Birthday</b></td>
<td width="3">:</td>
<td width="120"><?php echo $row['birth']?></td>
</tr>
<tr>
<td width="100"><b>Age</b></td>
<td width="3">:</td>
<td width="120"><?php echo $row['age']?></td>
</tr>
<td width="120"> </td>
</tr>
</table>
<br>
<?php
}
}
?>
</body>
</html>
I found the solution...
instead of adding
<form class="pure-form">
i deleted
<form class="pure-form">
and changed
<form method="post" action="search.php">
to
<form method="post" class="pure-form" action="search.php">
Related
Assigning unique names for each option in a foreach loop
Good morning, I have the following form: <form name="changeImage" method="post" style="padding-bottom: 5%; border-bottom: 1px dotted black; margin-bottom: 5%;" > <select name="change[]" id="change" form="changeImage" style="width: 97%;"> <?php foreach(glob('images/backgrounds/*.*') as $filename){ echo '<option value="'.$filename.'">'.$filename.'</option>'; } ?> </select> <input type="submit" name="changeBGimage" id="changeBGimage" value="Change BG Image" style="width: 97%;" /> <?php if(isset($_POST['changeBGimage'])) { $updateBG = "UPDATE grow_backgroundImage SET filePath = '".$_POST['change']."'"; $updateBGQuery = $conn->query($updateBG); } ?> </form> I am having trouble assigning a unique value to $filename. After some research, it looks this can be done with either a hidden element or an array. I would like to use an array, but am unsure of how to do this. Currently, when the form is submitted, it is being submitted to the database correctly, however all values are equal to the last value in the foreach loop. Any assistance would be greatly appreciated.
Thank you to #MonkeyZeus and #FunkFortyNiner for assistance. This was resolved using the following code: <form name="changeImage" method="post" style="padding-bottom: 5%; border-bottom: 1px dotted black; margin-bottom: 5%;" > <select name="change" id="change" style="width: 97%;"> <?php foreach(glob('images/backgrounds/*.*') as $filename){ echo '<option value="'.$filename.'">'.$filename.'</option>'; } ?> </select> <input type="submit" name="changeBGimage" id="changeBGimage" value="Change BG Image" style="width: 97%;" /> <?php if(isset($_POST['changeBGimage'])) { $updateBG = "UPDATE grow_backgroundImage SET filePath = '".$_POST['change']."'"; $updateBGQuery = $conn->query($updateBG); echo '<pre>'.print_r($_POST, true).'</pre>'; } ?> </form>
display value from php table when clicking on a button on another page
Following is the table i created for displaying the Restaurant Name, Location and Menu for table owners. Now each of the row for the column Menu have Button as values. My table is ready with perfect values. NOW MY PROBLEM IS HOW TO DO:- Upon clicking the button corresponding to the each Restaurant, a new File(openmenu.php) will open and will echo the Restaurant Name, Mobile Number of that Restaurant and the menu. But so far, on clicking every Button ,I can only display above entries of the Last row of the table. Help Me Out. I am new to php. table.php <?php include 'nav.php'; $sql = 'SELECT * FROM owners'; $query = mysqli_query($con, $sql); if (!$query) { die ('SQL Error: ' . mysqli_error($con)); } ?> <html> <head> <link rel = "stylesheet" type = "text/css" href = "css/style.css"> <style> .data-table{ width: 1024px; margin-left: 150px; text-align:center; border: 1px solid firebrick; background-color: white; } td,th{ border: 1px solid firebrick; padding: 3px 2px 1px 1px; } </style> </head> <body> <div class="container"> <article> <table class="data-table"> <thead> <tr> <th>Restuarant Name</th> <th>Location</th> <th>Menu</th> </tr> <tr> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_array($query)){ $_SESSION['resphone'] = $row['resphone']; $_SESSION['restaur'] = $row['restaur']; echo '<tr> <td>'.$row['restaur'].'</td> <td>'.$row['loc'].'</td> <td style="background-color:firebrick;"><form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden"> <input type="submit" value="View"></form></td> </tr>'; } ?> </tbody> </table> </form> </article> </div> </body> </html> openmenu.php <?php include('nav.php'); ?> <html> <head> <link rel="stylesheet" href="css/style.css"> <style> table, td { border: none; text-align: center; text-align-last: center; } </style> </head> <body> <div class="container"> <article> <form method="get" align="center" action="" class="formwrap" enctype='multipart/form-data'> <h1><?php $restaur = $_SESSION['restaur']; echo $restaur ;?></h1> <h1>Call to Order:</h1> <?php $resphone = $_SESSION['resphone']; echo $resphone; ?> <br> <br> <?php $sql = "select img from owners where restaur ='$restaur'"; $result = mysqli_query($con,$sql); $row = mysqli_fetch_array($result); $image_src2 = "upload/".$row['img']; ?> <img src='<?php echo $image_src2; ?>' > </form> </article> </div> </body> </html>
Issue 1 In this snippet you are setting the session variables resphone and restaur to the values of the store you are currently iterating over. Over and over again. That's why you're only ever getting the last store's information - it's the last things you set those variables to. while ($row = mysqli_fetch_array($query)){ $_SESSION['resphone'] = $row['resphone']; $_SESSION['restaur'] = $row['restaur']; Issue 2 You should probably change the form method to get and discard the unused hidden input like so: <form method="post" action="openmenu.php?id=<?=$row['restaur']?>"> <input type="submit" value="View"> </form> Or more likely just change it a plain old a link: View Issue 3 You're completely ignoring store id requested in openmenu.php. You are using $_SESSION where you should be using $_REQUEST or $_GET. I'm not going to give an example of how you should do that. Instead, please refer to this answer before moving any further.
first you getting data from database & then use view button for openmenu.php but why u use this way <form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden"><input type="submit" value="View"></form>
Pass certain table cell values to SQL update query
I feel stuck with a bit unusual situation for me up until now ... I constructed a HTML table that shows quantities from different locations by reading and rows from SQL DB into a $locations variable that is essentially an array - here's the code: while ($location = mssql_fetch_array($locations)){ echo" <tr> <td style='text-align:center; padding-left: 2px; padding-right: 2px'>$location[1]</td> <td style='text-align:center; padding-left: 2px; padding-right: 2px'>$location[2]</td> <td width='50' style='text-align:center; padding-left: 2px; padding-right: 2px'><input type='number' style='border:none;text-align:center;' class='input' name='qty_to_add[]' type='text' value='' min='1' max='999'></td> </tr>"; }; But the real problem is how do I read only cells in the third column to the right, that have values imputed and pass only those to an update query that will further update only those rows that contain locations POL_12 (15 pcs + 5 more) and POL_54 (30 pcs + 7 more)? I need to do this in a procedural way, since I am not yet familiar with OOP and PDO (but I am striving to learn it soon) :/ Please advise, all suggestions are welcome! Thank Y'all!
In this scenario, following Barmar's advice (because it seemed most familiar to me in this moment) - using hidden fields in a form combined with for loop worked like a charm! <form method="post" enctype="multipart/form-data"> <table style="width:100%" border="2"> <tr> <th style="text-align:center; padding-left: 2px; padding-right: 2px">Location</th> <th style="text-align:center; padding-left: 2px; padding-right: 2px">Qty</th> <th style="text-align:center; padding-left: 2px; padding-right: 2px">Qty to add</th> </tr> <?php $locations = mssql_query("my query for reading item name, location and quantity per location "); while ($location = mssql_fetch_array($locations)) { echo" <tr> <input style='border:none;text-align:center;' class='input' name='location_id[]' type='hidden' value='$location[0]'> <input style='border:none;text-align:center;' class='input' name='item_id[]' type='hidden' value='$location[3]'> <td style='text-align:center; padding-left: 2px; padding-right: 2px'>$location[1]</td> <td width='2' style='text-align:center; padding-left: 2px; padding-right: 2px'><input type='number' style='border:none;text-align:center;' class='input' name='current_qty[]' type='text' value='";if (!isset($location[2])) {echo "0";} else {echo $location[2];}; echo "'></td> <td width='50' style='text-align:center; padding-left: 2px; padding-right: 2px'><input type='number' style='border:none;text-align:center;' class='input' name='qty_to_add[]' type='text' value='0' min='0' max='999'></td> </tr>"; }; ?> </table></br> <input id="post" class="search" name="submit" type="submit" value="POST" style="position: relative"></br> </form> <?php if (isset($_POST['submit'])) { $location_id = $_POST['location_id']; $ite_id = $_POST['item_id']; $curr_qty = $_POST['current_qty']; $added_qty = $_POST['qty_to_add']; $rowCount = count($_POST['location_id']); for ($i = 0; $i < $rowCount; $i++) { if ($added_qty > 0) { $query = mssql_query("update [my-table-name] set qty_per_location = cast('$curr_qty[$i]' as decimal (5,2)) + cast('$added_qty[$i]' as decimal (5,2)) where item_id = $item_id[$i] and item_location_id = $location_id[$i]"); echo "<br/><br/><span>Data inserted to DB successfully!</span>"; } } } ?> I don't want to sound disrespectful to others, that suggested possible solutions - I chose this solution merely because it was understandable for my current novice level of knowledge! Instead a big shoutout to all that sacrificed a lil' bit their time to contribute. Thank y'all!
Blank options following Correct options in html select
I created a select option and populated it with a mysqli query from the database. But there are blank options below the correct options in the dropdown menu. This is my php page with select option: <!DOCTYPE html> <!DOCTYPE html> <?php include("includes/connect.php"); function getcats_add_products(){ global $con; $get_cats="select * from categories"; $run_cats=mysqli_query($con, $get_cats); echo "<option>Select Category</option>"; while($row_cats = mysqli_fetch_array($run_cats)){ $cat_id = $row_cats['cat_id']; $cat_title = $row_cats['cat_title']; echo "<option value='$cat_id'>$cat_id, $cat_title<option>"; } } ?> <html> <head> <title>Admin Panel - Add Products</title> <link rel="stylesheet" type="text/css" href="styles/admin-style.css"> </head> <body> <header class="header"> </header> <div class="heading">Add New Product</div> <div class="product-table-div"> <form> <table class="product-table"> <tr> <td>Product Category</td> <td> <select id="product-table-input" > <?php getcats_add_products(); ?> </select> </td> </tr> <tr> <td>Product Brand</td> <td> <input type="" name="" id="product-table-input"> </td> </tr> <tr> <td>Product title</td> <td> <input type="" name="" id="product-table-input"> </td> </tr> <tr> <td>Product Price</td> <td> <input type="" name="" id="product-table-input"> </td> </tr> <tr> <td>Product description</td> <td> <input type="" name="" id="product-table-input"> </td> </tr> <tr> <td>Product image</td> <td> <input type="" name="" id="product-table-input"> </td> </tr> <tr> <td>Product Keywords</td> <td> <input type="" name="" id="product-table-input"> </td> </tr> <tr> <td colspan="2"> <div id="product-submit-div"> <input type="submit" name="submit" id="product-submit" value="Add"> </div> </td> </tr> </table>`enter code here` </form> </div> <?php getcats_add_products(); ?> </body> </html> This is the css file: header { height: 100px; background: #006b00; /* For browsers that do not support gradients */ background: -webkit-linear-gradient(#006b00, #00fa00); /* For Safari 5.1 to 6.0 */ background: -o-linear-gradient(#006b00, #00fa00); /* For Opera 11.1 to 12.0 */ background: -moz-linear-gradient(#006b00, #00fa00); /* For Firefox 3.6 to 15 */ background: linear-gradient(#006b00, #00fa00); } .heading { margin: 20px; text-align: center; width: 100%; color: #001A00; font-size: 25px; font-weight: bold; } .product-table-div { width: fit-content; margin: auto; display: block; } .product-table { table-layout: auto; height: auto; background-color: #00CC8A; } .product-table td { font-size: 20px; text-align: left; } #product-submit-div { text-align: center; max-width: 100%; } #product-submit { border: 0px; height: 100%; width: 30%; line-height: 20px; font-size: 20px; border-radius: 3px; } This is my connect page: <?php $con = mysqli_connect("localhost", "root", "root", "ecommerce"); if(!$con){ die('connection error: '.$mysqli->connect_error()); } ?> This is how the select option is looking after populating with data: Select options followed by spaces This is the table i am querying: Database table I cannot make sure if it is a mysql problem or css problem. The spaces are not between the first tag and the second. There are blank options following only the tags which i am pulling from the database.
You're missing closing tag, therefore, you get additional empty space after each option. echo "<option value='".$cat_id."'>".$cat_title."</option>"; This is the reason why you're getting empty line after each select option.
You have added two time the Start of the HTML document and that it not advisable and you have to remove that from the code. Remove two time that you have added <!DOCTYPE html> Reason for not displaying the Options in the select tag: You have not concatenated the string properly over the echo that you have added onto the select tag. Hence your select tag will not display any value in the option value and you need to change the entire function like this in order to display the values over to the option tag. Instead of using the mysqli_fetch_array() you can use the mysqli_fetch_assoc() and you can get the single row at a time in the while loop so that you can modify the data as needed. Like the same you need to follow for the mysqli_fetch_array(). mysqli_fetch_array() - Method PHP Code: <?php include("includes/connect.php"); function getcats_add_products(){ global $con; $get_cats="select * from categories"; $run_cats=mysqli_query($con, $get_cats); echo "<option>Select Category</option>"; while($row_cats = mysqli_fetch_array($run_cats)){ $cat_id = $row_cats['cat_id']; $cat_title = $row_cats['cat_title']; echo "<option value=".$cat_id.">".$cat_title."<option>"; } } ?> mysqli_fetch_assoc()- Method PHP Code: <?php include("includes/connect.php"); function getcats_add_products(){ global $con; $get_cats="select * from categories"; $run_cats=mysqli_query($con, $get_cats); echo "<option>Select Category</option>"; while($row_cats = mysqli_fetch_assoc($run_cats)){ $cat_id = $row_cats['cat_id']; $cat_title = $row_cats['cat_title']; echo "<option value=".$cat_id.">".$cat_title."<option>"; } } ?> Note: Both will follow up the same methods of the looping structure so that you can decide which one to use and both are the same as you see when it displays the output. But see to that in the above code how the concatenation is done and you have to do like this alone. And in the default way you have to pass the ID or Value in the option value and then One more parameter in the Outside of the Option value. Replace: echo "<option value='$cat_id'>$cat_id, $cat_title<option>"; With: echo "<option value=".$cat_id.">".$cat_title."<option>"; Hope so my explanation would be clear and you can rectify it for future purposes. Happy Coding :)
Using MYSQL and dropdowns
Ok I almost got a dropdown pulling from my DB and posting to it as well to work. I got it to pull down the data and for it to submit to the DB. Still a stump. If I have example "ABC Trucking" as an option. It only posts "ABC" to table1. For whatever reason it doenst post two words? Any Ideas? See where the carriername dropdown is in the div. My Code: <?php if (isset($_POST["submit"]) && $_POST["submit"] == "Submit") { for ($count = 1; $count <= 9; $count++) { $fields[$count] = ""; if (isset($_POST["field" . $count . ""])) { $fields[$count] = trim($_POST["field" . $count . ""]); //echo $fields[$count] . "<br />"; } } $con = mysql_connect("local", "user", "pass"); mysql_select_db("DB", $con); $carriername = mysql_real_escape_string($_POST['carriername']); $fromzip = mysql_real_escape_string($_POST['fromzip']); $tozip = mysql_real_escape_string($_POST['tozip']); $typeofequipment = mysql_real_escape_string($_POST['typeofequipment']); $weight = mysql_real_escape_string($_POST['weight']); $length = mysql_real_escape_string($_POST['length']); $paymentamount = mysql_real_escape_string($_POST['paymentamount']); $contactperson = mysql_real_escape_string($_POST['contactperson']); $loadtype = mysql_real_escape_string($_POST['loadtype']); $insert = "INSERT INTO table1 (`carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype`) VALUES('$carriername' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype');"; mysql_query($insert) or die(mysql_error()); $select = "SELECT `carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` FROM `table1` ORDER BY `paymentamount` DESC;"; $result = mysql_query($select) or die(mysql_error()); } ?> </script> <style ="text-align: center; margin-left: auto; margin-right: auto;"></style> </head> <body> <div style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;"> <form action="" method="post";"> <div style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br> <table style="font-weight: normal; width: 100%; font-size: 12px;" border="1" bordercolor="#929087" cellpadding="6" cellspacing="0"> <table style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;" border="1" bordercolor="#929087" cellpadding="6" cellspacing="0"> <tbody> <tr> <td style="width: 10%;">Carrier:</td><td> <?php $con = mysql_connect("local", "user", "pass"); mysql_select_db("DB", $con); $query=("SELECT * FROM table2"); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=carriername>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['carriername'].">".$row['carriername']."</OPTION>"; } echo "</select>"; ?> </td> </tr> <tr> <td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50" style="width: 100%;" type="text"> </tr> <tr> <td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50" style="width: 100%;" type="text"> </tr> <tr> <td style="width: 35%;">Load Type:</td><td> <input id="loadtype" name="loadtype" maxlength="50" style="width: 100%;" type="text"> </tr> <tr> <td style="width: 35%;">Rate:</td><td> <input id="paymentamount" name="paymentamount" maxlength="50" style="width: 100%;" type="text"> </tr> </tbody> </table> <p style="text-align: center;"><input name="submit" value="Submit" class="submit" type="submit"></p> </div> </form> </div> <p style="margin-bottom: -20px;"> </p> </body>
instead of : echo "<OPTION VALUE=".$row['carriername'].">".$row['carriername']."</OPTION>"; use this echo "<OPTION VALUE='".$row['carriername']."'>".$row['carriername']."</OPTION>"; notice ' in ur value...concate '' to your value attr.. so that it makes it a string.... EDITED echo "<select name='carriername'>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['carriername'].">".$row['carriername']."</OPTION>"; } echo "</select>";