Jump to content

Recommended Posts

hi.

i am making a profolio for all of my work and i am quite new to php.

what i am working on at the moment is a way to add new projects to the site.

i have decided what information i need and set it all out. i have also created the database to go with this.

i have two tables a section table and project table

all the details from this are going to be stored in the project table.

 

what i need is a way of storing the information i want into the database. i also have a file upload section for an image to represent the project. i need to upload this to a specific directory and store the location in the database.

here is the code i have so far..

<?php
include("misc.inc");

$cxn = mysql_connect($localhost,$user,$pass)
	or die ("could not connect to server");

$datab = mysql_select_db($dbname,$cxn);

$query="SELECT DISTINCT section_name FROM section ORDER BY section_name";
$result=mysql_query($query,$cxn)
	or die ("couldnt execute query");

echo "<table width='395' border='0' cellpadding='0' cellspacing='0'>
  <!--DWLayoutTable-->
  <tr><form action='uploadproj.php' method='POST'>
    <td width='111' height='22' valign='top'>Section:</td>
    <td width='284' valign='top'><select name='section_name'>\n";

while ($row = mysql_fetch_assoc($result))
  {
     extract($row);
     echo "<option value='$section_name'>$section_name\n";
  }

echo"</select></td>
  </tr>
  
  <tr>
    <td height='22' valign='top'>Title:</td>
    <td valign='top'><input type='text' value='$title'/></td>
  </tr>
  <tr>
    <td height='163' valign='top'>Description:</td>
    <td valign='top'><textarea cols='40' rows='10' value='$descrip'></textarea></td>
  </tr>
  <tr>
    <td height='22' valign='top'>Image:</td>
    <td valign='top'><input type='file' value='$image'/></td>
  </tr>
  
  <tr>
    <td height='24' valign='top'><!--DWLayoutEmptyCell--> </td>
    <td valign='top'><input type='submit' value='Submit' />
      <input type='reset' value='Reset' /></td>
  </tr>
</table>";
?>

 

any help on how to do these would be awesome

Thanks

Wrathican

Link to comment
https://forums.phpfreaks.com/topic/50502-solved-help-needed-with-upload-script/
Share on other sites

my code...

 

<?php
echo "<font face=Arial size=2 color=#000000>";
$path = "uploads/";
$date = date("YmdHis");
if (isset($HTTP_POST_FILES['userfile'])){
if (!$HTTP_POST_FILES['userfile']){ echo "<font color=#ff0000>Error</font>: Please select a file to upload";
}else if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {
if (file_exists($path .$date .$HTTP_POST_FILES['userfile']['name'])) { echo "<font face=#ff0000>Error</font>: Please try upload again now<br />";
}else{
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .$date .$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "<font color=#ff0000>Error</font>: Unexpected fail<br>";
}else{
echo "upload sucessful<br><br>"; }
echo "File Name: ".$date."".$HTTP_POST_FILES['userfile']['name']."<br>";
echo "File Path: <a href=uploads/".$date."".$HTTP_POST_FILES['userfile']['name']." TARGET=_BLANK>uploads/".$date."".$HTTP_POST_FILES['userfile']['name']."</a><br>";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>";
echo "<img src=uploads/".$date."".$HTTP_POST_FILES['userfile']['name']."><br>";
}}else{ echo "<font color=#ff0000>Error</font>: wrong file type"; }}}
?>
</font>
<form ENCTYPE=multipart/form-data action='<?php echo "'$_SERVER[php_SELF]'"; ?> method=POST>
The file:
<input type=file name=userfile>
<input type=submit value=Upload>
</form></font>
<form ENCTYPE=multipart/form-data action='<?php echo "'$_SERVER[php_SELF]'"; ?> method=POST>
The file:
<input type=file name=userfile>
<input type=submit value=Upload>
</form></font>
<form ENCTYPE=multipart/form-data action='<?php echo "'$_SERVER[php_SELF]'"; ?> method=POST>
The file:
<input type=file name=userfile>
<input type=submit value=Upload>
</form>

hey thanks for the response. unfortunately i could not get it to work....

this is probably due to noobieness.

however i did manage to get my data inserted into my database, but for some reason the date doesnt work. ive created a variable with the date and then said to insert it into my mysql database. the field in my db that is to contain the date is of the DATE type. any help with this?

i have included my form process script so you can see whats happening in it.

i still need a way of uploading the file that is attatched in the form.

this is the form:

<?php
include("misc.inc");

$cxn = mysql_connect($localhost,$user,$pass)
	or die ("could not connect to server");

$datab = mysql_select_db($dbname,$cxn);

$query="SELECT DISTINCT section_name FROM section ORDER BY section_name";
$result=mysql_query($query,$cxn)
	or die ("couldnt execute query");

echo "<p><table width='395' border='0' cellpadding='0' cellspacing='0'>
  <!--DWLayoutTable-->
  <tr><form ENCTYPE='multipart/form-data' action='insertproj.php' method='POST'>
    <td width='111' height='22' valign='top'>Section:</td>
    <td width='284' valign='top'><select name='section_name'>\n";

while ($row = mysql_fetch_assoc($result))
  {
     extract($row);
     echo "<option value='$section_name'>$section_name\n";
  }

echo"</select></td>
  </tr>
  
  <tr>
    <td height='22' valign='top'>Title:</td>
    <td valign='top'><input type='text' value= name='title'/></td>
  </tr>
  <tr>
    <td height='163' valign='top'>Description:</td>
    <td valign='top'><textarea cols='40' rows='10' name='descrip'></textarea></td>
  </tr>
  <tr>
    <td height='22' valign='top'>Image:</td><input type='hidden' name='MAX_FILE_SIZE' value='300000'>
    <td valign='top'><input type='file'  name='image'/></td>
  </tr>
  
  <tr>
    <td height='24' valign='top'><!--DWLayoutEmptyCell--> </td>
    <td valign='top'><input type='submit' value='Submit' />
      <input type='reset' value='Reset' /></td>
  </tr>
</table></p>";
?>

 

 

this is the process script

<?php 
include("misc.inc");

$sectionname = $_POST['section_name'];
$prjtitle = $_POST['title'];
$date = date("Y-m-d");
$description = $_POST['descrip'];


mysql_connect("$localhost", "$user", "$pass") or die(mysql_error()); 

mysql_select_db("$dbname") or die(mysql_error()); 

mysql_query("INSERT INTO project (proj_section, proj_title, proj_date, proj_descrip, proj_imagepath) 
 VALUES ('$sectionname', '$prjtitle', '$date', '$description', '$imagepath')");

Print "Your information has been successfully added to the database.";

?>

 

in the value statement there is a vaiable '$imagepath'. this is to contain the path of the image i am to upload so that it is stored in my db.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.