PHP gevorderde |
|
Het updaten van de status van de tickets wil niet lukken.
Als ik de query echo, dan zie ik dat er tussen de haakjes van de IN, niets staat, terwijl ik wel tickets aangevinkt heb.
Ik snap het niet, het staat in een form, en de namen komen overeen.
Hieronder de foutmelding waarin ook de geëchode query te zien is:
Warning: implode() [function.implode]: Invalid arguments passed in /home/admin/domains/adsupply.nl/public_html/admin/tickets.php on line 23
UPDATE tickets_berichten SET status = 2 WHERE id IN ()You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 7
Hieronder de (volledige) code:
<?php
//////////////////////////////////////////////
// tickets.php //
// page with an overview of the tickets //
// in the admin panel //
// //
// creation: 2008-12-03 //
// last modified: 2008-12-03 //
// created by: Stefan van Iwaarden //
// last modified by: Stefan van Iwaarden //
//////////////////////////////////////////////
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if ($_POST['ticket'] != '')
{
$query = "UPDATE
tickets_berichten
SET
status = ".$_POST['status']."
WHERE
id
IN (".implode(",", $_POST['tickets']).")";
echo $query;
$result = mysql_query($query) or die (mysql_error());
}
}
if ($_GET['col'] == 'status')
{
$orderby = 'status';
}
elseif ($_GET['col'] == 'datum')
{
$orderby = 'datum';
}
else
{
$orderby = 'datum';
}
if ($_GET['sort'] == 'ASC')
{
$sort = 'ASC';
$nextsort = 'DESC';
}
elseif ($_GET['sort'] == 'DESC')
{
$sort = 'DESC';
$nextsort = 'ASC';
}
else
{
$sort = 'DESC';
$nextsort = 'ASC';
}
$query = "SELECT
id,
onderwerp,
naam,
SUBSTRING(bericht, 0, 100) AS short,
status,
DATE_FORMAT(datum, '%d-%m-%Y %H:%i') AS datumnl
FROM
tickets_berichten
WHERE
status != 5
ORDER BY
".$orderby." ".$sort;
$result = mysql_query($query) or die (mysql_error());
echo '<b>Tickets</b><br /><br />';
echo '<form action="" method="post">';
echo '<table cellspacing="0" width="90%">';
echo '<tr>
<td> </td>
<td><b>Naam</b></td>
<td><b>Onderwerp</b></td>
<td><b>Bericht</b></td>
<td><b><a href="?page=tickets&col=status&sort='.$nextsort.'" style="text-decoration: none;">Status</a></b></td>
<td><b><a href="?page=tickets&col=datum&sort='.$nextsort.'" style="text-decoration: none;">Datum</a></b></td>
</tr>';
while ($row = mysql_fetch_assoc($result))
{
$query2 = "SELECT onderwerp FROM tickets_onderwerpen WHERE id = ".$row['onderwerp'];
$result2 = mysql_query($query2) or die (mysql_error());
$onderwerp = mysql_result($result2,0,'onderwerp');
$query3 = "SELECT status FROM tickets_statussen WHERE id = ".$row['status'];
$result3 = mysql_query($query3) or die (mysql_error());
$status = mysql_result($result3,0,'status');
if ($r % 2 == 0)
{
$bgcolor = '#CCCCCC';
}
else
{
$bgcolor = '#FFFFFF';
}
echo '<tr bgcolor="'.$bgcolor.'">
<td><input type="checkbox" name"tickets[]" value="'.$row['id'].'"></td>
<td width="20%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$row['naam'].'</a></td>
<td width="15%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$onderwerp.'</a></td>
<td width="35%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$row['short'].'</a></td>
<td width="15%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$status.'</a></td>
<td width="15%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$row['datumnl'].'</a></td>
</tr>';
$r++;
}
echo '</table>';
echo '<br /><br />';
echo 'Geselecteerde berichten status wijzigen:<br />';
echo '<select name="status">';
$query = "SELECT id,status FROM tickets_statussen ORDER BY rang ASC";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<option value="'.$row['id'].'">'.$row['status'].'</option>';
}
echo '</select>';
echo '<br />';
echo '<input type="submit" name="submit" value="Wijzig" />';
echo '</form>';
?>
<?php ////////////////////////////////////////////// // tickets.php // // page with an overview of the tickets // // in the admin panel // // // // creation: 2008-12-03 // // last modified: 2008-12-03 // // created by: Stefan van Iwaarden // // last modified by: Stefan van Iwaarden // ////////////////////////////////////////////// if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($_POST['ticket'] != '') { $query = "UPDATE tickets_berichten SET status = ".$_POST['status']." WHERE id IN (".implode(",", $_POST['tickets']).")"; } } if ($_GET['col'] == 'status') { $orderby = 'status'; } elseif ($_GET['col'] == 'datum') { $orderby = 'datum'; } else { $orderby = 'datum'; } if ($_GET['sort'] == 'ASC') { $sort = 'ASC'; $nextsort = 'DESC'; } elseif ($_GET['sort'] == 'DESC') { $sort = 'DESC'; $nextsort = 'ASC'; } else { $sort = 'DESC'; $nextsort = 'ASC'; } $query = "SELECT id, onderwerp, naam, SUBSTRING(bericht, 0, 100) AS short, status, DATE_FORMAT(datum, '%d-%m-%Y %H:%i') AS datumnl FROM tickets_berichten WHERE status != 5 ORDER BY ".$orderby." ".$sort; echo '<b>Tickets</b><br /><br />'; echo '<form action="" method="post">'; echo '<table cellspacing="0" width="90%">'; <td> </td> <td><b>Naam</b></td> <td><b>Onderwerp</b></td> <td><b>Bericht</b></td> <td><b><a href="?page=tickets&col=status&sort='.$nextsort.'" style="text-decoration: none;">Status</a></b></td> <td><b><a href="?page=tickets&col=datum&sort='.$nextsort.'" style="text-decoration: none;">Datum</a></b></td> </tr>'; { $query2 = "SELECT onderwerp FROM tickets_onderwerpen WHERE id = ".$row['onderwerp']; $query3 = "SELECT status FROM tickets_statussen WHERE id = ".$row['status']; if ($r % 2 == 0) { $bgcolor = '#CCCCCC'; } else { $bgcolor = '#FFFFFF'; } echo '<tr bgcolor="'.$bgcolor.'"> <td><input type="checkbox" name"tickets[]" value="'.$row['id'].'"></td> <td width="20%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$row['naam'].'</a></td> <td width="15%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$onderwerp.'</a></td> <td width="35%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$row['short'].'</a></td> <td width="15%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$status.'</a></td> <td width="15%"><a href="?page=tickets_details&id='.$row['id'].'" style="text-decoration: none;">'.$row['datumnl'].'</a></td> </tr>'; $r++; } echo 'Geselecteerde berichten status wijzigen:<br />'; echo '<select name="status">'; $query = "SELECT id,status FROM tickets_statussen ORDER BY rang ASC"; { echo '<option value="'.$row['id'].'">'.$row['status'].'</option>'; } echo '<input type="submit" name="submit" value="Wijzig" />'; ?>
|