问题描述
因此,当我点击< input type =button/>
时,我正在使用一个掩码来过滤数据。
我有:
- 学校课程(1,2,3,4 ,5)
- 部分(A,B,C .... Z)
- 和性复选框(男,女)。
这个掩码与mysql数据库交互,所以如果选中的唯一一个复选框是male,它应该让我回到所有的我的数据库中有男性。问题是我使用javascript来过滤性别,并使我的性别字符串,我不知道如何将它传递给一个PHP变量使用它在我的查询。
我在网上查找了3-4天,并且都推荐使用$ _POST。如果我使用$ _POST它说变量是未定义的。我在互联网上搜索这个错误,并说它用isset添加一个控件。我已经这样做了,但似乎没有任何工作,因为它给了我一个新的错误未定义的索引。
所以我需要将一个javascript变量的值传递给一个php变量(我知道这很难,因为javascript是客户端,php是服务器端)或直接传递我的textarea文本(我可以在textarea中显示我的javascript结果)到一个php变量。
有人可以帮我吗?
这是我的index.php:
<?php
require'connection.php'
?>
< html>
< script src =scripts.js>< / script>
< form name =codemethod =postaction =query.php;<?php echo htmlspecialchars($ _ SERVER [PHP_SELF]);?>>
< table border =0>
<! - ROW1 - >
< tr>
Da codice
< input type =textname =dacode>
a codice
< input type =textname =acode>
< / tr>
< / form>
< form id =sexformname =sexform>
< tr>
< td>< / td>
< td>
Sesso
< input type =checkboxname =sexvalue =Maschio> M
< input type =checkboxname =sexvalue =Femmina> F
< input type =checkboxname =sexvalue =Azienda> G
< input type =hiddenid =xxx>
< / form>
< br>
Da data nascita
< input type =datename =dadatamin =1980-01-01>
a data nascita
< input type =datename =adatamin =1980-01-01>
< form id =sezformname =sezform>
< br>
Sezioni
< input type =checkboxname =sezvalue =A> A
< input type =checkboxname =sezvalue =B> B
< input type =checkboxname =sezvalue =C> C
< input type =checkboxname =sezvalue =D> D
< input type =checkboxname =sezvalue =E> E
< input type =checkboxname =sezvalue =F> F
< input type =checkboxname =sezvalue =G> G
< input type =checkboxname =sezvalue =H> H
< input type =checkboxname =sezvalue =I> I
< input type =checkboxname =sezvalue =J> J
< input type =checkboxname =sezvalue =K> K
< input type =checkboxname =sezvalue =L> L
< input type =checkboxname =sezvalue =M> M
< input type =checkboxname =sezvalue =N> N
< input type =checkboxname =sezvalue =O> O
< input type =checkboxname =sezvalue =P> P
< input type =checkboxname =sezvalue =Q> Q
< input type =checkboxname =sezvalue =R> R
< input type =checkboxname =sezvalue =S> S
< input type =checkboxname =sezvalue =T> T
< input type =checkboxname =sezvalue =U> U
< input type =checkboxname =sezvalue =V> V
< input type =checkboxname =sezvalue =W> W
< input type =checkboxname =sezvalue =X> X
< input type =checkboxname =sezvalue =Y> Y
< input type =checkboxname =sezvalue =Z> Z
< br>
< input type =checkboxname =sezvalue =Ai> Ai
< input type =checkboxname =sezvalue =Am> Am
< input type =checkboxname =sezvalue =Ae> Ae
< input type =checkboxname =sezvalue =Bi> Bi
< input type =checkboxname =sezvalue =Be> Be
< input type =checkboxname =sezvalue =Bm> Bm
< / form>
< form id =claformname =claform>
< br>
Sezioni
< input type =checkboxname =clavalue =1> 1
< input type =checkboxname =clavalue =2> 2
< input type =checkboxname =clavalue =3> 3
< input type =checkboxname =clavalue =4> 4
< input type =checkboxname =clavalue =5> 5
< br>
< br>
RESULT STRING
< textarea type =textname =outputfieldid =outputfield> < / textarea的>
< input type =buttononclick =myFunction(); selectValues(); query();值= Invia >
< / td>
< / tr>
< / form>
< br>
< br>
< / html>
这是我的query.php文件:
<?php
require'connection.php';
// Inizio selezione
$ usedatabase =use。 $ DBNAME;
if(isset($ _ POST ['xxx'])){
$ queryfinale =select * from sergiodellera.mskselez where sesso ='。 $ _POST ['xxx']。 ';
$ b // $ final1 = mysql_query($ usedatabase)或die(mysql_error());
// $ final2 = mysql_query($ queryfinale)或die(mysql_error());
// $ query = mysql_query($ queryfinale);
// $ row = mysql_fetch_row($ query);
// $ final2 = $ row [5];
echo $ queryfinale;
?>
这是我的js文件:
function myFunction(){
var sex = document.forms [sexform];
var sez = document.forms [sezform];
var cla = document.forms [claform];
var txt =;
var txtsex =;
var txtsez =;
var txtcla =;
var isex;
var isez;
var icla;
//对于性别
for(isex = 0; isex< sex.length; isex ++){
if(sex [isex] .checked){
txtsex = txtsex +性[isex]。价值;
//对于SEZ
(isez = 0; isez< sez.length; isez ++){
if(sez [ isez] .checked){
txtsez = txtsez + sez [isez] .value;
//对于CLA
(icla = 0; icla< cla.length; icla ++){
if(cla [icla] .checked ){
txtcla = txtcla + cla [icla] .value;
}
}
txtsex = txtsex;
txtsez = txtsez +;;
txtcla = txtcla +;;
txt = txtsex + txtsez + txtcla;
for(sexfor = 0; sexfor< txtsex.length; sexfor ++){
if(txtsex.length = 22){
var asex = txtsex;
var bsex = asex.substring(0,1);
var csex = asex.substring(7,8);
var dsex = asex.substring(14,15);
if(txtsex.length = 15){
var asex = txtsex;
var bsex = asex.substring(0,1);
var csex = asex.substring(7,8);
if(txtsex.length = 8){
var asex = txtsex;
var bsex = asex.substring(0,1);
}
break;
}
sexcontainer = bsex + csex + dsex;
document.getElementById(outputfield)。value = sexcontainer;
// myFunction()
}
函数selectValues(){
document.getElementById('xxx')。value = sexcontainer;
返回true;
}
函数query(){window.open(query.php);
}
我期待如果我检查例如男性和女性复选框,会有一个像MF的字符串。所以,通过一个php变量,我会有 select * from tablename where sex = $ varsex
其中varsex是MF
隐藏的输入将被你的php选为 $ _ POST ['all_sexes']
,你可以为其他项目做类似的事情。困难的一点可能是通过unclick或改变主意来编辑结果。
您可以以类似的方式在文本框中使用onKeyPress事件。我建议将它们全部放在一起,因为它们全部一起提交。
这是JavaScript:
< script language =javascript>
var all_sexes;
var sex;
函数make_sex(sex){
var sexes = document.getElementById('all_sexes')。value
if(sex ==Maschio){sex ='M' ;}
if(sex ==Femmina){sex ='F';}
if(sex ==Azienda){sex ='G';}
if( sexes.indexOf(sex)> -1){sex ='';} //如果未选中并在此处检查,则处理该做什么
all_sexes = document.getElementById('all_sexes')。value + sex;
document.getElementById('all_sexes')。value = all_sexes;
document.getElementById('outputfield')。value = all_sexes;
}
< / script>
然后在onClick事件中调用该复选框中的函数,并将该复选框的值传递给它。
Sesso
< input type =checkboxname =sexvalue =Femminaonclick =make_sex(this.value)> F
< input type =checkboxname =sexvalue =Aziendaonclick =make_sex(this.value)> G
< input type =hiddenname =all_sexesid =all_sexesvalue =>
html调试器对跨度外的某些文本不满意,但我不是在这里查看不管你做什么,都不要将任何POST变量内容放在你的数据库附近的任何地方,而不需要进行消毒处理 - 参见本页底部的注释
不是当然,如果你真的需要在页面上显示点击结果 - 如果你不这样做,并且只想要提交的值,这将是一个更好的方法 - 从接受的答案
<$ p $ ($ stuff)($ stuff)$ b $ echo $ thing($ stuff $ as $)$ {$ b $ if $($ stuff) 。 < br />;
}
} else {
echo $ stuff。< br />;
$ / code $ / pre
$ b $ p这是你的html,可以让你快速演示它的功能 - 你的PHP脚本显示在这里的底部将在你的query.php
有很多html错误,其中文本不在表格元素调试器所抱怨的 - 有太多的实例需要在这里修复,或许你应该看看不同的结构,而不是为你的框架使用表格而不是divs。
<!DOCTYPE html>
< html>
< form name =codemethod =postaction =<?php echo htmlspecialchars($ _ SERVER [REQUEST_URI]);?>>
< table border =0>
<! - ROW1 - >
< tr>
Da codice
< input type =textname =dacode>
a codice
< input type =textname =acode>
< / tr>
<! - ROW2 - >
< br />
Sesso
< / tr>
< tr>
< input type =checkboxname =Maschioid =Maschiovalue =Maschio> M
< input type =checkboxname =Femminaid =Femminavalue =Femmina> F
< input type =checkboxname =Aziendaid =Aziendavalue =Azienda> G
<! - ROW3 - >
< br>
Da data nascita
< input type =datename =dadatamin =1980-01-01>
a data nascita
< input type =datename =adatamin =1980-01-01>
< br>
Sezioni
< input type =checkboxname =Avalue =A> A
< input type =checkboxname =Bvalue =B> B
< input type =checkboxname =Cvalue =C> C
< input type =checkboxname =Dvalue =D> D
< input type =checkboxname =Evalue =E> E
< input type =checkboxname =Fvalue =F> F
< input type =checkboxname =Gvalue =G> G
< input type =checkboxname =Hvalue =H> H
< input type =checkboxname =Ivalue =I> I
< input type =checkboxname =Jvalue =J> J
< input type =checkboxname =Kvalue =K> K
< input type =checkboxname =Lvalue =L> L
< input type =checkboxname =Mvalue =M> M
< input type =checkboxname =Nvalue =N> N
< input type =checkboxname =Ovalue =O> O
< input type =checkboxname =Pvalue =P> P
< input type =checkboxname =Qvalue =Q> Q
< input type =checkboxname =Rvalue =R> R
< input type =checkboxname =Svalue =S> S
< input type =checkboxname =Tvalue =T> T
< input type =checkboxname =Uvalue =U> U
< input type =checkboxname =Vvalue =V> V
< input type =checkboxname =Wvalue =W> W
< input type =checkboxname =Xvalue =X> X
< input type =checkboxname =Yvalue =Y> Y
< input type =checkboxname =Zvalue =Z> Z
< br>
< input type =checkboxname =Aivalue =Ai> Ai
< input type =checkboxname =Amvalue =Am> Am
< input type =checkboxname =Aevalue =Ae> Ae
< input type =checkboxname =Bivalue =Bi> Bi
< input type =checkboxname =Bevalue =Be> Be
< input type =checkboxname =sezvalue =Bm> Bm
< input type =hiddenid =all_Bnvalue =>
< br>
Sezioni
< input type =checkboxname =Chk1value =1> 1
< input type =checkboxname =Chk2value =2> 2
< input type =checkboxname =Chk3value =3> 3
< input type =checkboxname =Chk4value =4> 4
< input type =checkboxname =Chk5value =5> 5
< / form>
< br>
< br>
RESULT STRING
< textarea type =textname =outputfieldid =outputfield> < / textarea的>
< input type =submitname =submitvalue =Invia>
< / td>
< / tr>
< / form>
< br>
< br>
<?php
foreach($ _POST as $ stuff){
if(is_array($ stuff)){
foreach($ stuff as $ thing){
回声$的东西。 < br />;
}
} else {
echo $ stuff。< br />;
}
}
?>
< / html>
其他一些借用和轻微修改的想法可能有助于处理表单发送的数据:
foreach(array_keys($ _ POST))$ b
这个将只显示你设置的内容和它的名字和值:
foreach作为$ key){echo htmlspecialchars($ key)。 。 htmlspecialchars($ _ POST [$ key])。 < br />;}
这个应该可以逃脱它(你需要)
$ b $ pre $ foreach(array_keys($ _ POST)as $ key){$ _POST [$ key] = mysqli_real_escape_string($ _ POST [$ key]); echo htmlspecialchars($ key)。 。 htmlspecialchars($ _ POST [$ key]);}
要从A到Z复选框收集结果成一个字符串,他们已经被检查过,这可能会起作用,并且具有这样的优点,即您不会将提交的值中的任何内容放入字符串中。
$ abc ='';
$ abc_cnt ='A';
while($ abc_cnt1 if(isset($ _ POST [$ abc_cnt])){
$ abc = $ abc。 $ abc_cnt;
}
$ abc_cnt ++;
$ abc_cnt1 ++;
}
echo $ abc; //你的Sezzioni的结果字符串
这同样适用于你想要放入字符串 - 例如,如果所有的Sesso复选框都被点击,您将获得MFG,或者您可能有M和G或F和G.
if(isset($ _ POST ['Maschio']))$ sesso = $ sesso。 M;
if(isset($ _ POST ['Femmina']))$ sesso = $ sesso。 'F';
if(isset($ _ POST ['Azienda']))$ sesso = $ sesso。 'G';
So, I'm working on a mask which filters the data when <input type="button" />
is clicked.
I have:
- school classes(1, 2, 3, 4, 5)
- sections (A, B, C....Z)
- and sex checkboxes (male, female).
This mask interacts with a mysql database, so if the only one checkbox checked is "male", it should give me back all the males in my database. The problem is that I used javascript to filter sexes and to make my string of sexes and I don't know how to pass it to a php variable to use it on my query.
I've been looking online for 3-4 days and all recommend to use $_POST. If I use $_POST it says that the variable is undefined. I searched for this error on the internet and it says to add a control with isset. I've done this but nothing seems to work because it gives me a new error "undefined index".
So I need help for passing the value of a javascript variable to a php variable (I know it's hard because javascript is client side and php is server side) or directly pass my textarea text (I can display my javascript result in a textarea) to a php variable.
May someone help me?
Here is my index.php:
<?php
require 'connection.php'
?>
<html>
<script src="scripts.js"></script>
<form name="code" method="post" action="query.php; <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table border="0">
<!-- ROW1 -->
<tr>
Da codice
<input type="text" name="dacode">
a codice
<input type="text" name="acode">
</tr>
</form>
<!-- ROW2 -->
<form id="sexform" name="sexform">
<tr>
<td></td>
<td>
Sesso
<input type="checkbox" name="sex" value="Maschio"> M
<input type="checkbox" name="sex" value="Femmina"> F
<input type="checkbox" name="sex" value="Azienda"> G
<input type="hidden" id="xxx">
</form>
<!-- ROW3 -->
<br>
Da data nascita
<input type="date" name="dadata" min="1980-01-01">
a data nascita
<input type="date" name="adata" min="1980-01-01">
<!-- ROW4 -->
<form id="sezform" name="sezform">
<br>
Sezioni
<input type="checkbox" name="sez" value="A"> A
<input type="checkbox" name="sez" value="B"> B
<input type="checkbox" name="sez" value="C"> C
<input type="checkbox" name="sez" value="D"> D
<input type="checkbox" name="sez" value="E"> E
<input type="checkbox" name="sez" value="F"> F
<input type="checkbox" name="sez" value="G"> G
<input type="checkbox" name="sez" value="H"> H
<input type="checkbox" name="sez" value="I"> I
<input type="checkbox" name="sez" value="J"> J
<input type="checkbox" name="sez" value="K"> K
<input type="checkbox" name="sez" value="L"> L
<input type="checkbox" name="sez" value="M"> M
<input type="checkbox" name="sez" value="N"> N
<input type="checkbox" name="sez" value="O"> O
<input type="checkbox" name="sez" value="P"> P
<input type="checkbox" name="sez" value="Q"> Q
<input type="checkbox" name="sez" value="R"> R
<input type="checkbox" name="sez" value="S"> S
<input type="checkbox" name="sez" value="T"> T
<input type="checkbox" name="sez" value="U"> U
<input type="checkbox" name="sez" value="V"> V
<input type="checkbox" name="sez" value="W"> W
<input type="checkbox" name="sez" value="X"> X
<input type="checkbox" name="sez" value="Y"> Y
<input type="checkbox" name="sez" value="Z"> Z
<br>
<input type="checkbox" name="sez" value="Ai"> Ai
<input type="checkbox" name="sez" value="Am"> Am
<input type="checkbox" name="sez" value="Ae"> Ae
<input type="checkbox" name="sez" value="Bi"> Bi
<input type="checkbox" name="sez" value="Be"> Be
<input type="checkbox" name="sez" value="Bm"> Bm
</form>
<!-- ROW5 -->
<form id="claform" name="claform">
<br>
Sezioni
<input type="checkbox" name="cla" value="1"> 1
<input type="checkbox" name="cla" value="2"> 2
<input type="checkbox" name="cla" value="3"> 3
<input type="checkbox" name="cla" value="4"> 4
<input type="checkbox" name="cla" value="5"> 5
<br>
<br>
RESULT STRING
<textarea type="text" name="outputfield" id="outputfield"> </textarea>
<input type="button" onclick="myFunction(); selectValues(); query();" value="Invia">
</td>
</tr>
</form>
<br>
<br>
</html>
This is my query.php file:
<?php
require 'connection.php';
// Inizio selezione
$usedatabase = "use " . $dbname;
if (isset($_POST['xxx'])) {
$queryfinale = "select * from sergiodellera.mskselez where sesso='" . $_POST['xxx'] . "'" ;
}
//$final1 = mysql_query($usedatabase) or die(mysql_error());
//$final2 = mysql_query($queryfinale) or die(mysql_error());
//$query = mysql_query($queryfinale);
//$row = mysql_fetch_row($query);
//$final2 = $row[5];
echo $queryfinale;
?>
and this is my js file:
function myFunction() {
var sex = document.forms["sexform"];
var sez = document.forms["sezform"];
var cla = document.forms["claform"];
var txt = "";
var txtsex = "";
var txtsez = "";
var txtcla = "";
var isex;
var isez;
var icla;
//FOR SEX
for (isex = 0; isex < sex.length; isex++) {
if (sex[isex].checked) {
txtsex = txtsex + sex[isex].value;
}
}
//FOR SEZ
for (isez = 0; isez < sez.length; isez++) {
if (sez[isez].checked) {
txtsez = txtsez + sez[isez].value;
}
}
//FOR CLA
for (icla = 0; icla < cla.length; icla++) {
if (cla[icla].checked) {
txtcla = txtcla + cla[icla].value;
}
}
txtsex = txtsex;
txtsez = txtsez + ";";
txtcla = txtcla + ";";
txt = txtsex + txtsez + txtcla;
for (sexfor = 0; sexfor < txtsex.length; sexfor++) {
if (txtsex.length = 22){
var asex = txtsex;
var bsex = asex.substring(0, 1);
var csex = asex.substring(7, 8);
var dsex = asex.substring(14, 15);
}
if (txtsex.length = 15){
var asex = txtsex;
var bsex = asex.substring(0, 1);
var csex = asex.substring(7, 8);
}
if (txtsex.length = 8){
var asex = txtsex;
var bsex = asex.substring(0, 1);
}
break;
}
sexcontainer = bsex + csex + dsex;
document.getElementById("outputfield").value = sexcontainer;
//myFunction()
}
function selectValues(){
document.getElementById('xxx').value = sexcontainer;
return true;
}
function query() { window.open("query.php");
}
I'm expecting that if i check for example male and female checkboxes i'll have a string like "MF". So, through a php variable i'm gonna have select * from tablename where sex=$varsex
where varsex is MF
(This was a basic work in progress which has only a limited amount of functionality which I will attempt to improve if I have the time - it may still have technical faults - it is only intended to give an indication of what I think is needed - you will need to sort the results.)
The hidden input will be picked up by your php as $_POST['all_sexes']
and you could do something similar for other items. The difficult bit might be to edit the result on an "unclick" or change of mind.
You could use an onKeyPress event for the textboxes in a similar way. I would suggest putting it all in one form as it is all being submitted together.
This is the JavaScript:
<script language="javascript">
var all_sexes;
var sex;
function make_sex(sex){
var sexes = document.getElementById('all_sexes').value
if(sex == "Maschio"){sex = 'M';}
if(sex == "Femmina"){sex = 'F';}
if(sex == "Azienda"){sex = 'G';}
if( sexes.indexOf(sex) >-1){ sex = '';} // working on what to do if unchecked and checked here
all_sexes = document.getElementById('all_sexes').value + sex;
document.getElementById('all_sexes').value = all_sexes;
document.getElementById('outputfield').value = all_sexes;
}
</script>
And call the function in your checkbox with an onClick event passing it the value of the checkbox.
Sesso
<input type="checkbox" name="sex" value="Maschio" onclick="make_sex(this.value)"> M
<input type="checkbox" name="sex" value="Femmina" onclick="make_sex(this.value)"> F
<input type="checkbox" name="sex" value="Azienda" onclick="make_sex(this.value)"> G
<input type="hidden" name="all_sexes" id="all_sexes" value="">
The html debugger is not happy with some text outside of spans but I am not here to look at that right now.
And, whatever you do do not put any POST variable content anywhere near your database without sanitizing it - see comments at the bottom of this page php registration form complication
Not sure if you actually need to display the click result on the page - if you don't and just want the submitted values this would be a much better approach - borrowed from PHP how to loop through a post array the accepted answer
foreach( $_POST as $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $thing ) {
echo $thing . "<br />";
}
} else {
echo $stuff ."<br />";
}
}
This is your html adapted to give you a quick demonstration of what it does - your php script shown here at the bottom would be on your query.php
There are a number of html errors where text is outside of the table elements which the debugger complains about - there are too many instances to fix here and perhaps you should be looking at a different structure rather than using tables for your framework as opposed to divs.
<!DOCTYPE html>
<html>
<form name="code" method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]);?>">
<table border="0">
<!-- ROW1 -->
<tr>
Da codice
<input type="text" name="dacode">
a codice
<input type="text" name="acode">
</tr>
<!-- ROW2 -->
<br />
Sesso
</tr>
<tr>
<input type="checkbox" name="Maschio" id="Maschio" value="Maschio" > M
<input type="checkbox" name="Femmina" id="Femmina" value="Femmina" > F
<input type="checkbox" name="Azienda" id="Azienda" value="Azienda" > G
<!-- ROW3 -->
<br>
Da data nascita
<input type="date" name="dadata" min="1980-01-01">
a data nascita
<input type="date" name="adata" min="1980-01-01">
<!-- ROW4 -->
<br>
Sezioni
<input type="checkbox" name="A" value="A"> A
<input type="checkbox" name="B" value="B"> B
<input type="checkbox" name="C" value="C"> C
<input type="checkbox" name="D" value="D"> D
<input type="checkbox" name="E" value="E"> E
<input type="checkbox" name="F" value="F"> F
<input type="checkbox" name="G" value="G"> G
<input type="checkbox" name="H" value="H"> H
<input type="checkbox" name="I" value="I"> I
<input type="checkbox" name="J" value="J"> J
<input type="checkbox" name="K" value="K"> K
<input type="checkbox" name="L" value="L"> L
<input type="checkbox" name="M" value="M"> M
<input type="checkbox" name="N" value="N"> N
<input type="checkbox" name="O" value="O"> O
<input type="checkbox" name="P" value="P"> P
<input type="checkbox" name="Q" value="Q"> Q
<input type="checkbox" name="R" value="R"> R
<input type="checkbox" name="S" value="S"> S
<input type="checkbox" name="T" value="T"> T
<input type="checkbox" name="U" value="U"> U
<input type="checkbox" name="V" value="V"> V
<input type="checkbox" name="W" value="W"> W
<input type="checkbox" name="X" value="X"> X
<input type="checkbox" name="Y" value="Y"> Y
<input type="checkbox" name="Z" value="Z"> Z
<br>
<input type="checkbox" name="Ai" value="Ai"> Ai
<input type="checkbox" name="Am" value="Am"> Am
<input type="checkbox" name="Ae" value="Ae"> Ae
<input type="checkbox" name="Bi" value="Bi"> Bi
<input type="checkbox" name="Be" value="Be"> Be
<input type="checkbox" name="sez" value="Bm"> Bm
<input type="hidden" id="all_Bn" value="">
<!-- ROW5 -->
<br>
Sezioni
<input type="checkbox" name="Chk1" value="1"> 1
<input type="checkbox" name="Chk2" value="2"> 2
<input type="checkbox" name="Chk3" value="3"> 3
<input type="checkbox" name="Chk4" value="4"> 4
<input type="checkbox" name="Chk5" value="5"> 5
</form>
<br>
<br>
RESULT STRING
<textarea type="text" name="outputfield" id="outputfield"> </textarea>
<input type="submit" name="submit" value="Invia">
</td>
</tr>
</form>
<br>
<br>
<?php
foreach( $_POST as $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $thing ) {
echo $thing . "<br />";
}
} else {
echo $stuff ."<br />";
}
}
?>
</html>
A couple of other borrowed and slighty modified ideas which might help with handling the data sent by your form from:mysql_escape_string whole post array?
This one will just display what you set and its name and value:
foreach(array_keys($_POST) as $key){ echo htmlspecialchars($key) . " " . htmlspecialchars($_POST[$key]) . "<br />";}
And this one is supposed to escape it (you need to be logged in to your sql session):
foreach(array_keys($_POST) as $key){ $_POST[$key] = mysqli_real_escape_string($_POST[$key]); echo htmlspecialchars($key) . " " . htmlspecialchars($_POST[$key]);}
To collect the results from the A to Z checkboxes into a string where they have been checked this might work and has the advantage that you are not putting anything from the submitted value into your string.
$abc = '';
$abc_cnt = 'A';
while( $abc_cnt1 < 26 ){
if(isset($_POST[$abc_cnt])){
$abc = $abc . $abc_cnt;
}
$abc_cnt++;
$abc_cnt1++;
}
echo $abc; // your result string for Sezzioni
The same applies to your other variables that you want to put into a string - for example if all the "Sesso" checkboxes are all clicked you will get "MFG" or you might have M and G or F and G.
if (isset($_POST['Maschio'])) $sesso = $sesso . 'M';
if (isset($_POST['Femmina'])) $sesso = $sesso . 'F';
if (isset($_POST['Azienda'])) $sesso = $sesso . 'G';
这篇关于Javascript变量值\ textarea内容到PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!