Jump to content

cgmcdonald

Members
  • Posts

    2
  • Joined

  • Last visited

cgmcdonald's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I don't know how to implement that. Could you give me an example of what the working code for that line would be?
  2. I need to upload my images to a folder and need the image name with file type to be places in a mysql database so it can be accessed by another page. This is my php where everything works except uploading the image name to the database; Instaead the column is populated with the word array. Does anyone know how to fix this. MySql column is set to varchar(50). <?php require_once("connect.php"); $name = $_POST['job_name']; $img = $_FILES['job_timg']; $desc = $_POST['job_desc']; $plug = "INSERT INTO tbl_job VALUES (NULL,'".$name."','".$desc."', '".$img."')"; $Set = mysql_query($plug); if($Set==1){ $qJob = "SELECT * FROM tbl_job WHERE job_name = '".$name."' "; $Result = mysql_query($qJob); $row = mysql_fetch_array($Result); $lastID = $row['job_id']; $Link1 = "INSERT INTO tbl_l_ji(ji_id, job_id, image_id) VALUES(NULL, '".$lastID."','".$cat."')"; $place1 = mysql_query($Link1); header("Location: index.php"); }else{ } if($_POST){// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.if ($_FILES["job_timg"]["error"] > 0){// if there is error in file uploadingecho "Return Code: " . $_FILES["job_timg"]["error"] . "<br />";}else{// check if file already exit in "images" folder.if (file_exists("_/img/" . $_FILES["job_timg"]["name"])){echo $_FILES["job_timg"]["name"] . " already exists. ";}else{ //move_uploaded_file function will upload your image. if you want to resize image before uploading see this link http://b2atutorials.blogspot.com/2013/06/how-to-upload-and-resize-image-for.htmlif(move_uploaded_file($_FILES["job_timg"]["tmp_name"],"_/img/" . $_FILES["job_timg"]["name"])){// If file has uploaded successfully, store its name in data base$query_image = "INSERT INTO tbl_job (job_timg) VALUES ('".$_FILES['job_timg']['name'].")";if(mysql_query($query_image)){echo "Stored in: " . "_/img/" . $_FILES["job_timg"]["name"];}else{echo 'File name not stored in database';}}}}}?> My Form: div class="container"> <div class="row"> <div class="twelvecol last"> <form action="add_site.php" method="post" enctype="multipart/form-data"> <!--add in the enctype in order to handle file management--> <label>Name:</label><br> <input name="job_name" type="text" size="32"><br><br> <label>Job Front Image:</label><br> <input name="job_timg" type="file" size="32"><br><br> <label>Description:</label><br> <textarea name="job_desc" cols="80" rows="10"></textarea><br><br> </select><br><br> <input type="submit" value="Add Job"> </form> </div> Thank you, Connor McDonald
×
×
  • Create New...