PHP update data to mysql (ERROR with undefined variable) - php

This is the part of the code:
It first retrieves the information according to the id. but When i change one of the information and clicked update, it gives me undefined variable error and couldnt update at all.
<?php
include("includes/connect.php");
if(isset($_GET['edit'])) {
$edit_id = $_GET['edit'];
$edit_query = "select * from posts where post_id = '$edit_id' ";
$run_edit = mysqli_query($con,$edit_query);
while ($edit_row=mysqli_fetch_array($run_edit)) {
$post_id = $edit_row['post_id'];
$post_title = $edit_row['post_title'];
$post_author = $edit_row['post_author'];
$post_keywords = $edit_row['post_keywords'];
$post_image = $edit_row['post_image'];
$post_content = $edit_row['post_content'];
}
}
?>
<form method="post" action="edit.php?edit_form=<?php echo $post_id; ?>" enctype="multipart/form-data">
<table width="600" bgcolor="orange" align="center" border="10">
<tr>
<td align="center" bgcolor="yellow" colspan="6">
<h1>Edit The Post Here</h1>
</td>
</tr>
<tr>
<td align="right">Post Title:</td>
<td><input type="text" name="title" size="30" value="<?php echo $post_title; ?>"></td>
</tr>
<tr>
<td align="right">Post Author:</td>
<td><input type="text" name="author" size="30" value="<?php echo $post_author; ?>"></td>
</tr>
<tr>
<td align="right">Post Keywords:</td>
<td><input type="text" name="keywords" size="30" value="<?php echo $post_keywords; ?>"></td>
</tr>
<tr>
<td align="right">Post Image:</td>
<td>
<input type="file" name="image">
<img src="../images/<?php echo $post_image; ?>"width="100" height="100"></td>
</tr>
<tr>
<td align="right">Post Content:</td>
<td><textarea name="content" cols="30" rows="15"><?php echo $post_content; ?></textarea></td>
</tr>
<tr>
<td align="center" colspan="6"><input type="submit" name="update" id="update" value="Update Now"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['update'])) {
$update_id = $_GET['edit_form'];
$post_title1 = $_POST['title'];
$post_date1 = date('m-d-y');
$post_author1 = $_POST['author'];
$post_keywords1 = $_POST['keywords'];
$post_content1 = $_POST['content'];
$post_image1 = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
if($post_title1 == '' or $post_author1=='' or $post_keywords1=='' or $post_content1=='' or $post_image1=='') {
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else {
move_uploaded_file($image_tmp,"../images/$post_image1");
$update_query = "update posts set post_title='$post_title1', post_date='$post_date1', post_author='$post_author1',post_image='$post_image1',post_keywords='$post_keywords1',post_content='$post_content1' where post_id='$update_id'";
if(mysqli_query($con,$update_query)) {
echo "<script>alert('Post has been updated')</script>";
echo "<script>window.open('view_posts.php','_self')</script>";
}
}
}
?>
Here is the Error. It says undefined variable:

In my opinion, at the first you load script, everything is ok because you GET a page. At this time, isset($_GET['edit']) would true .
After you clicked update (I guess you submit page itself). At this point, isset($_GET['edit']) would false because you're doing POST. So, block code inside
if(isset($_GET['edit'])) {
.....
}
will be skipped. And those variables would be undefined.
Sorry for my english.

Related

Php advance form

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();
}
}
?>

unable to edit data in table using PHP form

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.

Want to update a comma-seperated string

I want to make a CMS that is able to update my articles. When I use the update page I get the following error:
Notice: Undefined variable: post_image in C:\xampp\htdocs\website\admin\edit_posts.php on line 105
This is my code:
<?php
session_start();
if(!isset($_SESSION['user_name'])){
header("location: ../login.php");
}
else {
?>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" href="../apearance/stylesheet.css" />
</head>
<body>
<div id="navbar">
<div id="logo"><img id="logo" src="../apearance/logo.png" height="27px"></div>
<a id="button" href="view_posts.php">View Posts</a>
<a id="button" href="index.php?insert=insert">Insert New Post</a>
<a id="button" href="#">View Comments</a>
<a id="button" href="#">Webshop</a>
<a id="button" href="#">Do do list</a>
<a id="button" href="logout.php"><span style="color:red">Logout</span></a>
<br><hr>
</div>
<?php
include("includes/connect.php");
if(isset($_GET['edit'])){
$edit_id = $_GET['edit'];
$edit_query = "select * from posts where post_id = '$edit_id' ";
$run_edit = mysql_query($edit_query);
while ($edit_row = mysql_fetch_array($run_edit)){
$post_id = $edit_row['post_id'];
$post_title = $edit_row['post_title'];
$post_category = $edit_row['post_category'];
$post_header_image = $edit_row['post_header_image'];
$post_image = $edit_row['post_image'];
$post_content = $edit_row['post_content'];
$post_content2 = $edit_row['post_content2'];
$post_video = $edit_row['post_video'];
}}
?>
<div id="tile" height="100px">
<form method="post" action="edit_posts.php?edit_form=<?php $post_id; ?>" enctype="multipart/form-data">
<table align="center" border="0">
<tr>
<td align="center" colspan="2"><h1>Edit Post Here</h1></td>
</tr>
<tr>
<td align="left">Post Title:</td>
<td><input value="<?php echo $post_title; ?>" type="text" name="title" size="30"></td>
</tr>
<tr>
<td align="left">Post Category:</td>
<td><input value="<?php echo $post_category; ?>" type="text" name="category" size="30"></td>
</tr>
<tr>
<td align="left">Post header Images:</td>
<td>
<input type="file" name="header_image">
</td>
</tr>
<tr>
<td>
</td>
<td>
<img src="../images/<?php echo $post_header_image; ?>" height="100" >
</td>
</tr>
<tr>
<td align="left">Post Content:</td>
<td><textarea name="content" cols="30" rows="15"><?php echo $post_content; ?></textarea></td>
</tr>
<tr>
<td align="left">Post Images:</td>
<td><input type="file" name="files[]" multiple>
</td>
</tr>
<tr>
<td>
</td>
<td>
<?php
$values = explode(',', $post_image);
if( count($values)){
foreach($values as $value){
echo "<img src=\"../images/".$value."\" height=\"100\">";
}
}
?>
</td>
</tr>
<tr>
<td align="left">Post Content2:</td>
<td><textarea name="content2" cols="30" rows="15"><?php echo $post_content2; ?></textarea></td>
</tr>
<tr>
<td align="left">Post Video:</td>
<td><textarea name="video" cols="30" rows="15"><?php echo $post_video; ?></textarea></td>
</tr>
<tr>
<td align="right" colspan="6"><input type="submit" name="submit" value="Update Now"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['update'])){
$update_id = $_GET['edit_form'];
$post_title1 = $_POST['title'];
$post_date1 = date('m-d-y');
$post_category1 = $_POST['category'];
$post_content1 = $_POST['content'];
$post_content21 = $_POST['content2'];
$post_video1 = $_POST['video'];
$post_header_image1= $_FILES['header_image']['name'];
$header_image_tmp= $_FILES['header_image']['tmp_name'];
$filenames = array_values($_FILES['files']['name']);
$post_image1 = rtrim(implode(',', $filenames), ',');
if($post_title1=='' or $post_category1=='' or $post_content1=='' or $post_header_image1==''){
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else {
move_uploaded_file($header_image_tmp,"../images/$post_image1");
$update_query = "update posts set post_title='$post_title1',post_date='$post_date1',post_category='$post_category1',post_header_image='$post_header_image1',post_image='$post_image1',post_content='$post_content1',post_content2='$post_content21',post_video='$post_video1' where post_id='$update_id'";
if(mysql_query($update_query)){
echo "<script>alert('Post has been updated')</script>";
echo "<script>window.open('view_posts.php','_self')</script>";
}
}
}
?>
<?php }?>
Any help would be much appreciated.

Updating sql using php

Im trying to make an update form using php and updating the sql database but it seems not to work here. I tried updating the form and then it should say that its updated but it doesn't want to work. I need help please. Thanks
<?php
include 'connections/connection.php';
$updateinfo = #$_POST['update'];
$get_info = mysql_query("SELECT * FROM customer");
$id = #$_REQUEST['id'];
$get_row = mysql_fetch_assoc($get_info);
$db_cname = $get_row['customer_name'];
$db_cemail = $get_row['customer_email'];
$db_caddress = $get_row['customer_address'];
$db_cphone = $get_row['customer_phone'];
if ($updateinfo) {
$cname = strip_tags(#$_POST['cname']);
$cemail = strip_tags(#$_POST['cemail']);
$caddress = strip_tags(#$_POST['caddress']);
$cphone = strip_tags(#$_POST['cphone']);
//Submit the form to the database
$info_submit_query = mysql_query("UPDATE customer SET customer_name='$cname', customer_email='$cemail', customer_address='$caddress', customer_phone='$cphone' WHERE id='$id'") or die("Error! " . mysql_error());
echo "updated!";
}
else
{
echo "error " . mysql_error();
}
?>
<head>
<title>Customer Modification</title>
</head>
<body>
<table border="0" cellpadding="10" cellspacing="5" width="30%" style="margin-top:100px;" align="center" bgcolor="#FFB13C">
<form action="edit.php" method="post">
<tr>
<td><b>Customer Name:*</b></td>
<td><input type="text" size="50" name="cname" value="<?php echo $db_cname; ?>"></td>
</tr>
<tr>
<td><b>Customer Email:*</b></td>
<td><input type="text" size="50" name="cemail" value="<?php echo $db_cemail; ?>"></td>
</tr>
<tr>
<td><b>Customer Address:*</b></td>
<td><input type="text" size="50" name="caddress" value="<?php echo $db_caddress; ?>"></td>
</tr>
<tr>
<td><b>Customer Phone:*</b></td>
<td><input type="text" size="50" name="cphone" value="<?php echo $db_cphone; ?>"></td>
</tr>
<tr>
<td><input type="reset" name="reset" value="Reset"></td>
<td><input type="submit" name="update" value="Edit"></td>
</tr>
</form>
</table>
</body>

Hidden form relate to targetID

i'm currently trying to solve the edit product, when i pressed edit product and is works great that show everything and allow me to see product image and text filed for us to update it.
After I pressed submit, is updated into the database but after that I got errors in same page relate to inside of forms where it said
<label>
<input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
<input type="submit" name="button" id="button" value="Make change" />
</label>
This error said
Notice: Undefined variable: targetID in C:\VertrigoServ\www\shopone\admin\data\edit_product.php on line 147 Call Stack #TimeMemoryFunctionLocation 10.0010352200{main}( )..\edit_product.php:0 " />
please see full forms section and see at the near end of line...
<form id="form1" name="form1" method="post" action="edit_product.php">
<table width="80%" cellpadding="2" cellspacing="2">
<tr>
<?php echo '<td width="36%" rowspan="9" align="right"> <img src="' . GW_UPLOADPATH . '/' . $screenshot .'" width="351" height="402" /> </td>'; ?>
<td class="text-box1">Product Name:</td>
<td> </td>
<td><input name="product_name" type="text" class="text-field1" id="product_name" value="<?php echo $product_name; ?>" /></td>
<td colspan="2"><!-- Icons --></td>
</tr>
<tr>
<td class="text-box1">Product Category:</td>
<td> </td>
<td><input name="product_category" type="text" class="text-field1" id="product_category" value="<?php echo $product_category; ?>" /></td>
<td colspan="2"><!-- Icons --></td>
</tr>
<tr>
<td class="text-box1">Product Retail Price:</td>
<td> </td>
<td><input name="product_retail_price" type="text" class="text-field1" id="product_retail_price" value="<?php echo $product_retail_price; ?>" /></td>
<td colspan="2"><!-- Icons --></td>
</tr>
<tr>
<td class="text-box1">:Product price:</td>
<td> </td>
<td><input name="product_price" type="text" class="text-field1" id="product_price" value="<?php echo $product_price; ?>" /></td>
<td colspan="2"> </td>
</tr>
<tr>
<td class="text-box1"> </td>
<td> </td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td class="text-box1">Images</td>
<td> </td>
<td> </td>
<td colspan="2"><!-- Icons --></td>
</tr>
<tr>
<td> </td>
<td><label>
<input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
<input type="submit" name="button" id="button" value="Make change" />
</label></td>
</tr>
</tbody>
</table>
</form>
and in the php section...
<?php
$dbcs = new mysqli("localhost", "root", "password", "shopone");
// Check connection
if (mysqli_connect_errno($dbcs))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Parse the form data and update company information to the system
if (isset($_POST['product_name'])) {
$pid = $_POST['thisID'];
$product_name = $_POST['product_name'];
$product_category = $_POST['product_category'];
$product_retail_price = $_POST['product_retail_price'];
$product_price = $_POST['product_price'];
$sql = "UPDATE product SET
product_name='$product_name',
product_category='$product_category',
product_retail_price='$product_retail_price',
product_price='$product_price'
WHERE product_id='$pid'";
$result = mysqli_query($dbcs,$sql);
if(!$sql)
{
print "error";
}
else
{
header("product.php");
}}
// Gather these companies full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
$targetID = $_GET['pid'];
$sql = "SELECT * FROM product WHERE product_id='$targetID' LIMIT 1";
$result=mysqli_query($dbcs,$sql);
while($row = mysqli_fetch_array($result)){
$product_id = $row["product_id"];
$product_name = $row["product_name"];
$product_category = $row["product_category"];
$product_retail_price = $row["product_retail_price"];
$product_price = $row["product_price"];
$screenshot =$row["screenshot"];
}
}
mysqli_close($dbcs);
?>
Does anyone know what is mean and how to solve that!
When you prss the submit button you change the variable from $_GET to $_POST is another script in php I think that you have to implement.
But if you wanna try.. try this:
if (isset($_GET['pid'])) {
$targetID = $_GET['pid'];
$sql = "SELECT * FROM product WHERE product_id='$targetID' LIMIT 1";
$result=mysqli_query($dbcs,$sql);
while($row = mysqli_fetch_array($result)){
$product_id = $row["product_id"];
$product_name = $row["product_name"];
$product_category = $row["product_category"];
$product_retail_price = $row["product_retail_price"];
$product_price = $row["product_price"];
$screenshot =$row["screenshot"];
}
}
else{
if (isset($_POST['pid'])) {
$targetID = $_POST['pid'];
}
}

Categories