Jump to content

alexa16

New Members
  • Posts

    2
  • Joined

  • Last visited

alexa16's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. File wont move to directory nor even upload to database here is my code , everything else uploads except the image <?php include('../connect.php'); if(isset($_POST['submit'])){ echo $post_title=mysqli_real_escape_string($connect,$_POST['title']); echo $post_date=date('m-d-y'); echo $post_price=mysqli_real_escape_string($connect,$_POST['price']); echo $post_keywords=mysqli_real_escape_string($connect,$_POST['keywords']); echo $post_content=mysqli_real_escape_string($connect,$_POST['content']); echo $post_image=mysqli_real_escape_string($connect,$_FILES['image']['name']); echo $image_tmp=mysqli_real_escape_string($connect,$_FILES['image']['tmp_name']); if($post_title=='' OR $post_price=='' OR $post_content=='' OR $post_keywords=='' OR $post_image=''){ echo "<script> alert('None of the post fields can be left blank')</script>"; }else{ //moves uploaded image into the image file move_uploaded_file($image_tmp,"../images/$post_image"); $insert_query="INSERT INTO posts (post_title,post_date,post_price,post_image,post_keywords,post_content) VALUES('$post_title','$post_date','$post_price','$post_image','$post_keywords','$post_content')"; if(mysqli_query($connect,$insert_query)){ echo "<script>alert('Succefully posted'); </script>"; } else "<h1> Did not work </h1>"; } if (is_uploaded_file($_FILES['image']['tmp_name'])) { echo "uploaded"; }else echo "could not upload"; var_dump(getcwd()); echo "<a href='logout.php'> Log out </a> <br/>"; echo "<a href='view_posts.php'> View Posts </a>"; ?> <?php } ; ?> here is the html <html> <head> <title> inserting new posts </title> <link rel="stylesheet" type="text/css" href="admin_style.css"> </head> <body> <div id="edit_postform"> <form method="post" action="insert_post.php" enctype="multipart/form-data"> <table width="600" align="centre" border"10"> <tr> <td> <h1> Insert New Post here </h1> </td> </tr> <tr> <td> Post title <td> <td> <input type="text" name="title" size="30"> </td> </tr> <tr> <td> Post Price<td> <td> <input type="text" name="price" size="30"> </td> </tr> <tr> <td> Post keywords<td> <td> <input type="text" name="keywords" size="30"> </td> </tr> <tr> <td> Post image <td> <td> <input type="file" name="image"> </td> </tr> <tr> <td> Post Content <td> <td> <textarea name="content" cols="20" rows="20" size="30"> </textarea> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Publish now"> </td> </tr> </table> </form> </div> </body> </html>
  2. i am getting this error Notice: Undefined index: image . i am trying to upload an image to databse . I cannot figure out whats going on , everything else uploads except the image, not even the image name is uploaded to database below is code the size of the file is only 3kb. the echo $max_upload = (int)(ini_get('upload_max_filesize')); echo "<pre>" . print_r($_POST, true) . "</pre>"; echo "<pre>". var_dump($_FILES['image']) . "</pre>"; the print_r displays as Array ( [title] => This is a post [author] => Me [keywords] => posting [image] => url.jpg [content] => this is a new post [submit] => Publish now ) displays as NULL the vardump below is actual code. <html> <head> <title> inserting new posts </title> </head> <body> <form method="post" action="insert_post.php" enctype="multipart/form-data/"> <table width="600" align="centre" border"10"> <tr> <td> <h1> Insert New Post here </h1> </td> </tr> <tr> <td> Post title <td> <td> <input type="text" name="title" size="30"> </td> </tr> <tr> <td> Post Author<td> <td> <input type="text" name="author" size="30"> </td> </tr> <tr> <td> Post keywords<td> <td> <input type="text" name="keywords" size="30"> </td> </tr> <tr> <td> Post image <td> <td> <input type="file" name="image"> </td> </tr> <tr> <td> Post Content <td> <td> <textarea name="content" cols="20" rows="20" size="30"> </textarea> </td> </tr> <tr> <td> Post title <td> <td> <input type="text" name="title" size="30"> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Publish now"> </td> </tr> </table> </form> </body> </html> <?php include('../includes/connect.php'); if(isset($_POST['submit'])){ echo $post_title=$_POST['title']; echo $post_date=date('d-m-y'); echo $post_author=$_POST['author']; echo $post_keywords=$_POST['keywords']; echo $post_content=$_POST['content']; echo $post_image=$_FILES['image']['name']; echo $image_tmp=$_FILES['image']['tmp_name']; if($post_title=='' or $post_keywords=='' or $post_content=='' or $post_author==''){ echo "<script> alert('none of the fields can be empty')</script>"; exit(); } else{ move_uploaded_file($image_tmp,"../images/$post_image"); //query is below to insert data $insert_query="INSERT into posts (post_title,post_date,post_author,post_image,post_keywords,post_content) VALUES('$post_title','$post_date','$post_author','$post_image','$post_keywords','$post_content')"; if(mysqli_query($connect,$insert_query)){ echo " <h1> successfully Posted </h1> "; } else " h1> Did not work </h1>"; } } echo $max_upload = (int)(ini_get('upload_max_filesize')); echo "<pre>" . print_r($_POST, true) . "</pre>"; echo "<pre>". var_dump($_FILES['image']) . "</pre>"; ?> thanks in advance guys.
×
×
  • 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.