Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "zz224466";
- $database = "zain";
- $conn = mysqli_connect($servername,$username,$password,$database);
- if($conn->connect_error) {
- die("connection failed: " . $conn->connect_error);
- }
- if(isset($_GET['edit'])) {
- $id = $_GET["edit"]; //Get id of sql table from other php page.
- echo $id; //It gives true result. It means that $_GET method above gets id of sql table correctly
- $res = mysqli_query($conn, "SELECT * FROM product where product_id=$id");
- if ($res == FALSE) {
- die("Error");
- }
- $row = mysqli_fetch_array($res);// Getting row from sql of specific id above selected above
- if (isset($_POST['Edit'])) { ///Checking if Edit button has been pressed
- $product_category = $_POST['product_category'];
- $product_id = $id;
- //// SQL query
- $sql_category = "UPDATE product SET product_category='$product_category' WHERE product_id='$product_id'";
- if (mysqli_query($conn, $sql_category)) {
- }
- }
- }
- ?>
- ////////////////////HTML FORM/////////////////////////
- <form method="post" action ="edit.php" id="contact-form">
- <input type="text" name="product_category" placeholder="product_category" value="<?php echo $row['product_category'];//It prints sql record in input field which is to be updated and it prints correctly. But when I press edit button it gives above mentioned error ?>"/>
- <div class="btn-group" role="group">
- <input type="submit" class="btn btn-default" name="Edit" value="Save Edits" style="margin-top: 15px; margin-right: 15px; border-radius: 4px;">
- </div>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement