I want to export my mysql-database into a php-form, and update it, if I make any changes to the input-boxes, through the submit-button.
My main-problem is, that I want to update multiple rows at once.
Here is my code; I don't get any errors, it just doesn't work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html>
<head>
<style>
<!--
A:link {text-decoration: none; color:#005BA2}
A:visited {text-decoration: none; color:#005BA2}
A:active {text-decoration: underline; color:#FF0000}
A:hover { color: #FF0000; line-height: normal; text-decoration: underline; background-color: #FFFFFF }
input.center { text-align:center; }
body { color: #0061AE; font-size: 13px; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>
<body>
<center>
<form method="post" action="#">
<?php
// Fehlermeldungen ausschalten wegen undef. Variablen
// error_reporting(E_ERROR | E_PARSE);
// Datenbankvariablen setzen
$hostname = "localhost";
$database = "intranet";
$username = "intranet";
$password = "intranet";
$table = "arbeitsanweisungen";
// Verbindung mit Datenbank herstellen
$db_connect = mysql_connect($hostname, $username, $password);
mysql_select_db("$database") or die();
// Datenbankabfrage
$sql = "SELECT * FROM $table ORDER BY kennung";
$result = mysql_query($sql);
// Zeilen zählen
$count = mysql_num_rows($result);
?>
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Kennung</strong></td>
<td align="center"><strong><img src="images/german.jpg"></strong></td>
<td align="center"><strong><img src="images/usa.jpg"></strong></td>
<td align="center"><strong>deutscher Titel</strong></td>
<td align="center"><strong>englischer Titel</strong></td>
<td align="center"><strong>Mitarbeiter</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center">
<?php
$id[]=$rows['id']; ?><?php echo $rows['id'];
?>
</td>
<td align="center">
<input name="kennung[]" size="15" type="text" id="kennung" value="<?php echo $rows['kennung']; ?>">
</td>
<td align="center">
<input name="german[]" class="center" size="1" type="text" id="german" value="<?php echo $rows['german']; ?>">
</td>
<td align="center">
<input name="english[]" class="center" size="1" type="text" id="english" value="<?php echo $rows['english']; ?>">
</td>
<td align="center">
<input name="nameDE[]" size="50" type="text" id="nameDE" value="<?php echo $rows['nameDE']; ?>">
</td>
<td align="center">
<input name="nameEN[]" size="50" type="text" id="nameEN" value="<?php echo $rows['nameEN']; ?>">
</td>
<td align="center">
<input name="mitarbeiter[]" size="25" type="text" id="mitarbeiter" value="<?php echo $rows['mitarbeiter']; ?>">
</td>
</tr>
<br>
<?php
};
?>
</table>
<input type="submit" name="Submit" value="Submit">
<?php
if(isset($_POST['Submit'])){
$kennung = $_POST['kennung'];
$german = $_POST['german'];
$english = $_POST['english'];
$nameDE = $_POST['nameDE'];
$nameEN = $_POST['nameEN'];
$mitarbeiter = $_POST['mitarbeiter'];
for($i=0;$i<$count;$i++){
mysql_query("UPDATE $table SET kennung = '$kennung[$i]', german = '$german[$i]', english = '$english[$i]', nameDE = '$nameDE[$i]', nameEN = '$nameEN[$i]', mitarbeiter = '$mitarbeiter[$i]' WHERE id = '$id[$i]'");
}
}
// Verbindung schließen
mysql_close();
?>
</form>
</center>
</body>
</html>
In side if(isset($_POST['Submit'])){ } condition, please write following code and check again:
for($i=0;$i<$count;$i++){
mysql_query("UPDATE $table SET kennung = '".$_POST[$kennung[$i]]."', german = '".$_POST[$german[$i]]."', english = '".$_POST[$english[$i]]."', nameDE = '".$_POST[$nameDE[$i]]."', nameEN = '".$_POST[$nameEN[$i]]."', mitarbeiter = '".$_POST[$mitarbeiter[$i]]."' WHERE id = '".$id[$i]."'");
}
Don't put arrays directly into a quoted string:
mysql_query("UPDATE $table SET kennung = '$kennung[$i]', ger....")
Properly concatenate it using a .:
mysql_query("UPDATE " . $table . " SET kennung = '" . $kennung[$i] . "', ger..");
Also, enable error reporting:
<?php
// Put these lines to the top of your script
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
ini_set('xmlrpc_errors', true);
And check for mysql_last_error(); or mysql_error(); (not sure atm).
mysql_* is deprecated, use mysqli or PDO.
You need to put $rows['id'] into the form:
<td align="center">
<?php echo $rows['id'] . '<input type="hidden" name="id[]" value="' . $rows['id'] . '">';
?>
</td>
Then when you're processing the form, you have to use
$id = $_POST['id'];
if you want to update multiple rows in a single query than you need to use WHERE id IN (); in your query...
so your query will be like
UPDATE $table SET kennung = '$kennung[$i]', german = '$german[$i]', english = '$english[$i]', nameDE = '$nameDE[$i]', nameEN = '$nameEN[$i]', mitarbeiter = '$mitarbeiter[$i]' WHERE id IN ($id_array)
and your $id_array will contain all the ids which needs to be updated
like
$id_array = array(`1,2,3,4,5`);
Related
I am having an issue with my shopping cart when I add three items only the last item enters into the database. I am not sure how to get all the items to insert into the database like 3 or 4. I have tried many different ways and still come up with nothing. I still have to also figure how to get subtotal and customer name to attach to the orders
Index.php
<?php
session_start();
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "add":
if(!empty($_POST["quantity"])) {
$productByCode = $db_handle->runQuery("SELECT * FROM tblproduct WHERE code='" . $_GET["code"] . "'");
$itemArray = array($productByCode[0]["code"]=>array('name'=>$productByCode[0]["name"], 'code'=>$productByCode[0]["code"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["price"]));
if(!empty($_SESSION["cart_item"])) {
if(in_array($productByCode[0]["code"],array_keys($_SESSION["cart_item"]))) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($productByCode[0]["code"] == $k) {
if(empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
}
}
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
}
break;
case "remove":
if(!empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($_GET["code"] == $k)
unset($_SESSION["cart_item"][$k]);
if(empty($_SESSION["cart_item"]))
unset($_SESSION["cart_item"]);
}
}
break;
case "empty":
unset($_SESSION["cart_item"]);
break;
}
}
?>
<HTML>
<HEAD>
<TITLE>Simple PHP Shopping Cart</TITLE>
<link href="style.css" type="text/css" rel="stylesheet" />
</HEAD>
<BODY>
<div id="product-grid">
<div class="txt-heading">Products</div>
<?php
$product_array = $db_handle->runQuery("SELECT * FROM tblproduct ORDER BY id ASC");
if (!empty($product_array)) {
foreach($product_array as $key=>$value){
?>
<div class="product-item">
<form method="post" action="index.php?action=add&code=<?php echo $product_array[$key]["code"]; ?>">
<div class="product-image"><img src="<?php echo $product_array[$key]["image"]; ?>"></div>
<div><strong><?php echo $product_array[$key]["name"]; ?></strong></div>
<div class="product-price"><?php echo "$".$product_array[$key]["price"]; ?></div>
<div><input type="text" name="quantity" value="1" size="2" /><input type="submit" value="Add to cart" class="btnAddAction" /></div>
</form>
</div>
<?php
}
}
?>
</div>
<div id="shopping-cart">
<div class="txt-heading">Shopping Cart <a id="btnEmpty" href="index.php?action=empty">Empty Cart</a></div>
<?php
if(isset($_SESSION["cart_item"])){
$item_total = 0;
?>
<form method="post" action="process_insert.php">
<table cellpadding="10" cellspacing="1">
<tbody>
<tr>
<th style="text-align:left;"><strong>Name</strong></th>
<th style="text-align:left;"><strong>Code</strong></th>
<th style="text-align:right;"><strong>Quantity</strong></th>
<th style="text-align:right;"><strong>Price</strong></th>
<th style="text-align:center;"><strong>Action</strong></th>
</tr>
<?php
foreach ($_SESSION["cart_item"] as $item){
?>
<tr>
<td style="text-align:left;border-bottom:#F0F0F0 1px solid;" ><input type="text" name="name" value="<?php echo $item["name"]; ?>"></td>
<td style="text-align:left;border-bottom:#F0F0F0 1px solid;"><input type="text" name="code" value="<?php echo $item["code"]; ?>"></td>
<td style="text-align:right;border-bottom:#F0F0F0 1px solid;"><input type="text" name="quantity" value="<?php echo $item["quantity"]; ?>"></td>
<td style="text-align:right;border-bottom:#F0F0F0 1px solid;"><input type="text" name="price" value="<?php echo $item["price"]; ?>"></td>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">Remove Item</td>
</tr>
<?php
$item_total += ($item["price"]*$item["quantity"]);
}
?>
<tr>
<td colspan="5" align=right><strong>Total:</strong> <?php echo "$".$item_total; ?></td>
</tr>
</tbody>
</table>
<?php
}
?>
<input type="submit" name="submit" value="submit">
</form>
</div>
</BODY>
</HTML>
process_insert.php
<html>
<head>
<title></title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "blog_samples";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$sql = "INSERT INTO order_table (name, code, quantity, price)
VALUES ('".$_POST["name"]."','".$_POST["code"]."'
,'".$_POST["quantity"]."','".$_POST["price"]."')";
$query = mysqli_query($conn,$sql);
if($query) {
echo "Record add successfully";
}
mysqli_close($conn);
?>
</body>
</html>
That's because your submit form doesnt support multiple fields.
You have to add a index to each inputs' name.
<?php
$i = 0;
foreach ($_SESSION["cart_item"] as $item){
?>
<tr>
<td style="text-align:left;border-bottom:#F0F0F0 1px solid;" ><input type="text" name="name[<?php echo $i; ?>]" value="<?php echo $item["name"]; ?>"></td>
<td style="text-align:left;border-bottom:#F0F0F0 1px solid;"><input type="text" name="code[<?php echo $i; ?>]" value="<?php echo $item["code"]; ?>"></td>
<td style="text-align:right;border-bottom:#F0F0F0 1px solid;"><input type="text" name="quantity[<?php echo $i; ?>]" value="<?php echo $item["quantity"]; ?>"></td>
<td style="text-align:right;border-bottom:#F0F0F0 1px solid;"><input type="text" name="price[<?php echo $i; ?>]" value="<?php echo $item["price"]; ?>"></td>
<td style="text-align:center;border-bottom:#F0F0F0 1px solid;">Remove Item</td>
</tr>
<?php
$item_total += ($item["price"]*$item["quantity"]);
$i++;
}
?>
process_insert.php
<html>
<head>
<title></title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "blog_samples";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$rows_count = count($_POST["name"]);
for($i=0;$i<$rows_count;$i++){
// PREVENTING SQL INJECTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$name = mysqli_real_escape_string($conn,$_POST["name"][$i]);
$code = mysqli_real_escape_string($conn,$_POST["code"][$i]);
$quantity = intval($_POST["quantity"][$i]);
$price = mysqli_real_escape_string($conn,$_POST["price"][$i]);
$sql = "INSERT INTO order_table (name, code, quantity, price)
VALUES ('$name','$code','$quantity','$price')";
$query = mysqli_query($conn,$sql);
}
if(mysqli_affected_rows($conn)>0) {
echo "Record add successfully";
}
mysqli_close($conn);
?>
</body>
</html>
I'm having trouble setting up some css code for a table I'm generating using php from a database. I want every even row to have a different background-color, so I tried using nth-child(even) for this, but it doesn't seem to work for some reason. Here's my code:
style.css:
#usertable {
border-collapse: collapse;
font-family: "Trebuchet MS", Arial;
}
#usertable td, #usertable th {
border: 1px solid black;
background-color: rgb(228,227,227);
padding: 8px;
}
#usertable tr:nth-child(odd){background-color: rgb(115,115,115);}
admin.php:
<table id="usertable">
<tr>
<th> Id: </th>
<th> Username: </th>
<th> Rights: </th>
</tr>
<?php
$userquery = "SELECT id, username, strength FROM users";
$result = $conn->query($userquery) or die($conn->error);
while ($row = $result->fetch_assoc()) { ?>
<tr>
<td> <?php echo $row['id']; ?> </td>
<td> <?php echo $row['username']; ?> </td>
<td>
<form method="post" action="">
<input type="number" min="0" max="255" name="newrights" value=" <?php echo $row['strength']; ?> ">
<input type="text" name="idnumber" hidden="true" value=" <?php echo $row['id']; ?> ">
<input type="text" name="usertochange" hidden="true" value=" <?php echo $row['username']; ?> ">
<input type="submit" value="Update">
</form>
</td>
</tr>
<?php
}
?>
</table>
There is some markup error with your code
<table id="usertable">
<tr> <!--Add this-->
<th> Id: </th>
<th> Username: </th>
<th> Rights: </th>
</tr> <!--Add this-->
<?php
$userquery = "SELECT id, username, strength FROM users";
$result = $conn->query($userquery) or die($conn->error);
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['username'] . "</td><td>";
echo "<form method=\"post\" action=\"\">
<input type=\"number\" min=\"0\" max=\"255\" name=\"newrights\" value=\"" . $row['strength'] . "\">
<input type=\"text\" name=\"idnumber\" hidden=\"true\" value=\"" . $row['id'] . "\">
<input type=\"text\" name=\"usertochange\" hidden=\"true\" value=\"" . $row['username'] . "\">
<input type=\"submit\" value=\"Update\">
</form></td></tr>";
}
?>
Also looks like you have used many slaces so i suggest you to check table markup on browser
Updated: Add
#usertable td:nth-child(odd) { background-color: #efefef;}
Do not use tr as you have given background color to td and th initially
Why don't you sue some CSS class in each alternate table row?
Ex:
HTML
<tr class="bg-red">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr class="bg-blue">
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
CSS
<style type="text/css">
.bg-blue{
background-color: blue;
}
.bg-red{
background-color: red;
}
</style>
I think this will simplify your code & make it easy to read.
Example for Dynamic Data
<?php
$users[] = array('fname'=>'Jill', 'lname'=>'Smith', 'age'=>50);
$users[] = array('fname'=>'Eve', 'lname'=>'Jackson', 'age'=>94);
$rowColClass = 'bg-blue';
foreach ($users as $key => $value)
{
echo "<tr class='$rowColClass'>";
echo "<td>$value[fname]</td>";
echo "<td>$value[lname]</td>";
echo "<td>$value[age]</td>";
echo "</tr>";
if($rowColClass == 'bg-blue')
$rowColClass = 'bg-red';
else
$rowColClass = 'bg-blue';
}
?>
I took over a job from a friend. Now I am working on a MVC, I have made a Form that looks like his:
<form method="post" action="QA/public/index.php?controller=QA&action=shabUpdate">
<table class="clean">
{data}
<tr style="display:{display};">
<td class="label">Specific:</td>
<td>{remarks}</td>
</tr>
</table>
{back}
<input type="submit" />
</form>
In my controller I made the following shabUpdateAction:
protected function shabUpdateAction()
{
$_POST['titel'] = $_POST['titel'];
/*$_POST['inspectie'] = 'so sorry';
$_POST['extraDocument'] = 'newIMG';*/
$this->dbh->setShab($_POST, $_POST['partId']);
$_SESSION['page'] = './QA/public/index';
$_SESSION['getIndex'] = '?controller=QA&action=showInspectionDocument&templateId='.$_POST['templateId'];
header('Location: http://stuffff/something/');
exit();
}
this is suppose to update my form and when I visit the form page I should be able to see the new information (new changes that was made).
However the update action doesn't work and it doesn't redirect to a correct page.
this is the part from my Model:
public function updateSshab($sdr)
{
$sql = "UPDATE `qa_template`
SET `inspection_requirement` = :requirement
WHERE `part_id` = :partId AND `title` = :title;";
$statement = $this->dbh->prepare($sql);
$statement->bindParam(':requirement', $sdr['defectDescription']);
$statement->bindParam(':partId', $sdr['partId']);
$statement->bindValue(':title', 'SDR nummer: SDR' .$sdr['nr']);
$statement->execute();
}
and finally my view:
public function renderShowInspectionDocument()
{
setLastPage();
$dochtml = '';
$url = str_replace(end(explode('/', $_SERVER['HTTP_REFERER'])), '', $_SERVER['HTTP_REFERER']);
//Template
$template = file_get_contents('templates/inspectionDetails.tpl');
//shab
if(isset($this->data['shab']))
{
$shab= $this->data['shab'];
$dochtml .= '
<tr>
<td class="label">Inspection:</td>
<td>
<input type="hidden" name="templateId" value="'.$shab['id'].'" />
<div id="testDiv" style="width:420px; font-weight:normal; border-left:1px solid black; border-bottom:1px solid black; padding:5px;">'. nl2br($shab['inspection_requirement']) .'</div>
<div id="testDiv2" style="display=none">
<textarea name="inspection" class="width">'. nl2br($shab['inspection_requirement']) .'</textarea>
</div>
</td>
</tr>
<tr>
<td class="label">Inspection-tools:</td>
<td>
<input type="hidden" name="templateId" value="'.$shab['id'].'" />
<div id="testDiv22" style="width:420px; font-weight:normal; border-left:1px solid black; border-bottom:1px solid black; padding:5px;">'. nl2br($shab['inspection_resources']) .'</div>
<div id="testDiv222" style="display=none">
<textarea name="InspectieResources" class="width">'. nl2br($shab['inspection_resources']) .'</textarea>
</div>
</td>
</tr>
';
}
$template = str_replace('{data}', $dochtml, $template);
$template = str_replace('{terug}', backButtonQA(), $template);
$template = str_replace('{display}', 'none', $template);
echo $template;
}
my update function doesn't work correctly. I didn't write nu I am working on it and I cant seem to figure out the problem with update Action, is there something I am missing??
I have a page that seems to work fine other than updating new text to the database. Everytime I hit submit it just takes it back to the original data. Please let me know what is missing for this to successfully query old data and update new data.
if (isset($_POST["submit"]) && $_POST["submit"] == "Update Load")
{
for ($count = 1; $count <= 6; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$carriername = mysql_real_escape_string($_POST['carriername']);
$contact = mysql_real_escape_string($_POST['contact']);
$phone = mysql_real_escape_string($_POST['phone']);
$rating = mysql_real_escape_string($_POST['rating']);
$info = mysql_real_escape_string($_POST['info']);
$insert = "UPDATE carrierinfo Set `carriername` = '$carriername', `contact` = '$contact', `phone` = '$phone', `rating` = '$rating', `info` = '$info' WHERE `id` = '$id';";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`contact` ,`phone` ,`rating` ,`info` ,`id` FROM `carrierinfo` ORDER BY `carriername` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
if ($rating == "")
{
$rating = "3";
}
if (isset($_GET["id"]))
{
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$id = mysql_real_escape_string($_GET["id"]);
$select = "SELECT * FROM `carrierinfo` WHERE `id` = '$id'";
$result = mysql_query($select) or die(mysql_error());
$fields = mysql_fetch_array($result, MYSQL_BOTH);
mysql_close($con);
}
else
{
header("Location:board.php");
}
?>
</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: 35%;">Carrier Name:</td><td><input id="carriername" name="carriername" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[carriername]; ?>">
</tr>
<tr>
<td style="width: 35%;">Contact:</td><td><input id="contact" name="contact" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[contact]; ?>">
</tr>
<tr>
<td style="width: 35%;">Phone:</td><td><input id="phone" name="phone" maxlength="50" style="width: 100%;" type="text" value="<?php echo $fields[phone]; ?>">
</tr>
<tr>
<td style="width: 10%;">Carrier Rating:</td><td>
<select id="rating" name="rating">
<option value=""></option>
<option <?php if($fields[rating] == "1") echo "selected"; ?> value="1">1</option>
<option <?php if($fields[rating] == "2") echo "selected"; ?> value="2">2</option>
<option <?php if($fields[rating] == "3") echo "selected"; ?> value="3">3</option>
<option <?php if($fields[rating] == "4") echo "selected"; ?> value="4">4</option>
<option <?php if($fields[rating] == "5") echo "selected"; ?> value="5">5</option>
</select>
</td>
</tr>
<tr>
<td style="width: 10%;">Carrier Info:</td><td style="text-align: center;" colspan="2"><textarea name="info" maxlength="65535" style="width: 100%; height: 4em;"><?php echo $fields[info]; ?></textarea></td>
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Update"
class="submit" type="submit"></p>
</div>
</form>
<input type="button" onclick="window.location.href='test3.php';" value="Back" />
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
$insert = "UPDATE carrierinfo Set `carriername` = '$carriername', `contact` = '$contact', `phone` = '$phone', `rating` = '$rating', `info` = '$info' **WHERE `id` = '$id';**";
You haven't declared what $id should be before running your UPDATE query so nothing is being updated.
You are looking for
$_POST["submit"] == "Update Load"
but the value of your submit button is "Update", not "Update Load".
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>";