alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/52e671ec40cb173a458b4686/ask-php--mysql-tentang-handling-post-array
[ASK] PHP + MySql, tentang Handling $_POST array
mau tanya gan kenapa ketika ane upload script seperti ini di hosting

Code:

$op = $_GET['op'];

if ($op == "order")
{
if(is_array($_POST['checkbox']))
{
foreach($_POST['checkbox'] as $idmovie){
$sql1="INSERT INTO detorder (idorder, tgl, idmovie, judul, size, hdd, jenis, status) VALUES ('".$idp."', '".$_POST['tgl']."', '$idmovie', '".$_POST['judul'][$idmovie]."', '".$_POST['size'][$idmovie]."', '".$_POST['hdd'][$idmovie]."', '".$_POST['jenis'][$idmovie]."', 'N')";
$hasil = mysql_query($sql1);
}
} else echo "[removed]alert('Bukan Array. ".$_POST['checkbox']."');[removed]";
$_SESSION['nohp'] = $_POST['nohp'];
$_SESSION['nama'] = $_POST['nama'];
$_SESSION['alamat'] = $_POST['alamat'];
$_SESSION['idp'] = $idp;

echo "[removed]alert('Silahkan Lengkapi Proses Selanjutnya.'); [removed] = 'checkout.php';[removed]";
}


kemudian ada form yang didalamnya ada element checkbox

Code:

<table width="100%" border=1px bordercolor="#FF0000" style="border:0.5px solid red;">
<tr height="50px" bgcolor="#FF0033" style="color:#FFFFFF">
<th align="center">PESAN</th>
<th align="center" width="40%">TITLE</th>
<th align="center">TYPE</th>
<th align="center">SUBTITLE</th>
<th align="center">SIZE</th>
<th align="center">RELEASE</th>
</tr>
<?php

$query1 = "SELECT * FROM list WHERE jenis = 'HD' ORDER BY id ASC";

$hasil1 = mysql_query($query1);
while ($data1 = mysql_fetch_array($hasil1))
{
echo "<tr>
<td><input type ='checkbox' name='checkbox[".$data1['id']."]' id='checkbox[".$data1['id']."]' value='".$data1['id']."'></td>
<input type='hidden' name='judul[".$data1['id']."]' value='".$data1['judul']."' />
<input type='hidden' name='size[".$data1['id']."]' value='".$data1['size']."' />
<input type='hidden' name='hdd[".$data1['id']."]' value='".$data1['hdd']."' />
<input type='hidden' name='jenis[".$data1['id']."]' value='HD MOVIE' />
<td>".$data1['judul']."</td>
<td align='center'>".$data1['type']."</td>
<td align='center'>".$data1['subtitle']."</td>
<td align='center'>".$data1['size']."</td>
<td align='center'>".$data1['release']."</td>
</tr>";
$no++;
}
mysql_free_result($hasil1);
?>
</table>


ketika submit, array dari checkbox gak mau tersimpan (ketika pilih id yang besar), padahal kalau di localhost bisa tersimpan value arraynya

mohon pencerahannya emoticon-Malu (S)
kok sepi yaa emoticon-Frown
Quote:Original Posted By DOGYHOLY
mau tanya gan kenapa ketika ane upload script seperti ini di hosting

Code:

$op = $_GET['op'];

if ($op == "order")
{
if(is_array($_POST['checkbox']))
{
foreach($_POST['checkbox'] as $idmovie){
$sql1="INSERT INTO detorder (idorder, tgl, idmovie, judul, size, hdd, jenis, status) VALUES ('".$idp."', '".$_POST['tgl']."', '$idmovie', '".$_POST['judul'][$idmovie]."', '".$_POST['size'][$idmovie]."', '".$_POST['hdd'][$idmovie]."', '".$_POST['jenis'][$idmovie]."', 'N')";
$hasil = mysql_query($sql1);
}
} else echo "[removed]alert('Bukan Array. ".$_POST['checkbox']."');[removed]";
$_SESSION['nohp'] = $_POST['nohp'];
$_SESSION['nama'] = $_POST['nama'];
$_SESSION['alamat'] = $_POST['alamat'];
$_SESSION['idp'] = $idp;

echo "[removed]alert('Silahkan Lengkapi Proses Selanjutnya.'); [removed] = 'checkout.php';[removed]";
}


kemudian ada form yang didalamnya ada element checkbox

Code:

<table width="100%" border=1px bordercolor="#FF0000" style="border:0.5px solid red;">
<tr height="50px" bgcolor="#FF0033" style="color:#FFFFFF">
<th align="center">PESAN</th>
<th align="center" width="40%">TITLE</th>
<th align="center">TYPE</th>
<th align="center">SUBTITLE</th>
<th align="center">SIZE</th>
<th align="center">RELEASE</th>
</tr>
<?php

$query1 = "SELECT * FROM list WHERE jenis = 'HD' ORDER BY id ASC";

$hasil1 = mysql_query($query1);
while ($data1 = mysql_fetch_array($hasil1))
{
echo "<tr>
<td><input type ='checkbox' name='checkbox[".$data1['id']."]' id='checkbox[".$data1['id']."]' value='".$data1['id']."'></td>
<input type='hidden' name='judul[".$data1['id']."]' value='".$data1['judul']."' />
<input type='hidden' name='size[".$data1['id']."]' value='".$data1['size']."' />
<input type='hidden' name='hdd[".$data1['id']."]' value='".$data1['hdd']."' />
<input type='hidden' name='jenis[".$data1['id']."]' value='HD MOVIE' />
<td>".$data1['judul']."</td>
<td align='center'>".$data1['type']."</td>
<td align='center'>".$data1['subtitle']."</td>
<td align='center'>".$data1['size']."</td>
<td align='center'>".$data1['release']."</td>
</tr>";
$no++;
}
mysql_free_result($hasil1);
?>
</table>


ketika submit, array dari checkbox gak mau tersimpan (ketika pilih id yang besar), padahal kalau di localhost bisa tersimpan value arraynya

mohon pencerahannya emoticon-Malu (S)


coba ganti baris ini:
PHP Code:
<td><input type ='checkbox' name='checkbox[".$data1['id']."]' id='checkbox[".$data1['id']."]' value='".$data1['id']."'></td


menjadi:
PHP Code:
<td><input type ='checkbox' name='checkbox[]' id='checkbox[".$data1['id']."]' value='".$data1['id']."'></td


dan dicoba lagi emoticon-Smilie
Quote:Original Posted By korancrew
coba ganti baris ini:
PHP Code:
<td><input type ='checkbox' name='checkbox[".$data1['id']."]' id='checkbox[".$data1['id']."]' value='".$data1['id']."'></td


menjadi:
PHP Code:
<td><input type ='checkbox' name='checkbox[]' id='checkbox[".$data1['id']."]' value='".$data1['id']."'></td


dan dicoba lagi emoticon-Smilie


ane udah nyoba jg pake yg itu gan tp ttp value array gak kebaca (kalo id gede).... kalo id yg awal2 bisa kebaca...
udah coba di var_dump $_POST nya? klo nilainya kelempar berarti yg bermasalah querynya..., klo gak kelempar berarti masalah di formnya
Bener kata agan di atas ane, coba di var_dump($_POST); dan lihat nilai-nilai yang ada di situ
×