Jump to content

undifened index


Alfraganus

Recommended Posts

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 by Alfraganus
Link to comment
Share on other sites

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 by Alfraganus
Link to comment
Share on other sites

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

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

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

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

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 by Chikwado
Link to comment
Share on other sites

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 by Alfraganus
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...