php - UPDATE reports successful but not updating the table -
hey trying update table form have:
<?php include ('includes/header.php'); require ('../db_con.php'); // check valid document id, through or post: if ( (isset($_get['id'])) && (is_numeric($_get['id'])) ) { // view_docs.php $id = $_get['id']; } elseif ( (isset($_post['id'])) && (is_numeric($_post['id'])) ) { // form submission. $id = $_post['id']; } else { // no valid id, kill script. echo '<p class="error">this page has been accessed in error.</p>'; exit(); } $q = "select * cats cat_id = $id"; $r = mysqli_query($dbc, $q); ?> <form method="post" action="actions/update_cat.php"> <input type="hidden" name="cat_id" value="<? echo $id ?>" /> <input type="text" name="cat_name" /> <br><br> <input type="text" name="cat_color" /> <br><br> <input type="text" name="cat_icon" /> <br><br> <input type="submit" value="submit" /> </form>
when submit action script know passes on values fro input forms here action script - , before points out there no measures preventing sql injection yet:
<?php require ('../../db_con.php'); $cat_id = $_post['cat_id']; $cat_name = $_post['cat_name']; $cat_color = $_post['cat_color']; $cat_icon = $_post['cat_icon']; $q = "update cats set cat_name='cat_name', cat_color='cat_color', cat_icon='cat_icon' cat_id='cat_id'"; if (mysqli_query($dbc, $q)) { echo "record updated successfully"; } else { echo "error updating record: " . mysqli_error($dbc); } mysqli_close($dbc); ?>
so reports me updated isn't updating table?
your query not have dynamic values in...
$q = "update cats set cat_name='$cat_name', cat_color='$cat_color', cat_icon='$cat_icon' cat_id='$cat_id'";
Comments
Post a Comment