Alfraganus Posted August 27, 2015 Share Posted August 27, 2015 (edited) I cant fint my mistake here, I created database, I created a folder, but my locahost saying that 2 undefined indexes in image which are Notice: Undefined index: image in C:xampphtdocsyangiliklaradmininsert_post.php on line 68Notice: Undefined index: image in C:xampphtdocsyangiliklaradmininsert_post.php on line 70 here is the soursecode <?php include("includes/connect.php"); if (isset($_POST['submit'])) { $post_title=$_POST ['title']; $post_date= date ('d-m-y'); $post_author=$_POST ['author']; $post_keywords=$_POST ['keywords']; $post_content=$_POST ['content']; LINE 68: $post_image=$_FILES ['image']['name']; LINE 70: $image_tmp= $_FILES ['image']['tmp_name']; if($post_title=='' or $post_keywords=='' or $post_content=='' or $post_author=='') { echo "<script>alert ('any on the field is empty') </script>"; exit (); } else { move_uploaded_file($image_tmp, "images/$post_image"); $insert_query="insert into posts (posts_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 (mysql_query($insert_query)) { echo "<center><h1>post published succesfully </h1></center>"; } } } ?> Edited August 27, 2015 by Alfraganus Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2015 Share Posted August 27, 2015 The errors mean that $_FILES does not have an index called "image". What does your form look like? Link to comment Share on other sites More sharing options...
Alfraganus Posted August 27, 2015 Author Share Posted August 27, 2015 (edited) here is my form, but there is image there <body> <form method="post" action="insert_post.php" enctype="mutipart/form-data"> <table width="600" align="center" border="10"> <tr> <td align="center" bgcolor="green" colspan="6"><h2 style="color:red"><b><i>Insert new posts here</i></b></h2></td> </tr> <tr> <td align="right">Post Title</td> <td><input type="text" size="30" name="title"></td> </tr> <tr> <td align="right">Post Author</td> <td><input type="text" size="30" name="author"></td> </tr> <tr> <td align="right">Post keywords</td> <td><input type="text" size="30" name="keywords"></td> </tr> <tr> <td align="right">Post image</td> <td><input type="file" name="image"></td> </tr> <tr> <td align="right"> Post Content</td> <td><textarea name="content" cols="20" rows="15"> </textarea></td> </tr> <tr> <td align="center" colspan="4"><input type="submit" name="submit" value="publish now"> </td> </tr> </table> </form> Edited August 27, 2015 by Alfraganus Link to comment Share on other sites More sharing options...
Don E Posted August 27, 2015 Share Posted August 27, 2015 Looks like you spelled enctype="multipart/form-data" incorrectly, forgot the 'L'. You have: mutipart for multipart 1 Link to comment Share on other sites More sharing options...
Alfraganus Posted August 27, 2015 Author Share Posted August 27, 2015 yeaaah dude, it has been fixed, I am such a blind(( but there is one more challange, the data is not being uploaded to database, when I am clicking the button, nothing is happening. what it could be ? Link to comment Share on other sites More sharing options...
Don E Posted August 27, 2015 Share Posted August 27, 2015 Are you checking/getting any mysql errors anywhere? Just to note, it's recommended to use MySQLi instead of mysql. May not be the reason why but looks like you're missing a single quote for $post_title for the values in your mysql query. It's '$post_title Also make sure you're columns spelled correctly. Link to comment Share on other sites More sharing options...
Alfraganus Posted August 28, 2015 Author Share Posted August 28, 2015 I checked many times to know what is wrong with my codes, but could not find my mistake, my datas are not going to database (mysql database) could you please check if anything wrong with it? here are codes: <?php include("includes/connect.php"); if (isset($_POST['submit'])) { $post_title=$_POST ['title']; $post_date= date ('d-m-y'); $post_author=$_POST ['author']; $post_keywords=$_POST ['keywords']; $post_content=$_POST ['content']; $post_image=$_FILES ['image']['name']; $image_tmp= $_FILES ['image']['tmp_name']; if($post_title=='' or $post_keywords=='' or $post_content=='' or $post_author=='') { echo "<script>alert ('any on the field is empty') </script>"; exit (); } else { move_uploaded_file($image_tmp, "images/$post_image"); $insert_query="insert into posts (posts_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 (mysql_query($insert_query)) { echo "<center><h1>post published succesfully </h1></center>"; } } } ?> HTML-------------------------------------------------------- <body> <form method="post" action="insert_post.php" enctype="multipart/form-data"> <table width="600" align="center" border="10"> <tr> <td align="center" bgcolor="green" colspan="6"><h2 style="color:red"><b><i>Insert new posts here</i></b></h2></td> </tr> <tr> <td align="right">Post Title</td> <td><input type="text" size="30" name="title"></td> </tr> <tr> <td align="right">Post Author</td> <td><input type="text" size="30" name="author"></td> </tr> <tr> <td align="right">Post keywords</td> <td><input type="text" size="30" name="keywords"></td> </tr> <tr> <td align="right">Post image</td> <td><input type="file" name="image"></td> </tr> <tr> <td align="right"> Post Content</td> <td><textarea name="content" cols="20" rows="15"> </textarea></td> </tr> <tr> <td align="center" colspan="4"><input type="submit" name="submit" value="publish now"> </td> </tr> </table> </form> Link to comment Share on other sites More sharing options...
Alfraganus Posted August 28, 2015 Author Share Posted August 28, 2015 I dont know whats wrong with my codes but when I am clicking submit button, my datas are not being uploaded to database, please can you kindly check if I have something wrong? my codes: --------PHP-------------------- I cant fint my mistake here, I created database, I created a folder, but my locahost saying that 2 undefined indexes in image which are Notice: Undefined index: image in C:xampphtdocsyangiliklaradmininsert_post.php on line 68Notice: Undefined index: image in C:xampphtdocsyangiliklaradmininsert_post.php on line 70 here is the soursecode <?php include("includes/connect.php"); if (isset($_POST['submit'])) { $post_title=$_POST ['title']; $post_date= date ('d-m-y'); $post_author=$_POST ['author']; $post_keywords=$_POST ['keywords']; $post_content=$_POST ['content']; $post_image=$_FILES ['image']['name']; $image_tmp= $_FILES ['image']['tmp_name']; if($post_title=='' or $post_keywords=='' or $post_content=='' or $post_author=='') { echo "<script>alert ('any on the field is empty') </script>"; exit (); } else { move_uploaded_file($image_tmp, "images/$post_image"); $insert_query="insert into posts (posts_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 (mysql_query($insert_query)) { echo "<center><h1>post published succesfully </h1></center>"; } } } ?> ----------------HTML------------------------- <body> <form method="post" action="insert_post.php" enctype="multipart/form-data"> <table width="600" align="center" border="10"> <tr> <td align="center" bgcolor="green" colspan="6"><h2 style="color:red"><b><i>Insert new posts here</i></b></h2></td> </tr> <tr> <td align="right">Post Title</td> <td><input type="text" size="30" name="title"></td> </tr> <tr> <td align="right">Post Author</td> <td><input type="text" size="30" name="author"></td> </tr> <tr> <td align="right">Post keywords</td> <td><input type="text" size="30" name="keywords"></td> </tr> <tr> <td align="right">Post image</td> <td><input type="file" name="image"></td> </tr> <tr> <td align="right"> Post Content</td> <td><textarea name="content" cols="20" rows="15"> </textarea></td> </tr> <tr> <td align="center" colspan="4"><input type="submit" name="submit" value="publish now"> </td> </tr> </table> </form> Link to comment Share on other sites More sharing options...
dsonesuk Posted August 28, 2015 Share Posted August 28, 2015 IF inserting into mysql data type of date the format should be y-m-d Link to comment Share on other sites More sharing options...
Alfraganus Posted August 28, 2015 Author Share Posted August 28, 2015 it did not help((( Link to comment Share on other sites More sharing options...
dsonesuk Posted August 28, 2015 Share Posted August 28, 2015 I don't know if this is a typo but you are missing single quote in values ('$post_title, '$post_date','$post_author', '$post_image', '$post_keywords', '$post_content') should be values ('$post_title', '$post_date','$post_author', '$post_image', '$post_keywords', '$post_content') Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 You're not checking for errors and you're using the outdated mysql extension. I would recommend you do some research on PDO and rewrite your queries using PDO with prepared statements instead of the mysql extension. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 I've merged your topics, please don't open multiple topics for the same issue. 1 Link to comment Share on other sites More sharing options...
Alfraganus Posted August 29, 2015 Author Share Posted August 29, 2015 my apologies sir, but I had some problems with internet, when I clicked "post" button, there was an error on page, and I did one more time, I did not know the error also posted my question Link to comment Share on other sites More sharing options...
Chikwado Posted August 31, 2015 Share Posted August 31, 2015 (edited) What you need to do is not what you are doing, You need to learn php form and database. You are not binding parameter to database. Where do you expect the data to go? The code above are not w3schools examples. Edited August 31, 2015 by Chikwado Link to comment Share on other sites More sharing options...
Alfraganus Posted September 4, 2015 Author Share Posted September 4, 2015 (edited) I tried many times, dude, and I achieved a new error instead of the old ones, here is the error: Warning: mysqli_errno() expects exactly 1 parameter, 0 given in C:xampphtdocsyangiliklaradmininsert_post.php on line 103 and here is the php sourse code, I beleive html form is quite normal, the problem should belong to PHP:::: <?php $con=mysqli_connect("localhost","root","","yangiliklar") or die (mysqli_errno()); if (mysqli_connect_errno()) { echo "ulanmadi" .mysqli_connect_errno(); } else { echo "ulandi"; } if (isset($_POST['submit'])) { $post_title=$_POST ['title']; // $post_date= date ('y-m-d'); $post_author=$_POST ['author']; $post_keywords=$_POST ['keywords']; $post_content=$_POST ['content']; $post_image=$_FILES ['image']['name']; $image_tmp= $_FILES ['image']['tmp_name']; // if($post_title=='' or $post_keywords=='' or $post_content=='' or // $post_author=='') { // echo "<script>alert ('any on the field is empty') </script>"; // exit (); // } else { move_uploaded_file($image_tmp, "images/$post_image"); $insert_query="insert into posts (posts_title, post_author, post_image, post_keywords, post_content) values ('$post_title, '$post_author', '$post_image', '$post_keywords', '$post_content')"; line 103: $insert=mysqli_query($con, $insert_query) or die (mysqli_errno()); if ($insert) { echo "<center><h1>post published succesfully </h1></center>"; } else { "<br>"; echo "post has not been published succesfully"; } // } } ?> Edited September 4, 2015 by Alfraganus Link to comment Share on other sites More sharing options...
dsonesuk Posted September 4, 2015 Share Posted September 4, 2015 As the error description describes when using mysqli_errno(), you have to provide connection parameter as in mysqli_errno($con), as described here http://www.w3schools.com/php/func_mysqli_errno.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now