...

View Full Version : Adding image upload to a exsisting event entry form



DJ Hands3
03-25-2009, 09:51 PM
I have found a really good event php code that enables a user to add an event to a calender as shown below, the only problem is I want the user to be able to upload a picture of the event as well. I managed to modify it so the user can enter a url to a picture to display this way but I thought this was pretty lame so I'm thinking of a way to involve a image upload within the exsisting form to get round this.

As my php knowledege is very basic I have tried merging a upload php code into the original form but no luck as yet, can any of you guys get me on the right track?

Below is the code and $event_flyer is what I wish to change to an image upload.



<html>
<head>
<title>Show / Add Events</title>
</head>
<body>
<h1>Show / Add Events</h1>
<?php
$mysql = mysql_connect("server", "user", "pass");
mysql_select_db("dbname", $mysql) or die(mysql_error());

// Add our new events
if ($_POST){
$m = $_POST['m'];
$d = $_POST['d'];
$y = $_POST['y'];

// Formatting for SQL datetime (if this is edited, it will NOT work.)
$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_flyer, event_url, event_start) VALUES('".$_POST["event_title"]."','".$_POST

["event_shortdesc"]."','".$_POST["event_flyer"]."','".$_POST["event_url"]."','$event_date')";
$insEvent_res = mysql_query($insEvent_sql, $mysql)
or die(mysql_error($mysql));
} else {
$m = $_GET['m'];
$d = $_GET['d'];
$y = $_GET['y'];
}
// Show the events for this day:
$getEvent_sql = "SELECT event_title, event_shortdesc, event_flyer, event_url,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calendar_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysql_query($getEvent_sql, $mysql)
or die(mysql_error($mysql));

if (mysql_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysql_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = str_replace("\r", "<br/>", $ev["event_shortdesc"]);
$event_flyer = $ev["event_flyer"];
$event_url = $ev["event_url"];
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."<br />
<a href=".$event_url."><img border=\"0\" src=mixes/flyers/".$event_flyer." alt=".$event_title."></a>
</li>";
}
$event_txt .="</ul>";
mysql_free_result($getEvent_res);
} else {
$event_txt = "";
}

mysql_close($mysql);

if ($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}

// Show form for adding the event:

echo "
<form method=\"post\" action=".$_SERVER['PHP_SELF'].">
<p><strong>Add Event:</strong><br/>
Complete the form below then press the submit button when you are done.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p>
<p><strong>Event Description:</strong<br/>
<textarea rows=\"2\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></textarea></p>
<p><strong>Event flyer url:</strong<br/>
<input type=\"text\" name=\"event_flyer\" size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event url:</strong<br/>
<input type=\"text\" name=\"event_url\" size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x<=24; $x++){
echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";
?>
</body>
</html>

Fumigator
03-25-2009, 09:54 PM
The PHP manual has a pretty good section on how to do this:

http://us2.php.net/manual/en/features.file-upload.php

DJ Hands3
03-25-2009, 10:47 PM
the first example shown on this page http://us2.php.net/manual/en/features.file-upload.php is pretty good I have managed to include this in the event add form the only issues I'm confussed on are how I include the file path for the uploaded image as since the form requires the image to be uploaded before I would be able to extract a file name from the uploaded image and i would need that to place into a hidden field so the url reference would be included on submission to the database... I could use another type of upload php script where it prints out the uploaded image file path after upload but I could get this value to be included in a hidden field so all could then be added to the database.. but the only problem with this is that I require information from an original query string, the upload event form is brought about by clicking on a date on another .php page with a calender that then pops up a window with the date clicked on to pass this within the query string to the form and hence the database, so i would loose this info if done this way, my working demo is here http://dj-promo.co.uk/calender.php with the included upload added field but as you can see the upload file part is not working as yet..

Below what I could get together with the first example on php.net


<?php
/***
this is a simple and complete function and
the easyest way i have found to allow you
to add an image to a form that the user can
verify before submiting

if the user do not want this image and change
his mind he can reupload a new image and we
will delete the last

i have added the debug if !move_uploaded_file
so you can verify the result with your
directory and you can use this function to
destroy the last upload without uploading
again if you want too, just add a value...
***/

function upload_back() { global $globals;

/***
1rst set the images dir and declare a files
array we will have to loop the images
directory to write a new name for our picture
***/

$uploaddir = 'mixes/flyers/'; $dir = opendir($uploaddir);
$files = array();

/***
if we are on a form who allow to reedit the
posted vars we can save the image previously
uploaded if the previous upload was successfull.
so declare that value into a global var, we
will rewrite that value in a hidden input later
to post it again if we do not need to rewrite
the image after the new upload and just... save
the value...
***/

if(!empty($_POST['attachement_loos'])) { $globals['attachement'] = $_POST['attachement_loos']; }

/***
now verify if the file exists, just verify
if the 1rst array is not empty. else you
can do what you want, that form allows to
use a multipart form, for exemple for a
topic on a forum, and then to post an
attachement with all our other values
***/

if(isset($_FILES['attachement']) && !empty($_FILES['attachement']['name'])) {

/***
now verify the mime, i did not find
something more easy than verify the
'image/' ty^pe. if wrong tell it!
***/

if(!eregi('image/', $_FILES['attachement']['type'])) {

echo 'The uploaded file is not an image please upload a valide file!';

} else {

/***
else we must loop our upload folder to find
the last entry the count will tell us and will
be used to declare the new name of the new
image. we do not want to rewrite a previously
uploaded image
***/

while($file = readdir($dir)) { array_push($files,"$file"); echo $file; } closedir($dir);

/***
now just rewrite the name of our uploaded file
with the count and the extension, strrchr will
return us the needle for the extension
***/

$_FILES['attachement']['name'] = ceil(count($files)+'1').''.strrchr($_FILES['attachement']['name'], '.');
$uploadfile = $uploaddir . basename($_FILES['attachement']['name']);

/***
do same for the last uploaded file, just build
it if we have a previously uploaded file
***/

$previousToDestroy = empty($globals['attachement']) && !empty($_FILES['attachement']['name']) ? '' : $uploaddir . $files[ceil(count($files)-'1')];

// now verify if file was successfully uploaded

if(!move_uploaded_file($_FILES['attachement']['tmp_name'], $uploadfile)) {

echo '<pre>
Your file was not uploaded please try again
here are your debug informations:
'.print_r($_FILES) .'
</pre>';

} else {

echo 'image succesfully uploaded!';

}

/***
and reset the globals vars if we maybe want to
reedit the form: first the new image, second
delete the previous....
***/

$globals['attachement'] = $_FILES['attachement']['name'];
if(!empty($previousToDestroy)) { unlink($previousToDestroy); }

}

}
}

upload_back();

// merge here

$mysql = mysql_connect("host", "user", "pass");
mysql_select_db("dbname", $mysql) or die(mysql_error());

// Add our new events
if ($_POST){
$m = $_POST['m'];
$d = $_POST['d'];
$y = $_POST['y'];

// Formatting for SQL datetime (if this is edited, it will NOT work.)
$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_flyer, event_url, event_start) VALUES('".$_POST["event_title"]."','".$_POST

["event_shortdesc"]."','".$_POST["event_flyer"]."','".$_POST["event_url"]."','$event_date')";
$insEvent_res = mysql_query($insEvent_sql, $mysql)
or die(mysql_error($mysql));
} else {
$m = $_GET['m'];
$d = $_GET['d'];
$y = $_GET['y'];
}
// Show the events for this day:
$getEvent_sql = "SELECT event_title, event_shortdesc, event_flyer, event_url,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calendar_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysql_query($getEvent_sql, $mysql)
or die(mysql_error($mysql));

if (mysql_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysql_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = str_replace("\r", "<br/>", $ev["event_shortdesc"]);
$event_flyer = $ev["event_flyer"];
$event_url = $ev["event_url"];
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."<br />
<a href=".$event_url."><img border=\"0\" src=mixes/flyers/".$event_flyer." alt=".$event_title."></a>
</li>";
}
$event_txt .="</ul>";
mysql_free_result($getEvent_res);
} else {
$event_txt = "";
}

mysql_close($mysql);

if ($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}
/***
now the form if you need it (with the global...):

just add the hidden input when you write your
preview script and... in the original form but!
if you have send a value to advert your script
than we are remaking the form. for exemple with a
hidden input with "reedit" as value or with a
$_GET method who can verify that condition
***/

echo "
<form method=\"post\" action=".$_SERVER['PHP_SELF']." enctype=\"multipart/form-data\">
<input type=\"file\" name=\"attachement\" name=\"attachement\"></input>
<input type=\"hidden\" name=\"attachement_loos\" name=\"attachement_loos\" value=".$globals['attachement']."></input>
<p><strong>Add Event:</strong><br/>
Complete the form below then press the submit button when you are done.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p>
<p><strong>Event Description:</strong<br/>
<textarea rows=\"2\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></textarea></p>
<p><strong>Event flyer url:</strong<br/>
<input type=\"text\" name=\"event_flyer\" size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event url:</strong<br/>
<input type=\"text\" name=\"event_url\" size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x<=24; $x++){
echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";
?>
</body>
</html>

Fumigator
03-25-2009, 11:08 PM
You should be able to use a single form for everything, though IIRC all the form elements will come through in the $_FILE array rather than the $_POST array.

DJ Hands3
03-26-2009, 01:31 AM
I'v been trying and it dosent make any sense to me, so what your saying above is when the form is submitted the picture uploads and can also at the same time tell the database where its stored on the server whilst submitting what ever else is on the form? I'v tried I just cant understand how the form can tell the database where the image is stored before its even uploaded to the server or is it a case of somehow telling the text input the name of the directory and file name into a vairable from the php script?

code so far:



<?php
/***
this is a simple and complete function and
the easyest way i have found to allow you
to add an image to a form that the user can
verify before submiting

if the user do not want this image and change
his mind he can reupload a new image and we
will delete the last

i have added the debug if !move_uploaded_file
so you can verify the result with your
directory and you can use this function to
destroy the last upload without uploading
again if you want too, just add a value...
***/

function upload_back() { global $globals;

/***
1rst set the images dir and declare a files
array we will have to loop the images
directory to write a new name for our picture
***/

$uploaddir = 'mixes/flyers/'; $dir = opendir($uploaddir);
$files = array();

/***
if we are on a form who allow to reedit the
posted vars we can save the image previously
uploaded if the previous upload was successfull.
so declare that value into a global var, we
will rewrite that value in a hidden input later
to post it again if we do not need to rewrite
the image after the new upload and just... save
the value...
***/

if(!empty($_POST['attachement_loos'])) { $globals['attachement'] = $_POST['attachement_loos']; }

/***
now verify if the file exists, just verify
if the 1rst array is not empty. else you
can do what you want, that form allows to
use a multipart form, for exemple for a
topic on a forum, and then to post an
attachement with all our other values
***/

if(isset($_FILES['attachement']) && !empty($_FILES['attachement']['name'])) {

/***
now verify the mime, i did not find
something more easy than verify the
'image/' ty^pe. if wrong tell it!
***/

if(!eregi('image/', $_FILES['attachement']['type'])) {

echo 'The uploaded file is not an image please upload a valide file!';

} else {

/***
else we must loop our upload folder to find
the last entry the count will tell us and will
be used to declare the new name of the new
image. we do not want to rewrite a previously
uploaded image
***/

while($file = readdir($dir)) { array_push($files,"$file"); echo $file; } closedir($dir);

/***
now just rewrite the name of our uploaded file
with the count and the extension, strrchr will
return us the needle for the extension
***/

$_FILES['attachement']['name'] = ceil(count($files)+'1').''.strrchr($_FILES['attachement']['name'], '.');
$uploadfile = $uploaddir . basename($_FILES['attachement']['name']);

/***
do same for the last uploaded file, just build
it if we have a previously uploaded file
***/

$previousToDestroy = empty($globals['attachement']) && !empty($_FILES['attachement']['name']) ? '' : $uploaddir . $files[ceil(count($files)-'1')];

// now verify if file was successfully uploaded

if(!move_uploaded_file($_FILES['attachement']['tmp_name'], $uploadfile)) {

echo '<pre>
Your file was not uploaded please try again
here are your debug informations:
'.print_r($_FILES) .'
</pre>';

} else {

echo 'image succesfully uploaded!';

}

/***
and reset the globals vars if we maybe want to
reedit the form: first the new image, second
delete the previous....
***/

$globals['attachement'] = $_FILES['attachement']['name'];
if(!empty($previousToDestroy)) { unlink($previousToDestroy); }

}

}
}

upload_back();

// merge here

$mysql = mysql_connect("host", "user", "pass");
mysql_select_db("dbname", $mysql) or die(mysql_error());

// Add our new events
if ($_POST){
$m = $_POST['m'];
$d = $_POST['d'];
$y = $_POST['y'];

// Formatting for SQL datetime (if this is edited, it will NOT work.)
$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_flyer, event_url, event_start) VALUES('".$_POST["event_title"]."','".$_POST

["event_shortdesc"]."','".$_POST["event_flyer"]."','".$_POST["event_url"]."','$event_date')";
$insEvent_res = mysql_query($insEvent_sql, $mysql)
or die(mysql_error($mysql));
} else {
$m = $_GET['m'];
$d = $_GET['d'];
$y = $_GET['y'];
}
// Show the events for this day:
$getEvent_sql = "SELECT event_title, event_shortdesc, event_flyer, event_url,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calendar_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysql_query($getEvent_sql, $mysql)
or die(mysql_error($mysql));

if (mysql_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysql_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = str_replace("\r", "<br/>", $ev["event_shortdesc"]);
$event_flyer = $ev["event_flyer"];
$event_url = $ev["event_url"];
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."<br />
<a href=".$event_url."><img border=\"0\" src=mixes/flyers/".$event_flyer." alt=".$event_title."></a>
</li>";
}
$event_txt .="</ul>";
mysql_free_result($getEvent_res);
} else {
$event_txt = "";
}

mysql_close($mysql);

if ($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}
/***
now the form if you need it (with the global...):

just add the hidden input when you write your
preview script and... in the original form but!
if you have send a value to advert your script
than we are remaking the form. for exemple with a
hidden input with "reedit" as value or with a
$_GET method who can verify that condition
***/

echo "
<form method=\"post\" action=".$_SERVER['PHP_SELF']." enctype=\"multipart/form-data\">
<input type=\"file\" name=\"attachement\" name=\"attachement\"></input>
<input type=\"hidden\" name=\"attachement_loos\" name=\"attachement_loos\" value=".$globals['attachement']."></input>
<p><strong>Add Event:</strong><br/>
Complete the form below then press the submit button when you are done.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p>
<p><strong>Event Description:</strong<br/>
<textarea rows=\"2\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></textarea></p>
<p><strong>Event flyer url:</strong<br/>
<input type=text name=event_flyer value=" .$files. " size=25 maxlength=200 /></p>
<p><strong>Event url:</strong<br/>
<input type=\"text\" name=\"event_url\" size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x<=24; $x++){
echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";
?>
</body>
</html>

PappaJohn
03-26-2009, 02:01 AM
Have your upload_back() function return the information you need to insert into your db. I'm assuming (haven't read all your code) that you are determining the storage location based on the filename. Since this info is available inside upload_back(), simply build your filename, etc inside the function and return it. Something like:



function upload_back()
{
// function code

$file_location = ''; // insert filename, path, etc.

return $file_location;
}


Usage example:


$file_storage_location = upload_back();
// $file_storage_location can now be used in your query to insert the location into your db


BTW: You don't need this line: global $globals;, $globals is automatically global.

Inigoesdr
03-26-2009, 06:34 AM
You should be able to use a single form for everything, though IIRC all the form elements will come through in the $_FILE array rather than the $_POST array.

Only uploaded file data will show up in $_FILES. The rest of your inputs will be in $_POST.

DJ Hands3
03-27-2009, 01:02 AM
Had no luck doing it that way but this works,

page 1



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Full name</title>
</head>

<body>
<form action="event.php" method="post" enctype="multipart/form-data" name="frm_upload" id="frm_upload">
<table border="0" cellspacing="0" cellpadding="0" id="tbl_upload">
<tr>
<th scope="row"><label for="frmname">Full name:</label></th>
<td><input type="text" name="frmname" id="frmname" class="frmfld" /></td>
</tr>
<tr>
<th scope="row"><label for="frmfile">File:</label></th>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="300000000000" />
<input name="frmfile" type="file" id="frmfile" size="30" /></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td>
<label for="btn" id="sbm">
<input type="submit" name="btn" id="btn" value="Upload" />
</label>
</td>
</tr>
</table>
</form>
</body>

</html>


page 2



<?php

$m = $_GET['m'];
$d = $_GET['d'];
$y = $_GET['y'];
// define constant which contains the maximum file size in bytes
define('MAX_FILE_SIZE', 4000000);

if (array_key_exists('btn', $_POST)) {

// define new constant which contains the path the the upload folder
define('UPL_FLD','/home/fhlinux193/d/dj-promo.co.uk/user/htdocs/mixes/media/uploads/');

//Find the extension
$flext = pathinfo($_FILES['frmfile']['name']);
$ext = strtolower($flext['extension']);

// create new file name
$file = str_replace(' ', '_', $_POST['frmname'].'.'.$ext);
$file = strtolower($file);

// create variable and assign the formatted value of MAX_FILE_SIZE to it
$maxfs = number_format(MAX_FILE_SIZE/1024, 1).'KB';
$fsize = false;

// check the file size
if ($_FILES['frmfile']['size'] > 0 && $_FILES['frmfile']['size'] <= MAX_FILE_SIZE) {

$fsize = true;

}

// allow MIME file types
$filetype = array('image/gif','image/jpeg','image/pjpeg','image/png');
$ftype = false;

// check if uploaded file type is allowed
foreach($filetype as $type) {

if ($type == $_FILES['frmfile']['type']) {

$ftype = true;
break;

}

}

if ($ftype && $fsize && $_POST['frmname'] != '') {

switch($_FILES['frmfile']['error']) {

case 0:
// move file to the upload folder
$upload = move_uploaded_file($_FILES['frmfile']['tmp_name'],UPL_FLD.$file);
if ($upload) {

echo "
<form method=\"post\" action=\"event.php\">
<p><strong>Add Event:</strong><br/>
Complete the form below then press the submit button when you are done.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p>
<p><strong>Event Description:</strong<br/>
<textarea rows=\"2\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></textarea></p>
<p><strong>Event flyer url:</strong<br/>
<input type=\"text\" name=\"event_flyer\" value=".$_FILES['frmfile']['name']." size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event url:</strong<br/>
<input type=\"text\" name=\"event_url\" size=\"25\" maxlength=\"200\"/></p>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x<=24; $x++){
echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";

} else {

$msg = 'Error.<br />Please try again.';
}
break;

case 3:
$msg = 'Error.<br />Please try again.';
break;

default:
$msg = 'Error - please contact administrator';

}


} elseif ($_FILES['frmfile']['error'] == 4) {

$msg = 'Please select file';

} elseif ($_POST['frmname'] == '') {

$msg = 'Please provide your full name';

} else {

$msg = $_FILES['frmfile']['name'].' cannot be uploaded.<br />';
if(!$ftype) {
$msg .= 'Acceptable file formats are: .gif, .jpg, .png<br />';
}
if(!$fsize) {
$msg .= 'Maximum file size is '.$maxfs;
}

}

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>File upload</title>
<style type="text/css">
<!--
body {
font-family:Arial, Helvetica, sans-serif;
font-size:10pt;
color:#444;
}
#frm_upload, #tbl_upload, #btn, #sbm {
margin:0px;
padding:0px;
}
#tbl_upload {
border-top:solid 1px #aaa;
border-left:solid 1px #aaa;
}
#tbl_upload th, #tbl_upload td {
border-right:solid 1px #aaa;
border-bottom:solid 1px #aaa;
text-align:left;
vertical-align:top;
}
#tbl_upload th {
padding:3px 10px 0px 10px;
background-color:#f1f1f1;
font-weight:bold;
}
#tbl_upload td {
padding:3px;
}
.frmfld {
border:1px solid #aaa;
width:300px;
}
#btn, #sbm {
height:20px;
width:120px;
display:block;
}
#btn {
background-color:transparent;
border:none;
cursor:pointer;
}
#sbm {
border:solid 1px #aaa;
background:url(button.gif) repeat-x 0px 50%;
}
.warning {
color:#990000;
font-weight:bold;
}
-->
</style>
</head>

<body>

<?php if(isset($msg)) { echo '<p class="warning">'.$msg.'</p>'; } ?>

<form action="" method="post" enctype="multipart/form-data" name="frm_upload" id="frm_upload">
<table border="0" cellspacing="0" cellpadding="0" id="tbl_upload">
<tr>
<th scope="row"><label for="frmname">Full name:</label></th>
<td><input type="text" name="frmname" id="frmname" class="frmfld" /></td>
</tr>
<tr>
<th scope="row"><label for="frmfile">File:</label></th>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input name="frmfile" type="file" id="frmfile" size="30" /></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td>
<label for="btn" id="sbm">
<input type="submit" name="btn" id="btn" value="Upload" />
</label>
</td>
</tr>
</table>
</form>

</body>
</html>



page 3



<html>
<head>
<title>Show / Add Events</title>
</head>
<body>
<h1>Show / Add Events</h1>
<?php
$mysql = mysql_connect("host", "user", "pass");
mysql_select_db("dbname", $mysql) or die(mysql_error());

// Add our new events
if ($_POST){
$m = $_POST['m'];
$d = $_POST['d'];
$y = $_POST['y'];

// Formatting for SQL datetime (if this is edited, it will NOT work.)
$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_flyer, event_url, event_start) VALUES('".$_POST["event_title"]."','".$_POST

["event_shortdesc"]."','".$_POST["event_flyer"]."','".$_POST["event_url"]."','$event_date')";
$insEvent_res = mysql_query($insEvent_sql, $mysql)
or die(mysql_error($mysql));
} else {
$m = $_GET['m'];
$d = $_GET['d'];
$y = $_GET['y'];
}
// Show the events for this day:
$getEvent_sql = "SELECT event_title, event_shortdesc, event_flyer, event_url,
date_format(event_start, '%l:%i %p') as fmt_date FROM
calendar_events WHERE month(event_start) = '".$m."'
AND dayofmonth(event_start) = '".$d."' AND
year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysql_query($getEvent_sql, $mysql)
or die(mysql_error($mysql));

if (mysql_num_rows($getEvent_res) > 0){
$event_txt = "<ul>";
while($ev = @mysql_fetch_array($getEvent_res)){
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = str_replace("\r", "<br/>", $ev["event_shortdesc"]);
$event_flyer = $ev["event_flyer"];
$event_url = $ev["event_url"];
$fmt_date = $ev["fmt_date"];
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."<br/>".$event_shortdesc."<br />
<a href=".$event_url."><img border=\"0\" src=mixes/flyers/".$event_flyer." alt=".$event_title."></a>
</li>";
}
$event_txt .="</ul>";
mysql_free_result($getEvent_res);
} else {
$event_txt = "";
}

mysql_close($mysql);

if ($event_txt != ""){
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}
?>
</body>
</html>



Above works fine just need to find out now how to display the image on the calender as well as the event name on calender.php



<?php
// At line 2 of our calendar.php script, add the MySQL connection information:
$mysql = mysql_connect("host", "user", "pass");
mysql_select_db("dbname", $mysql) or die(mysql_error());

// Now we need to define "A DAY", which will be used later in the script:
define("ADAY", (60*60*24));

// The rest of the script will stay the same until about line 82

if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST['month'];
$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400');
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
echo "<option value=\"$x\"";
if ($x == $month){
echo " selected";
}
echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++){
echo "<option";
if ($x == $year){
echo " selected";
}
echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
<strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray["mon"] != $month) {
break;
} else {
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
echo "<td>*</td>\n";
} else {
$chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start";
$chkEvent_res = mysql_query($chkEvent_sql, $mysql) or die(mysql_error($mysql));

$chkEvent_sql = "SELECT event_flyer FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start";
$chkEvent_res = mysql_query($chkEvent_sql, $mysql) or die(mysql_error($mysql));

if (mysql_num_rows($chkEvent_res) > 0) {
$event_title = "<br/>";
while ($ev = mysql_fetch_array($chkEvent_res)) {
$event_title .= stripslashes($ev["event_title"])."<br/>";
$event_show = $ev["event_flyer"];
}
mysql_free_result($chkEvent_res);
} else {
$event_title = "";
}

echo "<td valign=\"top\"><a href=javascript:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');>".$dayArray["mday"]."</a><br/>".$event_title."<br />".$event_show."</td>\n";

unset($event_title);

$start += ADAY;
}
}
echo "</tr></table>";
mysql_close($mysql);
?>
</body>
</html>


The above i tried but had no luck just chucks out the file name on every day on the calender - i will include img tags to get the picture to dispaly once the original issue is sorted the original code for the calender php is below



<?php
// At line 2 of our calendar.php script, add the MySQL connection information:
$mysql = mysql_connect("host", "user", "pass");
mysql_select_db("dbname", $mysql) or die(mysql_error());

// Now we need to define "A DAY", which will be used later in the script:
define("ADAY", (60*60*24));

// The rest of the script will stay the same until about line 82

if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST['month'];
$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400');
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
echo "<option value=\"$x\"";
if ($x == $month){
echo " selected";
}
echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++){
echo "<option";
if ($x == $year){
echo " selected";
}
echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
<strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray["mon"] != $month) {
break;
} else {
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
echo "<td>*</td>\n";
} else {
$chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start";
$chkEvent_res = mysql_query($chkEvent_sql, $mysql) or die(mysql_error($mysql));

if (mysql_num_rows($chkEvent_res) > 0) {
$event_title = "<br/>";
while ($ev = mysql_fetch_array($chkEvent_res)) {
$event_title .= stripslashes($ev["event_title"])."<br/>";
}
mysql_free_result($chkEvent_res);
} else {
$event_title = "";
}

echo "<td valign=\"top\"><a href=javascript:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');>".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";

unset($event_title);

$start += ADAY;
}
}
echo "</tr></table>";
mysql_close($mysql);
?>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum