Lid |
|
Beste,
ik weergeef een aantal verzend opties. Het werkt prima als ik de prijs aanpas, dit slaat hij ook keurig netjes op maar wanneer ik de checkbox wil aanpassen dus uit of aan vinken dan slaat hij dit niet op. Hij slaat het wel op maar als ik bijvoorbeeld A aanvink, dan slaat hij dit voor B of C op.
Kan iemand mij vertellen wat ik verkeerd doe?
Mijn code onderstaand:
<h1><?=SHPMENT_H1?></h1>
<h2><?=SHPMENT_H2?></h2>
<br />
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// upload a new shipment method if filled in
if($_POST['name'] != '' && $_POST['price'] != '')
{
// upload the picture
if(!move_uploaded_file($_FILES['logo']['tmp_name'], 'uploads'.DIRECTORY_SEPARATOR.$_FILES['logo']['name']))
{
// upload failed, give the user a message about this
echo '<div class="error">'.QUERY_ERROR.'</div>';
}
else
{
// add to the database
if(!mysql_query('INSERT INTO shipping_options
(name, price, logo)
VALUES
("'.mysql_real_escape_string($_POST['name']).'",
"'.mysql_real_escape_string($_POST['price']).'",
"'.mysql_real_escape_string($_FILES['logo']['name']).'")'))
{
echo '<div class="error">'.QUERY_ERROR.'</div>';
}
else
{
echo '<div class="success">'.USER_ADDED_QUERY.'</div>';
}
}
}
// update the current shipment methods
$i = 0;
foreach($_POST['which'] as $id)
{
mysql_query('UPDATE shipping_options
SET
price = "'.mysql_real_escape_string($_POST['curprice'][$i]).'",
active = "'.mysql_real_escape_string($_POST['check'][$i]).'"
WHERE
id = "'.mysql_real_escape_string($id).'"');
$i++;
}
}
?>
<form name="shipmentmethods" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Verzendmethodes</legend>
<?php
$query = mysql_query('SELECT id, name, price, logo, active FROM shipping_options
ORDER BY name DESC');
$rows = mysql_num_rows($query);
if($rows == 0)
{
echo SHPMENT_NONE;
}
else
{
// start a table
echo '<table width="500px">';
// process the loop
while($fetch = mysql_fetch_assoc($query))
{
// is the checkbox checked
if($fetch['active'] == 1){
$re = ' checked="checked"';
} else {
$re = '';
}
// check if the logo exists
if(file_exists('uploads'.DIRECTORY_SEPARATOR.$fetch['logo'])){
echo '<tr>
<td>
<input type="checkbox" name="check[]" value="1" '.$re.' />
</td>
<td>
<img src="uploads'.DIRECTORY_SEPARATOR.$fetch['logo'].'" alt="logo" />
</td>
<td>'.$fetch['name'].'</td>
<td>
€ <input type="text" name="curprice[]" value="'.number_format($fetch['price'], 2, '.', '.').'" />
<input type="hidden" name="which[]" value="'.$fetch['id'].'" />
</td>
</tr>';
} else {
echo '<tr><td></td><td>'.$fetch['name'].'</td><td>€ <input type="text" name="curprice" value="'.number_format($fetch['price'], 2, ',', '.').'" /></td></tr>';
}
}
// end the table
echo '</table>';
}
?>
</fieldset>
<fieldset>
<legend>Methode toevoegen</legend>
<label>Naam</label>
<input type="text" name="name" class="input" />
<br />
<label>Standaard kosten</label>
<input type="text" name="price" class="input" />
<br />
<label>Logo</label>
<input type="file" name="logo" class="input" />
</fieldset>
<input type="submit" name="submit" id="submit" value="<?=WRD_SAVE?>" />
</form>
<h1><?=SHPMENT_H1?></h1> <h2><?=SHPMENT_H2?></h2> <br /> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { // upload a new shipment method if filled in if($_POST['name'] != '' && $_POST['price'] != '') { // upload the picture if(!move_uploaded_file($_FILES['logo']['tmp_name'], 'uploads'.DIRECTORY_SEPARATOR .$_FILES['logo']['name'])) { // upload failed, give the user a message about this echo '<div class="error">'.QUERY_ERROR .'</div>'; } else { // add to the database (name, price, logo) VALUES { echo '<div class="error">'.QUERY_ERROR .'</div>'; } else { echo '<div class="success">'.USER_ADDED_QUERY .'</div>'; } } } // update the current shipment methods $i = 0; foreach($_POST['which'] as $id) { SET WHERE $i++; } } ?> <form name="shipmentmethods" method="post" enctype="multipart/form-data"> <fieldset> <legend>Verzendmethodes</legend> <?php $query = mysql_query('SELECT id, name, price, logo, active FROM shipping_options ORDER BY name DESC'); if($rows == 0) { } else { // start a table echo '<table width="500px">'; // process the loop { // is the checkbox checked if($fetch['active'] == 1){ $re = ' checked="checked"'; } else { $re = ''; } // check if the logo exists if(file_exists('uploads'.DIRECTORY_SEPARATOR .$fetch['logo'])){ <td> <input type="checkbox" name="check[]" value="1" '.$re.' /> </td> <td> <img src="uploads'.DIRECTORY_SEPARATOR.$fetch['logo'].'" alt="logo" /> </td> <td>'.$fetch['name'].'</td> <td> € <input type="text" name="curprice[]" value="'.number_format($fetch['price'], 2, '.', '.').'" /> <input type="hidden" name="which[]" value="'.$fetch['id'].'" /> </td> </tr>'; } else { echo '<tr><td></td><td>'.$fetch['name'].'</td><td>€ <input type="text" name="curprice" value="'.number_format($fetch['price'], 2, ',', '.').'" /></td></tr>'; } } // end the table } ?> </fieldset> <fieldset> <legend>Methode toevoegen</legend> <label>Naam</label> <input type="text" name="name" class="input" /> <br /> <label>Standaard kosten</label> <input type="text" name="price" class="input" /> <br /> <label>Logo</label> <input type="file" name="logo" class="input" /> </fieldset> <input type="submit" name="submit" id="submit" value="<?=WRD_SAVE?>" /> </form>
|