0

check my code and inform me why data is not inserted in database

<!DOCTYPE> <?php session_start(); include("includes/db_connect.php"); ?> <html> <head> <title>Post your add </title> <link rel="stylesheet" href="style.css" media="all"/> </head> <body> <form action="insert_post.php" method="post" enctype="multipart/form-data"> <table width="800" align="center" border="2"> <tr align="center"> <td colspan="6" bgcolor="grey"><h1>Insert New Post: </h1></td> </tr> <tr> <td align="right"><strong>Name:</strong> </td> <td><input type="text" name="name" required/></td> </tr> <tr> <td align="right"><strong>Ad Title:</strong></td> <td><input type="text" name="ad_title" required/></td> </tr> <tr> <td align="right"><strong>Address:</strong></td> <td><input type="text" name="address" required/></td> </tr> <tr> <td align="right"><strong>Country:</strong></td> <td><input type="text" name="country" required/></td> </tr> <tr> <td align="right"><strong>City:</strong></td> <td><input type="text" name="city" required/></td> </tr> <tr> <td align="right"><strong>Category:</strong></td> <td> <select name="cats"> <option value="null">Select a Category</option> <option>Books</option> <?php include("includes/db_connect.php"); if(isset($_GET['edit_cats'])){ $cats_id = $_GET['edit_cats']; $get_cats = "select * from categories where cats_id='$cats_id'"; $run_cats = mysqli_query($con, $get_cats); $row_cats = mysqli_fetch_array($run_cats); $cats_id = $row_cats['cats_id']; $cats_title = $row_cats['cats_title']; } ?> </select> </td> </tr> <tr> <td align="right"><strong>Subcategory:</strong></td> <td> <select name="subcats"> <option value="null">Select a subcategory</option> <option>Books</option> <?php include("includes/db_connect.php"); if(isset($_GET['edit_subcat'])){ $subcats_id = $_GE

6th May 2017, 7:27 PM
M Kamran Yousaf
M Kamran Yousaf - avatar
11 Respostas
+ 6
Then it looks like a working one. Tell us if you see any error, or error in console?
7th May 2017, 2:13 PM
Sachin Artani
Sachin Artani - avatar
+ 4
1. Code is incomplete because there's a limit of characters in Q/A. 2. You've included db_connect.php three times, and that is not good
6th May 2017, 7:37 PM
Sachin Artani
Sachin Artani - avatar
+ 2
@M Kamran i think the table name "recorde" is the typing error you might have done. Please check it
6th May 2017, 10:15 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 2
if($ad_title==''OR $cats=='null'OR $address=='' OR $image=='') replace this by if($ad_title=='"'OR $cats=='null'OR $address==''"OR $image=='')
7th May 2017, 12:47 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
Hey you should also include db_connect where you have written the code for insert query. and make sure you type the same name for connection variable
7th May 2017, 6:12 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
I think you should check for column name in the query and also in the name of column of the table. Can you please post your query with all variables passed into it.
8th May 2017, 7:19 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
Dear sachin Artani this is my sql code check it is this correct or not <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $ad_title = $_POST['ad_title']; $address= $_POST['address']; $country = $_POST['country']; $city = $_POST['city']; $cats = $_POST['cats']; $subcats = $_POST['subcats']; $price = $_POST['price']; $description = $_POST['description']; $image=$_FILES['image']['name']; $image_tmp = $_FILES['image']['tmp_name']; $mobile_no = $_POST['mobile_no']; $email = $_POST['email']; move_uploaded_file($image_tmp,"images/$image"); if($ad_title==''OR $cats=='null'OR $address=='' OR $image=='') { echo "<script>alert('Please fill in all the fields')</script>"; exit(); } mysqli_query($con, "insert into recorde(name,ad_title,address) values ('$name', '$ad_title', '$address')"); echo"<script>alert('Post has been posted')</script>"; echo"<script>window.open('index.php','_self')</script>"; } ?>
6th May 2017, 8:12 PM
M Kamran Yousaf
M Kamran Yousaf - avatar
0
I am correct this error but still data. not insearted in table
6th May 2017, 10:47 PM
M Kamran Yousaf
M Kamran Yousaf - avatar
0
i do this but still same
7th May 2017, 1:56 PM
M Kamran Yousaf
M Kamran Yousaf - avatar
0
Rishabh Argrawal there is no error when I am insert my data they redirect me to home page and also they show me an alert that data has posted and redirect and after the I check my database but there is nothing in it
8th May 2017, 4:48 AM
M Kamran Yousaf
M Kamran Yousaf - avatar
0
i an remove db_connect in my cats and subcats variable and after that when I am create 3 table only for firt 3 form value then all the value are store in database but when I am creat all table they not inserted in database
8th May 2017, 4:51 AM
M Kamran Yousaf
M Kamran Yousaf - avatar