I am working on CMS project and dealing with form which is adding information into mysql. Everything is working fine but the "textarea" seems like too simple even with tinymce. I am looking for any advice that help to improve the "texarea" such as add multiple images ( mine is only allowed one).
Thanks you and please abandon my bad English
Here is my code:
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
<form method="post" action="insert_post.php" enctype="multipart/form-data">
<table width="800" align="center" border="10">
<tr>
<td align="center" bgcolor="yellow" colspan="6"><h1>Insert New Post Here</h1></td>
</tr>
<tr>
<td align="right">Post Title:</td>
<td><input type="text" name="post_title" size="30"></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Category:</strong></td>
<td>
<select name="cat">
<option>Select a Category</option>
<?php
include("includes/connect.php");
$get_cats = "select * from catelogries";
$run_cats = mysql_query($get_cats);
while ($cats_row=mysql_fetch_array($run_cats)){
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right">Post Author:</td>
<td><input type="text" name="post_author" size="30"></td>
</tr>
<tr>
<td align="right">Post Keywords:</td>
<td><input type="text" name="post_keywords" size="30"></td>
</tr>
<tr>
<td align="right">Post Image:</td>
<td><input type="file" name="post_image"></td>
</tr>
<tr>
<td align="right">Post Content:</td>
<td><textarea name="post_content" cols="30" rows="15"></textarea></td>
</tr>
<tr>
<td align="center" colspan="6"><input type="submit" name="submit" value="Publish Now"></td>
</tr>
</table>
<?php
if(isset($_POST['submit'])){
$post_title = $_POST['post_title'];
$post_date = date('m-d-y');
$post_cat = $_POST['cat'];
$post_author = $_POST['post_author'];
$post_keywords = $_POST['post_keywords'];
$post_content = $_POST['post_content'];
$post_image= $_FILES['post_image']['name'];
$post_image_tmp= $_FILES['post_image']['tmp_name'];
if( $post_title=='' or $post_cat=='null' or
$post_author=='' or $post_keywords=='' or
$post_content=='' or $post_image=='')
{
echo "<script>alert('Any of the fields is empty')</script>";
exit();
} else {
move_uploaded_file($post_image_tmp,"../images/$post_image");
$insert_posts = "insert into posts
(category_id,post_title,post_date,
post_author,post_image,post_keywords,
post_content)
values ('$post_cat','$post_title','$post_date',
'$post_author','$post_image','$post_keywords',
'$post_content')";
mysql_query($insert_posts);
echo "<script>alert('post published successfuly')</script>";
exit();
}
}
?>
Related
So I'm working on creating an ecommerce system and have successfully set up the main bits. My database is running with 2 tables so far, "Categories" and "Products".
Categories is successfully connected to my index.php file but products is not connecting. Basically, if I insert data to Categories from my html file, it will show up on PhpMyAdmin, but the same wouldn't work for products.
I will post below the code for the related files. I would REALLY appreciate some help on this as I've been stuck on this issue for days now! Thank you
If you would prefer for me to email you the whole folder please let me know
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
</head>
<body bgcolor="limegreen">
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="750px" border="2" bgcolor="white">
<tr align="center">
<td colspan="7">
<h2>Insert New Product Here</h2>
</td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="50" /></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat">
<option>Select a Category</option>
<?php
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Quantity:</b></td>
<td><input type="text" name="product_quantity" /></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="40" rows="10" /></textarea>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" /></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name="product_keywords" size="50" /></td>
</tr>
<tr align="center">
<td colspan="7"><input type="submit" name="insert_post" value="Insert Product Now" /></td>
</tr>
</table>
</form>
</body>
</html>enter code here
<?php
if(isset($_POST['insert_post'])){
//getting text data from fields
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_price = $_POST['product_price'];
$product_quantity = $_POST['product_quantity'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting the image from the fields
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
echo $insert_product = "insert into product (product_title,product_cat,product_price,product_quantity,product_desc,product_image,product_keywords) values ('$product_title','$product_cat','$product_price','$product_quantity','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "<script>alert('Product has been inserted!')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";
}
}
?>
I am trying to follow a tutorial and seem not to be able to add the data into the database and have did check the code and do not seem to find why it is not working. The code should insert the data into the database but instead the page refreshes when the button is clicked. kindly please point out where i gone wrong. as i am also new to php. below would be my code:
<!DOCTYPE>
<?php
include ("includes/db.php");
?>
<html>
<head>
<title>inserting Product</title>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
tinymce.init({ selector:'textarea' });
</script>
</head>
<body bgcolor="skyblue">
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="700" border="2" bgcolor="orange">
<tr align="center">
<td colspan="7"><h2>Insert New Post Here</h2></td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="60" required /></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" >
<option>Select a Category</option>
<?php
$get_cats ="select * from categories";
$run_cats = mysqli_query($con, $get_cats);
While ($row_cats=mysqli_fetch_array($run_cats)){
//$cat_id = $row_cats['cats_id'];
$cat_title = $row_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" >
<option>Select a Brand</option>
<?php
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
While ($row_brands=mysqli_fetch_array($run_brands)){
//$cat_id = $row_cats['cats_id'];
$brand_title = $row_brands['brand_title'];
echo "<option value='brand_id'>$brand_title</option>";
}
?>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" required /></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" required /></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name="product_keywords" size="50" required /></td>
</tr>
<tr align="center">
<td colspan="7"><input type="submit" name="inset_post" value="Insert Product Now" /></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//input data from the fields
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//input image from feild
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
//move_uploaded_file($product_image_tmp,"product_images/$product_image");
echo $insert_product = "insert into products(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)values('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
//$insert_pro = mysqli_query($con, $insert_product);
//if($insert_pro){
//echo"<script>alert('Product has been inserted!')</script>";
//echo "<script>window.open('insert_product.php','_self'</script>)";
//}
}
?>
enter code here
Your submit button has name "inset_post" instead of "insert"
I am using phpcode to get data from form and upload it into database. But the data is not saved in database.Here 'insert_product.php' is the file where the entire code resides and form is redirected to same page after button is clicked. Anyone can help?
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="795" border="2" bgcolor="#187eae">
<tr align="center">
<td colspan="7"><h2>Insert New Post Here</h2></td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="60" required/></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" >
<option>Select a Category</option>
<option value="1">Laptop</option>
<option value="2">Computer</option>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" >
<option>Select a Brand</option>
<option value="1">LG</option>
<option value="2">Samsung</option>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" /></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name="product_keywords" size="50" required/></td>
</tr>
<tr align="center">
<td colspan="7"><input type="submit" name="insert_post" value="Insert Product Now"/></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//getting the text data from the fields
$product_title = $_POST['product_title'];
$product_cat= $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting the image from the field
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
$insert_product = "insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "<script>alert('Product Has been inserted!')</script>";
echo "<script>window.open('index.php?insert_product','_self')</script>";
}
}
?>
If this is the entire code, I can't find something like $con = mysqli_connect(...)
Obviously you need to connect to the database before executing any queries on it
You need to connect to database first like so:
$con = mysqli_connect("localhost","my_user","my_password","my_db");
More on database connections here. And if I was you I would start simple by first getting the connection working, then inserting data into to the table and only when you have a good grasp of those I would move onto uploading files.
Please look into this code unable to find out the actual error:
This is PHP upload code:
<?php
include_once("config.php");
if(isset($_GET['pro_id']))
{
$id=$_GET['pro_id'];
if(isset($_POST['submitBtn'])) {
$dept_id = $_POST['dept_id'];
$cat_id = $_POST['cat_id'];
/*$pro_id = $_POST['pro_id'];*/
$pro_name = $_POST['pro_name'];
$pro_desc = $_POST['pro_desc'];
$pro_spec = $_POST['pro_spec'];
$pro_price = $_POST['pro_price'];
$status = 'on';
$pro_keywords = $_POST['pro_keywords'];
//image names
$pro_image = $_FILES['pro_image']['name'];
//temp images names
$temp_image = $_FILES['pro_image']['tmp_name'];
if($dept_id=='' OR $cat_id=='' OR $pro_name=='' OR $pro_desc=='' OR $pro_spec=='' OR $pro_price=='' OR $pro_image=='' OR $pro_keywords=='')
{
echo "<script>alert('All the fields are mandatory')</script>";
exit();
}
else
{
//upload image to folder
move_uploaded_file($temp_image,"images/product_images/$pro_image");
$run_query1 = mysqli_query($login, "update products1 SET (dept_id,cat_id,pro_name,pro_desc,pro_spec,pro_price,pro_image,status,date,pro_keywords) values ( '$dept_id','$cat_id','$pro_name','$pro_desc','$pro_spec','$pro_price','$pro_image','$status','NOW()','$pro_keywords' WHERE pro_id='$id'");
if($run_query1)
{
echo "<script>alert('Product updated successfully')</script>";
exit();
}
else
{
echo "<script>alert('Errors')</script>";
}
} }
$query1 = mysqli_query($login, "select * from products1 where pro_id='$id'");
$query2 = mysqli_fetch_array($query1);
?>
This the form Part where data retrieve from table and when click on the update button nothing happened and page is redirected to view data page and showing the old data:
<form action="ViewProduct.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="650" border="0">
<tr>
<td width="183" align="right">Department:</td>
<th width="231" align="left">
<select name="dept_id" id="dept_id">
<option>Select Department</option>
<?php
$result=dept_show();
while($row=mysqli_fetch_assoc($result))
{
echo "<option value='{$row['dept_id']}'>{$row['dept_name']}</option>";
}
?>
</select></th></tr>
<tr>
<td width="183" align="right">Catagory</td>
<th width="231" align="left">
<select name="cat_id" id="cat_id">
<option>Select Catagory</option>
<?php
$result1=cat_show();
while($row=mysqli_fetch_assoc($result1))
{
echo "<option value='{$row['cat_id']}'>{$row['cat_name']}</option>";
}
?>
</select></th></tr>
<tr>
<!--<td width="231"><input type="hidden" name="pro_id" id="pro_id" value="<t?php echo $pro_id; ?>" /></td>-->
</tr>
<tr>
<td align="right">Product Name/Model:</td>
<td><input type="text" name="pro_name" id="pro_name" value="<?php echo $query2['pro_name']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Description:</td>
<td><textarea type="textarea" name="pro_desc" id="pro_desc" cols="45" rows="5"><?php echo $query2['pro_desc']; ?></textarea></td>
</tr>
<tr>
<td align="right">Products Specification:</td>
<td><textarea type="textarea" name="pro_spec" id="pro_spec" cols="45" rows="5"><?php echo $query2['pro_spec']; ?></textarea></td>
</tr>
<tr>
<td align="right">Product Price:</td>
<td><input type="text" name="pro_price" id="pro_price" value="<?php echo $query2['pro_price']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Image:</td>
<td><input type="file" name="pro_image" id="pro_image" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><input size="45" type="text" name="text" id="text" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td align="right">Keywords:</td>
<td><input size="45" type="text" name="pro_keywords" id="pro_keywords" value="<?php echo $query2['pro_keywords']; ?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submitBtn" id="submit" value="Update" /></td>
</tr>
</table>
</form>
</div> <?php } ?>
</td>
</tr>
</table>
</div>
Form method is POST and you are using GET method in if loop
if(isset($_GET['pro_id']))
Use POST here.
I have made the changes in you complete code. Use this code and if required made the changes (if issues arrived)
PHP code
<?php
include_once("config.php");
if(isset($_POST['submitBtn']))
{
$dept_id = $_POST['dept_id'];
$cat_id = $_POST['cat_id'];
$pro_id = $_POST['pro_id'];*/
$pro_name = $_POST['pro_name'];
$pro_desc = $_POST['pro_desc'];
$pro_spec = $_POST['pro_spec'];
$pro_price = $_POST['pro_price'];
$status = 'on';
$pro_keywords = $_POST['pro_keywords'];
//image names
$pro_image = $_FILES['pro_image']['name'];
//temp images names
$temp_image = $_FILES['pro_image']['tmp_name'];
if($dept_id=='' OR $cat_id=='' OR $pro_name=='' OR $pro_desc=='' OR $pro_spec=='' OR $pro_price=='' OR $pro_image=='' OR $pro_keywords=='')
{
echo "<script>alert('All the fields are mandatory')</script>";
exit();
}
else
{
//upload image to folder
move_uploaded_file($temp_image,"images/product_images/$pro_image");
$run_query1 = mysqli_query($login, "update products1 SET (dept_id,cat_id,pro_name,pro_desc,pro_spec,pro_price,pro_image,status,date,pro_keywords) values ( '$dept_id','$cat_id','$pro_name','$pro_desc','$pro_spec','$pro_price','$pro_image','$status','NOW()','$pro_keywords' WHERE pro_id='$id'");
if($run_query1)
{
echo "<script>alert('Product updated successfully')</script>";
exit();
}
else
{
echo "<script>alert('Errors')</script>";
}
}
}
$query2 = array();
if(isset($_GET['pro_id']))
{
$id=$_GET['pro_id'];
$query1 = mysqli_query($login, "select * from products1 where pro_id='$id'");
$query2 = mysqli_fetch_array($query1);
}
?>
HTML Code
<form action="ViewProduct.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="650" border="0">
<tr>
<td width="183" align="right">Department:</td>
<th width="231" align="left">
<select name="dept_id" id="dept_id">
<option>Select Department</option>
<?php
$result=dept_show();
while($row=mysqli_fetch_assoc($result))
{
echo "<option value='{$row['dept_id']}'>{$row['dept_name']}</option>";
}
?>
</select></th></tr>
<tr>
<td width="183" align="right">Catagory</td>
<th width="231" align="left">
<select name="cat_id" id="cat_id">
<option>Select Catagory</option>
<?php
$result1=cat_show();
while($row=mysqli_fetch_assoc($result1))
{
echo "<option value='{$row['cat_id']}'>{$row['cat_name']}</option>";
}
?>
</select></th></tr>
<tr>
<td width="231"><input type="hidden" name="pro_id" id="pro_id" value="<t?php echo $pro_id; ?>" /></td>
</tr>
<tr>
<td align="right">Product Name/Model:</td>
<td><input type="text" name="pro_name" id="pro_name" value="<?php echo $query2['pro_name']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Description:</td>
<td><textarea type="textarea" name="pro_desc" id="pro_desc" cols="45" rows="5"><?php echo $query2['pro_desc']; ?></textarea></td>
</tr>
<tr>
<td align="right">Products Specification:</td>
<td><textarea type="textarea" name="pro_spec" id="pro_spec" cols="45" rows="5"><?php echo $query2['pro_spec']; ?></textarea></td>
</tr>
<tr>
<td align="right">Product Price:</td>
<td><input type="text" name="pro_price" id="pro_price" value="<?php echo $query2['pro_price']; ?>" /></td>
</tr>
<tr>
<td align="right">Product Image:</td>
<td><input type="file" name="pro_image" id="pro_image" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><input size="45" type="text" name="text" id="text" value="<?php echo $query2['pro_image']; ?>" /></td>
</tr>
<tr>
<td align="right">Keywords:</td>
<td><input size="45" type="text" name="pro_keywords" id="pro_keywords" value="<?php echo $query2['pro_keywords']; ?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submitBtn" id="submit" value="Update" /></td>
</tr>
</table>
</form>
</div> <?php } ?>
</td>
</tr>
</table>
Your pro_id field is commented out in your HTML using <!-- and -->, so the following never is true:
if(isset($_GET['pro_id']))
Also, you have a mismatch between your form method POST and $_GET that you are looking for.
Your query of update is correct? I think you must use
UPDATE products1 SET dept_id='$dept_id',cat_id ='$cat_id'... the rest of values
WHERE pro_id='$id'
And verify if your dept_id is INT as well cat_id, so if they are INT you don't need ''
UPDATE products1 SET dept_id=$dept_id,cat_id =$cat_id
Try to do this steps:
First thing comment out this line,
<!--<td width="231"><input type="hidden" name="pro_id" id="pro_id" value="<t?php echo $pro_id; ?>" /></td>-->
next step,
you are sending data using POST i.e. (form method="post"), so use this
if(isset($_POST['pro_id'])) , then comment out $pro_id = $_POST['pro_id'];
you will get $pro_id value.
i found the insert to database code on internet, use it for trying and its works. but, after i add on some more column, i got error on inserting data to database. which i'm using this code
error_reporting(E_ALL);
ini_set('display_errors','on');
to determine error location, but its show no error on coding. only goes to error result. could anyone help me looking for my mistake and my code error?
here is my insert2_db.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="insert_ac.php" onSubmit="return checkinput(this)">
<table width="100%" height="398" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="9"><strong>Insert Data Into EXA_mySQL Database </strong></td>
</tr>
<tr>
<td width="106">MACHINE ID</td>
<td width="6">:</td>
<td colspan="3"><input name="id_mesin" type="text" id="id_mesin"></td>
<td colspan="2">BRAND</td>
<td width="9">:</td>
<td width="164"><select name="jenama">
<option selected>Please select :</option>
<option value="SHARP">SHARP</option>
<option value="TOSHIBA">TOSHIBA</option>
<option value="CANON">CANON</option>
<option value="SAMSUNG">SAMSUNG</option>
<option value="MEXTEC">MEXTEC</option>
</select></td>
</tr>
<tr>
<td>MODEL</td>
<td>:</td>
<td colspan="3"><input name="model" type="text" id="model"></td>
<td colspan="2">METER START</td>
<td>:</td>
<td><input name="meter_awal" type="text" id="meter_awal" value="0"></td>
</tr>
<tr>
<td>SERIAL NO</td>
<td>:</td>
<td colspan="3">MACHINE</td>
<td colspan="2">FEEDER</td>
<td> </td>
<td>FINISHER</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><input name="siri_mesin" type="text" id="siri_mesin"></td>
<td colspan="3"><input name="siri_feeder" type="text" id="siri_feeder"></td>
<td><input name="siri_finisher" type="text" id="siri_finisher"></td>
</tr>
<tr>
<td>STOCK IN</td>
<td>:</td>
<td width="58">DATE</td>
<td width="8">:</td>
<td width="220"><input type="text" name="stok_in" id="stok_in"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="in_do" id="in_do"></td>
</tr>
<tr>
<td>LOCATION</td>
<td>:</td>
<td colspan="3"><select name="lokasi">
<option selected>Please select :</option>
<option value="HQ WAREHOUSE">HQ WAREHOUSE</option>
<option value="CHENDERING WAREHOUSE">CHENDERING WAREHOUSE</option>
</select></td>
<td colspan="2">J.S.O</td>
<td>:</td>
<td><input type="text" name="js_order" id="js_order"></td>
</tr>
<tr>
<td>STOCK OUT</td>
<td>:</td>
<td>DATE</td>
<td>:</td>
<td><input type="text" name="stok_out" id="stok_out"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="out_do" id="out_do"></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td colspan="7"><input name="pelangan" type="text" id="pelangan" size="90"></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:</td>
<td colspan="7"><textarea name="pelangan_alamat" cols="69" id="pelangan_alamat"></textarea></td>
</tr>
<tr>
<td>CONTACT PERSON</td>
<td>:</td>
<td colspan="4"><input name="pelangan_person" type="text" id="pelangan_person" size="50"></td>
<td width="109">NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="pelangan_no" id="pelangan_no"></td>
</tr>
<tr>
<td>TECHNICIAN INCHARGE</td>
<td>:</td>
<td colspan="4"><input name="tech" type="text" id="tech" size="50"></td>
<td>NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="tech_no" id="tech_no"></td>
</tr>
<tr>
<td>STATUS</td>
<td>:</td>
<td colspan="3"><select name="status">
<option selected>Please select :</option>
<option value="ORDER PURCHASE">ORDER PURCHASE</option>
<option value="RENTAL">RENTAL</option>
<option value="HIRE PURCHASE">HIRE PURCHASE</option>
</select></td>
<td colspan="3"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
<td colspan="3"><input type="reset" value="Clean" /></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
and my insert_ac.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin=$_POST['id_mesin'];
$jenama=$_POST['jenama'];
$model=$_POST['model'];
$siri_mesin=$_POST['siri_mesin'];
$siri_feeder=$_POST['siri_feeder'];
$siri_finisher=$_POST['siri_finisher'];
$meter_awal=$_POST['meter_awal'];
$lokasi=$_POST['lokasi'];
$status=$_POST['status'];
$pelangan=$_POST['pelangan'];
//$rekod=$_POST['rekod'];
$stok_in=$_POST['stok_in'];
$stok_out=$_POST['stok_out'];
$in_do=$_POST['in_do'];
$out_do=$_POST['out_do'];
$pelangan_alamat=$_POST['pelangan_alamat'];
$pelangan_no=$_POST['pelangan_no'];
$pelangan_person=$_POST['pelangan_person'];
$js_order=$_POST['js_order'];
$tech=$_POST['tech'];
$tech_no=$_POST['tech_no'];
//$sql2="SELECT * FROM aset where id_mesin = '".$id_mesin."'";
//$result2=mysqli_query($con, $sql2);
$sql="INSERT INTO aset(id_mesin, jenama, model, siri_mesin, siri_feeder, siri_finisher, meter_awal, lokasi, status, pelangan, stok_in, stok_out, in_do, out_do, pelangan_alamat, pelangan_no, pelangan_person, js_order, tech, tech_no) VALUES('$id_mesin', '$jenama', '$model', '$siri_mesin', $siri_feeder, $siri_finisher, '$meter_awal', '$lokasi', '$status', '$pelangan', '$stok_in', '$stok_out', '$in_do', $out_do, $pelangan_alamat, '$pelangan_no', '$pelangan_person', '$js_order', '$tech', '$tech_no')";
$result=mysqli_query($con, $sql);
if($result){//if ($result2 !== 1){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL'>";
echo "</form></th>}";
}//}
else {
echo "Data error, please check your submit.";
echo "<BR>";
echo "<a href='insert.php'>Back to insert form</a>";
}
mysqli_close($con);
?>
</body>
</html>
i'm also using some dropdown list as input on my form, which initial value = Please select: and it has null value. i cant insert data even i put all information on my insert form, all goes to this error result.
echo "Data error, please check your submit.";