Forum Moderators: coopster
<?php
//This is the directory where images will be saved
$target = "News/";
$target = $target . basename( $_FILES['photo']['name']);
$ok=1;
//This is our size condition
if ($uploaded_size > 650000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//This gets all the other information from the form
$header=$_POST['header'];
$description=$_POST['description'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("host", "user", "password") or die(mysql_error()) ;
mysql_select_db("mwzzzcyg_news") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `index_news` VALUES ('$header', '$description', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your News article has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
print ". To upload another article <a href=http://www.example.com/newsite/uploadform.php> Click Here</a>";
?>
[edited by: eelixduppy at 8:10 pm (utc) on Jan. 16, 2009]
[edit reason] exemplified [/edit]
here is my script so far for out putting the data but its not displaying how i want it to
<?php
// Connects to your Database
mysql_connect("localhost", "user", "password") or die(mysql_error()) ;
mysql_select_db("mwzzzcyg_news") or die(mysql_error()) ;
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM index_news ORDER BY pid DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "<img src=http://www.example.com/newsite/News/".$info['photo'] ."> <br>";
Echo "<b></b> ".$info['header'] . "<br> ";
Echo "<b></b> ".$info['description'] . " <br>";
}
?>
[edited by: coopster at 1:19 pm (utc) on Jan. 17, 2009]
[edit reason] please use example.com, thanks! [/edit]
If theres a specific CSS problem you're having, then please post in the CSS section - [webmasterworld.com...]
:)