How to populate php/html form with MySQL data -
i trying create program in user can update specific product. when user click on update
button, form opens. want populate html
form mysql
data. have written following code giving me error message. sharing html
part of code.i using form inside php echo. kindly check it.
html:
<label>product name:</label> </td> <td> <input type='text' name='product_name' value='<?php echo $fetch['product_id']; ?'/>*required </td> </tr>
error message:
parse error: syntax error, unexpected '' (t_encapsed_and_whitespace), expecting identifier (t_string) or variable (t_variable) or number (t_num_string) in f:\xampp\htdocs\cms\update_single_product.php
complete code
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> </body> </html> <?php include 'connect.php'; $id= $_get['product_id']; $select_query= "select * products left join product_description on products.product_id=$id , product_description.product_id=$id"; if(!$select_query_run= mysql_query($select_query)) { echo mysql_error(); } else { $fetch = mysql_fetch_array ($select_query_run); echo " <form action='insert_product.php' method='post' enctype='multipart/form-data' > <table border=1> <tr> <td> <label>product name:</label> </td> <td><input type='text' name='product_name' value='<?php echo $fetch['product_id']; ?>' />*required</td></tr> <tr><td><label>item no:</label></td> <td><input type='text' name='item_no' ></td></tr> <tr><td> image3:</td><td> <input type='file' name= 'image3' ></td></tr></table> "; /*------------------ drop down list start ------------------ */ echo "<select name='category'>"; $select_query= 'select * category'; $select_query_run = mysql_query($select_query); $sub_category_query= "select * sub_categories"; $sub_query_run= mysql_query($sub_category_query); while ($select_query_array= mysql_fetch_array($select_query_run) ) { echo "<option value='".$select_query_array['category_id']."' >". htmlspecialchars($select_query_array["name"]). "<option value='".$sub_query_run['sub_category_id']."' >" . htmlspecialchars($sub_query_run['sub_category_name']). "</option>". "</option>"; } echo "</br>"; $selecttag= "</br><input type='submit' value='update product' /></select></form>"; echo "</div></div>"; echo $selecttag;
thanks
replace
echo " <form action='insert_product.php' method='post' enctype='multipart/form-data' > <table border=1> <tr> <td> <label>product name:</label> </td> <td><input type='text' name='product_name' value='<?php echo $fetch['product_id']; ?>' />*required</td></tr> <tr><td><label>item no:</label></td> <td><input type='text' name='item_no' ></td></tr> <tr><td> image3:</td><td> <input type='file' name= 'image3' ></td></tr></table> ";
with:
echo '<form action="insert_product.php" method="post" enctype="multipart/form-data"> <table border=1> <tr> <td> <label>product name:</label> </td> <td><input type="text" name="product_name" value="'.$fetch['product_id'].'" />*required</td></tr> <tr><td><label>item no:</label></td> <td><input type="text" name="item_no" ></td></tr> <tr><td> image3:</td><td> <input type="file" name= "image3" ></td></tr></table>';
as can not use echo
inside echo
. , thing don't need write <?php
tags inside echo because you've started php tag.
Comments
Post a Comment