I am working on this form but it's stroing garbage value of the 'phone' field in the database where I am giving the right number. what's wrong in the code? First i set the length of that field to 11 and thought that could be the problem. but when I increased that to even 50 the same problem occurred again. How to solve this?
PS: neglect the security part of the form, it's just for testing purpose.
<table border="1" id="tab1">
<form action="create.php" method="POST" enctype="multipart/form-data">
<tr align='center'><td>Ad Title:</td><td><input type='text' name='ad_title' id="ad_title" placeholder='type ad title'/></td></tr>
<tr align='center'><td>Ad Description:</td><td><textarea name='ad_details' id="ad_details" placeholder='type ad details' cols="40" rows="10"></textarea></td></tr>
<tr align="center"></tr>
<tr align="center"><td>Category:</td><td>
<select name="category">
<option value="mobile">Mobile Phone</option>
<option value="computer">Computer</option>
<option value="book">Books</option>
<option value="fashion">Fashion and Beauty</option>
</select>
</td></tr>
<tr align='center'><td>Phone Number:</td><td><input type='number' id="phone" name='phone' placeholder='type your Phone Number'/></td></tr>
<tr align='center'><td>Email:</td><td><input type='text' name='email' id="email" placeholder='type your email'/></td></tr>
<tr align='center'><td>Price:</td><td><input type='text' name='price' id="price" placeholder='enter your desired Price'/></td></tr>
<tr align="center"><td>Negotiable:</td><td><input type="radio" name="nego" value="yes"/>YES<input type="radio" name="nego" value="no"/>NO</td></tr>
<tr align="center"><td>City/Town:</td><td>
<select name="city">
<option value="Jalpaiguri">Jalpaiguri</option>
<option value="Siliguri">Siliguri</option>
</select>
</td></tr>
<tr align='center'><td>Location:</td><td><input type='text' id="location" name='location' placeholder='type your Location'/></td></tr>
<tr><td>Choose Photo for Ad:</td><td><input type='file' name='ad_pic'/></td></tr>
<tr align='center'><td colspan="7"><input type='submit' id="submit" name ='submit' value='Create Ad'/></td></tr>
</form>
</table>
the php code is as follows:
<?php
session_start();
if(!isset($_SESSION['username'])){
header("location:login.php");
}
$user = $_SESSION['username'];
$conn = new mysqli("localhost","root","","pending");
if($conn->connect_error){
echo "<script>document.getElementById('noti').innerHTML='Database Error.Please Try again !';</script>";
}
if(isset($_POST['submit'])){
$ad_title = $_POST["ad_title"];
$ad_details = $_POST["ad_details"];
$category = $_POST["category"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$nego = $_POST["nego"];
$city = $_POST["city"];
$location = $_POST["location"];
$price = $_POST["price"];
$sql = $conn->query("INSERT INTO ads(ad_id,user_name,ad_title,ad_details,price,category,phone,email,negotiable,city,location) VALUES('','$user','$ad_title','$ad_details','$price','$category','$phone','$email','$nego','$city','$location')");
$pid = $conn->insert_id;
$newname = "$pid.jpg";
move_uploaded_file($_FILES['ad_pic']['tmp_name'], "ad_images/$newname");
}
?>