hance2105 Posted June 5, 2013 Share Posted June 5, 2013 hello guys i worked out the codes to update a row in my sql database table. in fact i select the product id and some fields are populated automatically. the category, subcategory and photo upload do not populate as those have to be done by the user when updating the product. i think there is some issue with my update code below. can anyone help? <?php if(isset($_POST['update'])){ include('db_connect.php'); $prod_id=$_POST['prod_id']; $prod_name=$_POST['prod_name']; $prod_brand=$_POST['prod_brand']; $prod_desc=$_POST['prod_desc']; $prod_price=$_POST['prod_price']; $cat=$_POST['cat']; $subcat=$_POST['subcat']; $prod_w_c=$_POST['prod_w_c']; $prod_photo=$_POST['prod_photo']; $url='upd_prod.php'; $sql=$sql_query("UPDATE tbl_product SET prod_name='$prod_name', prod_brand='$prod_brand', prod_desc='$prod_desc', prod_price='$prod_price', cat='$cat', subcat='$subcat', prod_w_c='$prod_w_c', prod_photo='$prod_photo' WHERE prod_id='$prod_id'"); if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else { echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; echo "<script>alert('Product successfully updated')</script>"; } } ?> Quote Link to comment Share on other sites More sharing options...
Strider64 Posted June 5, 2013 Share Posted June 5, 2013 First of wrap you code: // Check to see if edited data has been submitted by the user: if (isset($_POST['action']) && $_POST['action'] == 'enter') { // Determine if post should be sticky or not: $sticky = $_POST['sticky']; if(!$user->isAdmin()) { $sticky = 'no'; } // Update the edited text: $query = 'UPDATE pages SET creatorId = :creatorId, sticky = :sticky, title = :title, content = :content, dateUpdated = NOW() WHERE id=:id'; // Prepare the Statement: $stmt = $pdo->prepare($query); // Clean-up user content: // Setup an array - 'title' and 'content' are the keys: $data = array('title' => $_POST['title'], 'content' => $_POST['content']); // Create an new instance: $dirtyWord = new DirtyWord($data); // Check you content for bad language: $title = $dirtyWord->checkTitle; $content = $dirtyWord->checkContent; // execute the statement: $show_details = $stmt->execute(array(':creatorId' => $user->getId(), ':sticky' => $sticky, ':title' => $title, ':content' => $content, ':id' => $page->getId())); } Secondly what you are you using is depreciated http://www.php.net/manual/en/function.mysql-connect.php and I would advised you reading up on this then using either: http://us1.php.net/manual/en/mysqli.construct.php (mysqli) or http://us1.php.net/manual/en/pdo.construct.php (pdo) Lastly the above code is how you update something in PDO, it was written in OOP but php.net shows examples on how to do things the procedural way and once you get code written the correct way I'm sure people here will gladly help you out if you are stock. Quote Link to comment Share on other sites More sharing options...
Solution hance2105 Posted June 5, 2013 Author Solution Share Posted June 5, 2013 thanks for the help my friend. i managed to sort this out and solved it myself a few minutes ago. now am having an issue with the other post i launched here. the enable/disable rows in mysql Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 5, 2013 Share Posted June 5, 2013 so - why not mark this as answered??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.