I am having problems with this script inserting the file name into my database and displaying the image.
the file uploads ok to my DIR , the image name is not being entered into the column(i have named 'name'). i think it's a path problem too. any help would be so much appreciated ...
<?php
// include the methods
include("showlister_methods.inc");
// parse the $_POST vars into something useful
// and check for nulls on required fields
$month = $_POST['month'];
$day = $_POST['day'];
$day_ofweek = $_POST['day_ofweek'];
if ($_POST['headliner']) {
$headliner = $_POST['headliner'];
} else {
die_now("<h3>Sorry</h3><p>headliner is a required field. Use your browser 'back' button to fix this.</a></p>");
}
if ($_POST['support']) {
$support = $_POST['support'];
} else {
die_now("<h3>Sorry</h3><p>support is a required field. Use your browser 'back' button to fix this.</a></p>");
}
$djs = $_POST['djs'];
$ticketaddl = $_POST['ticketaddl'];
$path = "images/";
$max_size = 200000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>\n"; exit; } else { echo "upload sucessful<br>\n"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { echo "Wrong file type<br>\n"; exit; }
}
_
?>
<html>
<head>
<title>Bigfloor showlister :: add shows [2]</title>
<link rel="stylesheet" type="text/css" href="showlister.css">
</head>
<body>
<?php
// read in the connection settings
require("showlister_settings.inc");
// connect to the RDBMS
$db = mysql_connect("$site","$user","$pass")
or die_now("<h2>Could not connect to database server</h2><p>Check passwords and sockets</p>");
// select the database
mysql_select_db("$database",$db)
or die_now("<h2>Could not select database $database</h2><p>Check database name</p>");
// add new show to the database
$result = mysql_query("insert into $database_table (show_id, day, month, day_ofweek, headliner, support, djs, ticketaddl, name)
values(null,'$month','$day','$day_ofweek','$headliner','$support','$djs','$ticketaddl','$name')",$db)
or die_now("<h2>Could not add show to database table</h2><p>Check database structure</p>");
// get the show_id for the previous insert query. We'll need it
// so we can drag the entry back out
$last_show_id = mysql_insert_id();
// echo out the most recent addition, for error checking
$result = mysql_query("select show_id, month, day, day_ofweek, headliner, support, djs,ticketaddl,name
from $database_table where show_id = $last_show_id",$db)
or die_now("<h2>Could not echo most recent show</h2>");
// while($i = mysql_fetch_row($result)) {
// echo($i[1] . ","); // month
// echo($i[2] . ","); // day
// echo($i[3] . ","); // dayofweek
// }
while($row = mysql_fetch_array($result)) {
$the_id = $row["show_id"];
$the_month = $row["month"];
$the_day = $row["day"];
$the_dayofweek = $row["day_ofweek"];
$the_headliner = $row["headliner"];
$the_support = $row["support"];
$the_djs = $row["djs"];
$ticketaddl = $row["ticketaddl"];
$name = $row["name"];
echo("<div class='box'><h3>showlister :: latest entry</h3></div>
<div class='box'>
<table border='1' width='100%'>
<tr>
<td>date</td>
<td>headliner</td>
<td>support</td>
<td>djs</td>
<td>ticketaddl</td>
<td>image of headliner</td>
</tr>
<tr>
<td>$the_month,$the_day,$the_dayofweek</td>
<td>$the_headliner</td>
<td>$the_support</td>
<td>$the_djs</td>
<td>$ticketaddl</td>
<td><img src=$path/$name></td>
</tr>
</table>
</div>");
// echo("$the_month" . "/" . "$the_day" . "/" . "$the_year " . "$the_venue $the_location $the_details");
}
?>
<?php
footer();
?>