September 26, 201213 yr On my edit script it works however the page_name after running my edit script changes in the database to Array(inputname) Any ideas why im stumped? <?php session_start(); include "../scripts/connection.php"; if(!isset($_POST['submit'])) { $q = "SELECT * FROM pages WHERE id = $_GET[id]"; $result = mysql_query($q); $row = mysql_fetch_array($result); } ?> <h1>Edit Page</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Page Name<input type="text" name="inputname" value="<?php echo $row['page_name']; ?>" /><br /> Content<input type="text" name="inputcontent" value="<?php echo $row['page_content']; ?>" /><br /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> <input type="submit" name="submit" value="Save" /> </form> <?php if (isset($_POST['submit'])) { $u = "UPDATE pages SET `page_name`='$_POST(inputname)', `page_content`='$_POST[inputcontent]' WHERE id = $_POST[id]"; mysql_query($u) or die (mysql_error()); echo "Page has been edited"; header("Location: controlpanel.php"); } ?>
September 27, 201213 yr If you're only trying to run the UPDATE on one record, you might want to use mysql_fetch_row() instead of mysql_fetch_array(). Your SQL statement gives me the impression that you are trying to return one row (as ID is usually a primary key type field). Yet you are returning the result as an array. If the SQL is in fact meant to return more than one row, then you would probably need to do split the array into some sort of loop before inserting into the DB. Lyndsey.
September 27, 201213 yr Author that wouldn't explain why the page_content gets updated and page_name doesn't
September 27, 201213 yr Author lol i found the error, used wrong brackets. Lyndsey nothing wrong with the code `page_name`='$_POST(inputname)', `page_content`='$_POST[inputcontent]'
September 27, 201213 yr Oh nice one, didn't notice the brackets! Edit: Apologies, I'm not as up to speed on PHP as I'd like. Edited September 27, 201213 yr by Lyndsey
October 2, 201213 yr For the love of all things holy, read about MySQL injection. Your code is wide open to everything. Also, the use og the mysql set of PHP is no longer recommended and is now depreciated - see http://www.php.net/m...intro.mysql.php - use mysqli (the "i" stands for improved) or PDO. no matter how many times i say it or u say it ive notice people still dont move away from the mysql set of functions onto mysqli or PDO
Create an account or sign in to comment