English 中文(简体)
把2个数值从一个单一甄选标点插入MySql
原标题:Inserting 2 values to MySql from a single selection tag of drop down menu

是否有办法将两条价值观从一例下降的菜单中加到Mysql?

插入形式值的神秘q星例子如下:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO menu (food, image_extension) VALUES (%s, %s)",
GetSQLValueString($_POST[ food ], "text"),
GetSQLValueString($_POST[ image_extension ], "text"),

mysql_select_db($database_menu, $menu);
$Result1 = mysql_query($insertSQL, $menu) or die(mysql_error());

$insertGoTo = "menu.php?status=choosen";
if (isset($_SERVER[ QUERY_STRING ])) {
$insertGoTo .= (strpos($insertGoTo,  ? )) ? "" : "?";
$insertGoTo .= $_SERVER[ QUERY_STRING ];
}
header(sprintf("Location: %s", $insertGoTo));
}

I m trying to insert values of 2 columns (food & image_extension) from each selected tag of the following dropdown list to MySql but it can t insert data to image_extension column. It only update food column.

<select name="food, image extension" class="dropdownmenu" input id="food" value="<?php echo $_POST[ food ].$_POST[ image_extension ]; ?>"> 
<option value="selected="selected">Select Food</option>
<option value="Pizza, pizza.jpg">Pizza</option>
<option value="French Fry  frenchfry.jpg">French Fry</option>
</select>

I m confused about how to put values in the following three attributes of the above dropdown list properly in this case?

1. <select name="food, image extension" 
2. <select value="<?php echo $_POST[ food ].$_POST[ image_extension ]; ?>" 
3. <option value="Pizza, pizza.jpg">Pizza</option>

任何准则都应受到高度评价。

问题回答

选择不使用两种不同的名称,而只是粗略地 gr取某些菜单的价值,将其变成一个阵列。

<?php

$food = explode (",", $_POST[ food ]);

//$food[0] will equal Pizza, $food[1] will equal pizza.jpg
$insertSQL = "INSERT INTO menu (food, image_extension) VALUES ({$food[0]}, {$food[1]})";

?>

<select name="food" class="dropdownmenu" id="food">
<option value="Pizza, pizza.jpg">Pizza</option>
<option value="French Fry, frenchfry.jpg">Pizza</option>
</select>

The problem has been solved anyway with the precise guideline of an expert fellow in www.phpbuilder.com I m presenting the whole solved scenario below:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { 

//("," Comma within the double quote shall be used as delimiter here) 
$food=explode(",",$_POST[ food ]); 
$insertSQL = sprintf("INSERT INTO menu (food, image_extension) VALUES (%s, %s)", 

// The column names in the following string should be replaced by the newly created 
// array elements along with trim function to remove any unexpected white space.       

GetSQLValueString (trim($food[0]), "text"), 
GetSQLValueString (trim($food[1]), "text");

mysql_select_db($database_menu, $menu); 
$Result1 = mysql_query($insertSQL, $menu) or die(mysql_error()); 

$insertGoTo = "menu.php?status=choosen"; 
if (isset($_SERVER[ QUERY_STRING ])) { 
$insertGoTo .= (strpos($insertGoTo,  ? )) ? "" : "?"; 
$insertGoTo .= $_SERVER[ QUERY_STRING ]; 
} 
header(sprintf("Location: %s", $insertGoTo)); 
} 

html部分应改为:

 <select name="food" class="dropdownmenu" input id="food" 
 value="<?php echo  $_POST[ food ]; ?>">
 <option value="selected="selected">Select Food</option>
 <option value="Pizza, pizza.jpg">Pizza</option>
 <option value="French Fry  frenchfry.jpg">French Fry</option>
 </select>




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签