Hallo allemaal
Onderste heb ik ook al bij Database en SQL hulp gezet, maar misschien hoort hij meer hier thuis omdat ik bij de andere geen reacties krijg...
Ik loop al enkele dagen te rommelen met een issue en ik kom er niet uit. Stackflow en andere sites geraadpleegd maar niets boodt de oplossing die ik wilde/werkte.
Nu zijn jullie mijn laatste hoop!
Issue:
CMS met een gallery. achter elke foto zijn er 3 checkboxen. 1ste checkbox: toon op homepage. 2de checkbox: toon in gallery en de 3rde is dat je hem kan verwijderen. checkbox 1 en 2 kunnen ook beide geselecteerd zijn.
Ik krijg het niet werkend om de waarde van de check in mijn database te krijgen. Of ik krijg het helemaal niet werkend, of enkel bij het 1ste record, ookal vink ik de 9de record aan.
Mijn code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
ob_start();
require('../../lib/dbconnection.php');
require("../../lib/checklogin.php");
require("includes/upload.inc.php");
$query = 'SELECT * FROM gallery where image_deleted != 1 order by id desc';
$result=$conn->query($query);
$count=$result->num_rows;
<!DOCTYPE html>
<html>
<head>
<title>Classic Nails - CMS</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="ClassicNails">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/screen.css">
<link rel="stylesheet" href="../css/libs/magnific-popup.css">
<script src="../js/libs/min/jquery-min.js" type="text/javascript"></script>
<script src="../js/min/custom-min.js" type="text/javascript"></script>
<script src="js/jquery.magnific-popup.js"></script>
<script>
$(document).ready(function() {
$('.image-link').magnificPopup({
type:'image',
gallery:{
enabled:true
}
});
});
</script>
</head>
<body>
<?php include('includes/header.inc.php');
<?php include('includes/nav.inc.php');
<div class="wrapper">
<article class="content">
<h1>Foto gallery</h1>
<?php
if (isset($uploadResult)) {
echo "<p><strong>$uploadResult</strong></p>";
}
<form action="" method="post" enctype="multipart/form-data" name="uploadImage" id="uploadImage">
<p>
<label for="image">Upload image:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; " />
<input type="file" name="images" id="imagesd" />
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload" />
</p>
</form>
<div id="maincontent">
<h2>Foto informatie</h2>
<form name="FotoInformatie" id="fotoInformatie" method="post" action="">
<table>
<tr>
<td align="center"><strong>Foto<strong></td>
<td align="center"><strong>Titel</strong></td>
<td align="center"><strong>Beschrijving</strong></td>
<td align="center"><strong>Homepage</strong></td>
</tr>
<?php
while ($rows=$result->fetch_assoc()) {
<tr>
<td class="hide" align="center"><?php $id[]=$rows['id']; <?php echo $rows['id']; </td>
<td><a href="../img/uploads/<?php echo $rows['filename'];" class="image-link"><img src="../img/thumbs/<?php echo $rows['filename']; "></a></td>
<td align="center"><input name="title[]" type="text" id="title" value="<?php echo $rows['title']; "></td>
<td align="center"><input name="caption[]" type="text" id="caption" value="<?php echo $rows['caption']; "></td>
<td><input type="checkbox" name="checkboxHome[]" id="checkBoxHome" value="<?php echo $rows['home']"/></td>
</tr>
<?php
}
<tr>
<td colspan="4" align="center">
<input type="submit" name="submit" value="Submit">
</tr>
</table>
</form>
</div>
</article> <!-- end of content -->
</div> <!-- end of container -->
<?php include('includes/footer.inc.php');
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$title = $_POST['title'];
$caption = $_POST['caption'];
var_dump($_POST['$checkboxHome']);
if ('$checkboxHome' == "" xor NULL) {
$checkboxHome = '0';
} else {
$checkboxHome = '1';
}
for($i=0;$i<$count;$i++){
$result1=mysqli_query($conn, "UPDATE gallery SET title='$title[$i]', caption='$caption[$i]', home='$checkboxHome[$i]' WHERE id='$id[$i]'");
// header("location:/admin/foto-admin.php");
}
}
?>
Nu is enkel 1 checkbox aanwezig. Het gaat mij om het principe.
ben bekend met de prepare statements die mogelijkerwijs ontbreken. dat is van latere zorg..
Hoop dat iemand mij kan helpen.
alvast bedankt.
4.749 views