Shamsul Kamal
asked on
How to submit multiple php array to mysql ?
Hi,
I would like to request an assistant.
May i know how to capture the following submitted form and update it in mysql ?
The following is the form :
$id=$line[id];
<input type=text name='newip[]'> <input type=hidden name='id[]' value='$id' >
The following is my script to capture the submitted form, it is obvious that **foreach($newiparray as $newip) && foreach($idarray as $id) {** will not work, but i wanted the same scenario but with working solution .
if(isset($_POST['Submitip' ])){
$newiparray=$_POST['newip' ];
$idarray=$_POST['id'];
foreach($newiparray as $newip) && foreach($idarray as $id) {
if ($newip !=""){
$sql=mysql_query("UPDATE tblip SET newip='$newip' WHERE id='$id' ");
if($sql){echo "<p><font face='Arial'><b>New IP $newip and ID $id Updated</b></font></p>";}} }}
Appreciates anybody can assist me on how to capture the "$id" array with the "$newip" array.
Thank you.
I would like to request an assistant.
May i know how to capture the following submitted form and update it in mysql ?
The following is the form :
$id=$line[id];
<input type=text name='newip[]'> <input type=hidden name='id[]' value='$id' >
The following is my script to capture the submitted form, it is obvious that **foreach($newiparray as $newip) && foreach($idarray as $id) {** will not work, but i wanted the same scenario but with working solution .
if(isset($_POST['Submitip'
$newiparray=$_POST['newip'
$idarray=$_POST['id'];
foreach($newiparray as $newip) && foreach($idarray as $id) {
if ($newip !=""){
$sql=mysql_query("UPDATE tblip SET newip='$newip' WHERE id='$id' ");
if($sql){echo "<p><font face='Arial'><b>New IP $newip and ID $id Updated</b></font></p>";}}
Appreciates anybody can assist me on how to capture the "$id" array with the "$newip" array.
Thank you.
ASKER
I tried as follows :
if(isset($_POST['Submitip' ]) && isset($_POST['newip'])){
$newiparray=$_POST['newip' ];
$idarray=$_POST['id'];
foreach($newiparray as $newip) {
foreach($idarray as $id) {
$sql=mysql_query("UPDATE tblip SET newip='$newip' WHERE id='$id' ");
if($sql){echo "<p><font face='Arial'><b>New IP $newip and ID $id Updated</b></font></p>";}} }}
It seems single NEWIP is updated in All ID table.
Its not working as it should.
Appreciates any other assistant.
if(isset($_POST['Submitip'
$newiparray=$_POST['newip'
$idarray=$_POST['id'];
foreach($newiparray as $newip) {
foreach($idarray as $id) {
$sql=mysql_query("UPDATE tblip SET newip='$newip' WHERE id='$id' ");
if($sql){echo "<p><font face='Arial'><b>New IP $newip and ID $id Updated</b></font></p>";}}
It seems single NEWIP is updated in All ID table.
Its not working as it should.
Appreciates any other assistant.
hi,
provide ur both array o/p
$i =0;
foreach($newiparray as $newip)
{
echo $idarray[$i];
$i++;
}
please provide echo of this value.
provide ur both array o/p
$i =0;
foreach($newiparray as $newip)
{
echo $idarray[$i];
$i++;
}
please provide echo of this value.
ASKER
Hi,
My Array form is as follows :
<input size='16' type=text name='newip[]' value='$newip'> <input type=hidden name='id[]' value='$id' >
The following script :
if(isset($_POST['Submitip' ])){
$newiparray=$_POST['newip' ];
$idarray=$_POST['id'];
$i =0;
foreach($newiparray as $newip)
{
echo $idarray[$i];
$i++;
}}
Produce :
72744422155215630830937515 5915601941 1942216217 5354168116 8217321733 2167216818 1518161451 1452145314 5419871988 1989199019 9119922622 6315711572 2066206720 6818972126 2127218721 8817923673 6821022103 1947194820 7820792080 2081209620 9720982142 2143214410 8710881089 1090217921 8019261927 1881891901 9115661567 2181218221 8314631464 5845856081 5381539205 0205116401 6411642194 9195019511 9521953195 4197919802 4624755555 6274275185 9186022022 2031776177 7188118822 0882089206 9207020142 0153143153 1631731831 9320321167 1167216731 6741675167 6163016312 1202121161 4161536236 3165216531 7301731165 4165521582 1591710171 1171217134 7347416341 6351754175 5184818492 1085445452 0202031159 6159721702 1712172217 3217421751 8541855182 5182616431 6441891189 2213021312 1222123426 4437173205 2061420156 1156815952 1362137176 1987988523 5242138213 9214021411 4177577584 4852552682 4205420551 7221723108 1379216521 6620562091 1929193087 0376377212 8212917041 7055996001 7461747185 0185117501 7511037103 8204620471 6451646187 9188021892 1906036045 3954019281 7569369371 7261727204 4204521342 1351687168 8669198119 8221922193 2063206484 6847631632 6336346376 3821322133 1724172516 0129130131 1321331341 3513659317 8617872057 2058189318 9420322033 2094209564 4645219621 9784885310 4110426766 7764664766 4833834219 8219991776 2142665465 5190819097 0170221162 1172118211 9708212421 2522042205 1005100620 9021627091 4651466131 0131167142 1142286666 6865214921 5011625942 1821532154 9539542160 2161176817 6910391040 8958968978 9889990020 4820499017 6376422002 2012109192 2192399399 4463464216 3216472172 2108510869 2692793893 9161216132 1697377389 4214371438 1380913914 9779782146 2147146814 8214831986 2028202920 3017011833 1834185614 6986412548 9064158958 8616263991 9923132924 9259681247 7344785659 2781249910 4041112405 1314215715 1613759899 9086523247 5252632427 2832529304 6146219202 0320415315 4485486219 4219564103 9899856857 8588598609 5969772086 7185218532 0232024202 5965985986 1413141412 5712581354 1355115811 5913561411 1412174017 4119461742 1743121512 1618401841 2042204320 9921451967 1478147917 8817891857 1858193919 4019951996 1562156317 2112291230 1870187118 7620592060 1955195621 0021011997 2002200320 0420072008 1795179621 7721782082 2083211421 1519721973 1974206520 9220931401 1402215121 5214251445 1446207320 7420752076 2077214821 7621912206 2207220812 4712481160 1161184519 8518681869 1290129115 2917781779 1762176314 2714281429 1430188718 8813261327 2104210521 0621071286 1283158016 20
Appreciates any assistant.
My Array form is as follows :
<input size='16' type=text name='newip[]' value='$newip'> <input type=hidden name='id[]' value='$id' >
The following script :
if(isset($_POST['Submitip'
$newiparray=$_POST['newip'
$idarray=$_POST['id'];
$i =0;
foreach($newiparray as $newip)
{
echo $idarray[$i];
$i++;
}}
Produce :
72744422155215630830937515
Appreciates any assistant.
You can create multidimensional arrays
Here some output
<input type='text' name='newip[$id]'>
if ( isset($_POST['submit']))
{
foreach(array_keys($_POST['newip']) as $key)
{
$sql = "UPDATE tblip SET newip='{$_POST['newip'][$key]}' WHERE id='{$key}'";
echo $sql;
}
}
Here some output
Array
(
[1] => 192.168.1.1
)
UPDATE tblip SET newip='192.168.1.1' WHERE id='1'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
foreach($newiparray as $newip) {
foreach($idarray AS $id) {
// sql insert statement here
}
}
So that should go through each value in the $newiparray and with each one it will loop through each value in the $idarray and insert it into the table.