Nieuw lid |
|
Hallo iedereen!
Ik ben bezig met een soort van cms script het is de bedoeling dat de eigenaar v/d site zelf zijn advertenties met foto toe kan voegen.
Ik ben nog maar net bezig met php, en had even de illusie dat alles van een leien dakje ging NEE DUS!
Eigenlijk werkt bijna alles , wordt netjes in de db gezet, foto`s komen in de map,
Krijg ook netjes een foto in de viewpage te zien, maar daar dan loop ik vast.
Krijg alleen maar de eerste foto te zien, al staan er 20 foto`s in de db en de map ,krijg alleen die ene foto te zien in alle rijen.
Ik heb getracht het script zo kort mogelijk te houden maar sorry, `t kan niet veel korter.
Ik ben al een poos aan het prutsen en hoop dat een van jullie mij kan helpen!
Met vriendelijke groet Lianne.
1. Database
CREATE TABLE `autos` (
`id` int(11) NOT NULL auto_increment,
`merk` varchar(150) collate latin1_general_ci NOT NULL default '',
`type` varchar(150) collate latin1_general_ci NOT NULL default '',
`cc` varchar(20) collate latin1_general_ci NOT NULL default '',
`brandstof` varchar(50) collate latin1_general_ci NOT NULL default '',
`bouwjaar` year(4) NOT NULL default '0000',
`km` varchar(200) collate latin1_general_ci NOT NULL default '',
`prijs` varchar(100) collate latin1_general_ci NOT NULL default '',
`opties` varchar(255) collate latin1_general_ci NOT NULL default '',
`datum` datetime NOT NULL default '0000-00-00 00:00:00',
`image_name` varchar(250) collate latin1_general_ci NOT NULL default '',
`image_size` varchar(200) collate latin1_general_ci NOT NULL default '',
`image_type` varchar(200) collate latin1_general_ci NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;
CREATE TABLE `autos` ( `id` int(11) NOT NULL auto_increment, `merk` varchar(150) collate latin1_general_ci NOT NULL default '', `type` varchar(150) collate latin1_general_ci NOT NULL default '', `cc` varchar(20) collate latin1_general_ci NOT NULL default '', `brandstof` varchar(50) collate latin1_general_ci NOT NULL default '', `bouwjaar` year(4) NOT NULL default '0000', `km` varchar(200) collate latin1_general_ci NOT NULL default '', `prijs` varchar(100) collate latin1_general_ci NOT NULL default '', `opties` varchar(255) collate latin1_general_ci NOT NULL default '', `datum` datetime NOT NULL default '0000-00-00 00:00:00', `image_name` varchar(250) collate latin1_general_ci NOT NULL default '', `image_size` varchar(200) collate latin1_general_ci NOT NULL default '', `image_type` varchar(200) collate latin1_general_ci NOT NULL default '', ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;
2 Deel upload
<?php
<input type="file" name="userfile" size="20" onFocus="window.status='Gebruik de knop Bladeren... om de juiste foto up te loaden.'" onBlur="window.status=''" /></td></tr>
<tr valign="top"><td> </td><td>
<input name="submit_toevoegen" type="submit" value="Bevestig >" /></td></tr>
</table>
</form>
<p><input type="button" onclick="java
?>
<?php <input type="file" name="userfile" size="20" onFocus="window.status='Gebruik de knop Bladeren... om de juiste foto up te loaden.'" onBlur="window.status=''" /></td></tr> <tr valign="top"><td> </td><td> <input name="submit_toevoegen" type="submit" value="Bevestig >" /></td></tr> </table> </form> <p><input type="button" onclick="java ?>
3 Deel toevoegen
<?php
if (is_uploaded_file($_FILES['userfile']['tmp_name'])
) {
$file_name = $_FILES['userfile']['name'];
$file_size = $_FILES['userfile']['size'];
$file_type = $_FILES['userfile']['type'];
$image_types = array('image/bmp','image/jpeg','image/pjpeg','image/gif','image/x-png');
if (in_array(strtolower($file_type),$image_types)) {
$uploaddir = "img/";
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploaddir . $_FILES['userfile']['name'])){
echo 'Het bestand is geplaatst in '.$uploaddir.$_FILES['userfile']['name']; }
$query = "INSERT INTO autos (merk,type,cc,brandstof,bouwjaar,km,prijs,
opties,datum,image_name,image_size,image_type) ";
$query.= "VALUES ('$merk','$type','$cc','$brandstof','$bouwjaar','$
km','$prijs','$opties','$datum','$file_name','$file_size','$file_type')";
}
else {
echo '<script language="JavaScript">window.alert("De foto heeft een ongeldig bestandstype!\nToegestaan: bmp, gif, jpg, png."); history.go(-1);</script>';
}
}
mysql_query($query) or die ("Query mislukt! Contacteer de webmaster.<p>Query:<br/><b>$query</b>");
echo '<script language="JavaScript">window.alert("Auto werd succesvol toegevoegd aan de database!");</script>';
}
?>
<?php ) { $file_name = $_FILES['userfile']['name']; $file_size = $_FILES['userfile']['size']; $file_type = $_FILES['userfile']['type']; $image_types = array('image/bmp','image/jpeg','image/pjpeg','image/gif','image/x-png'); $uploaddir = "img/"; if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploaddir . $_FILES['userfile']['name'])){ echo 'Het bestand is geplaatst in '.$uploaddir.$_FILES['userfile']['name']; } $query = "INSERT INTO autos (merk,type,cc,brandstof,bouwjaar,km,prijs, opties,datum,image_name,image_size,image_type) "; $query.= "VALUES ('$merk','$type','$cc','$brandstof','$bouwjaar','$ km','$prijs','$opties','$datum','$file_name','$file_size','$file_type')"; } else { echo '<script language="JavaScript">window.alert("De foto heeft een ongeldig bestandstype!\nToegestaan: bmp, gif, jpg, png."); history.go(-1);</script>'; } } mysql_query($query) or die ("Query mislukt! Contacteer de webmaster.<p>Query:<br/><b>$query</b>"); echo '<script language="JavaScript">window.alert("Auto werd succesvol toegevoegd aan de database!");</script>'; } ?>
4 Deel view
<h2>De opgegeven advertentie is geplaatst.</h2>
<?php
$uploaddir = "img/";
$result = mysql_query("SELECT * FROM autos");
if ($result)
{
while ($row = mysql_fetch_array($result))
{
if ($dir = opendir("img")) {
while (($row['file_name'] = readdir($dir)) !== false) {
if(!is_dir($row['file_name']) && strstr($row['file_name'],".")){
$FilesArr=$row['file_name'];
}
}
closedir($dir);
}
print "<div align=center>";
print "<table width=\"70%\" height=\"5%\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0000\" >";
print "<td width=131> ".$row ["merk"]."<div align=\"center\"></div></td>";
print "</tr>";
print "</table>
";
print "<table width=\"70%\" height=\"5%\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0000\" >";
print "<td width=131> ".$row ["type"]."<div align=\"center\"></div></td>";
print "</tr>";
print "</table>
";
print "<table width=\"70%\" height=\"20%\" border=\"2\" cellspacing=\"1\" cellpadding=\"1\" bordercolor=\"#FF0000\" >";
print "<tr>";
print "<td><img src=\"./img/".$FilesArr."\"></td>";
print "<td width=131>".$row ["cc"]."</td>";
print "<td width=100>".$row ["brandstof"]."</td>";
print "<td width=131>".$row ["bouwjaar"]."</td>";
print "<td width=100>".$row ["km"]."</td>";
print "<td width=100>".$row ["prijs"]."</td>";
print "<td width=169>".$row ["opties"]."</td>";
print "</tr>";
print "</table> ";
}
mysql_free_result($result);
}
?>
<h2>De opgegeven advertentie is geplaatst.</h2> <?php $uploaddir = "img/"; if ($result) { { while (($row['file_name'] = readdir($dir)) !== false) { if(!is_dir($row['file_name']) && strstr($row['file_name'],".")){ $FilesArr=$row['file_name']; } } } print "<div align=center>"; print "<table width=\"70%\" height=\"5%\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0000\" >"; print "<td width=131> ".$row ["merk"]."<div align=\"center\"></div></td>"; "; print "<table width=\"70%\" height=\"5%\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0000\" >"; print "<td width=131> ".$row ["type"]."<div align=\"center\"></div></td>"; "; print "<table width=\"70%\" height=\"20%\" border=\"2\" cellspacing=\"1\" cellpadding=\"1\" bordercolor=\"#FF0000\" >"; print "<td><img src=\"./img/".$FilesArr."\"></td>"; print "<td width=131>".$row ["cc"]."</td>"; print "<td width=100>".$row ["brandstof"]."</td>"; print "<td width=131>".$row ["bouwjaar"]."</td>"; print "<td width=100>".$row ["km"]."</td>"; print "<td width=100>".$row ["prijs"]."</td>"; print "<td width=169>".$row ["opties"]."</td>"; } } ?>
vinTage edit, PER codeblok [ code ] blabla [/ code ] gebruiken aub
|