jamesxg1 Posted March 26, 2009 Share Posted March 26, 2009 <?php session_start(); require("../db/db.php"); require("../db/config.php"); require("../db/util.php"); require("../db/Settings.php"); isloggedin(); accessneeded("A"); $id = $_GET['id']; $sql = "SELECT name, link FROM `menu` WHERE id = '$id' LIMIT 1"; $query = mysql_query($sql) or die(mysql_error()); while ($menu = mysql_fetch_assoc($query)) { $name1 = $menu['name']; $link1 = $menu['link']; } if(isset($_POST['submit'])) { $name = strip_tags(mysql_real_escape_string($_POST['name'])); $link = mysql_real_escape_string($_POST['link']); $sqltwo = "UPDATE menu SET name = '$name', link = '$link' WHERE id = '$id'"; $querytwo = mysql_query($sqltwo) or die(mysql_error()); header("Location: ../Index.php"); exit; } ?> <table> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <P ALIGN=CENTER> <tr><td>Name: <br><INPUT type="text" name="name" id="$name" value="<?php print htmlspecialchars($name1); ?>"></td></tr> <tr><td>Link: <br><INPUT type="text" name="link" id="$link" value="<?php print htmlspecialchars($link1); ?>"></td></tr> <tr><td><input type="submit" name="submit" value="Submit"></P></td></tr> </form> </table> does everything except update the mysql it reffers me to index.php as if it has but it doesnt update and there are no errors. Quote Link to comment https://forums.phpfreaks.com/topic/151179-solved-mysql-wont-update-please-help/ Share on other sites More sharing options...
Maq Posted March 26, 2009 Share Posted March 26, 2009 Cause you need to add an extra hidden field for when you submit. You're losing the $id... Name: Link: //ADDED*** When you submit, now you have to retrieve the id via POST like so: $id = mysql_real_escape_string($_POST['id']); //ADDED* $name = strip_tags(mysql_real_escape_string($_POST['name'])); $link = mysql_real_escape_string($_POST['link']); $sqltwo = "UPDATE menu SET name = '$name', link = '$link' WHERE id = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/151179-solved-mysql-wont-update-please-help/#findComment-794168 Share on other sites More sharing options...
jamesxg1 Posted March 26, 2009 Author Share Posted March 26, 2009 Cause you need to add an extra hidden field for when you submit. You're losing the $id... <tr><td>Name: <br><INPUT type="text" name="name" id="$name" value="<?php print htmlspecialchars($name1); ?>"></td></tr> <tr><td>Link: <br><INPUT type="text" name="link" id="$link" value="<?php print htmlspecialchars($link1); ?>"></td></tr> <input type="hidden" name="id" value="<?php echo $id; ?>"> //ADDED*** <tr><td><input type="submit" name="submit" value="Submit"></P></td></tr> When you submit, now you have to retrieve the id via POST like so: $id = mysql_real_escape_string($_POST['id']); //ADDED* $name = strip_tags(mysql_real_escape_string($_POST['name'])); $link = mysql_real_escape_string($_POST['link']); $sqltwo = "UPDATE menu SET name = '$name', link = '$link' WHERE id = '$id'"; Worked!, Thanks mate. Quote Link to comment https://forums.phpfreaks.com/topic/151179-solved-mysql-wont-update-please-help/#findComment-794173 Share on other sites More sharing options...
Maq Posted March 26, 2009 Share Posted March 26, 2009 Sure, you lost your $id because when you submitted the page it had to refresh and the $_GET variable isn't in the URL anymore so it just gets reset. You probably could have set the action with the variable name in it, but I like the hidden fields better Quote Link to comment https://forums.phpfreaks.com/topic/151179-solved-mysql-wont-update-please-help/#findComment-794180 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.