Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

UPDATE error

Featured Replies

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");
}
?>

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.

  • Author

lol i found the error, used wrong brackets. Lyndsey nothing wrong with the code

 

 

`page_name`='$_POST(inputname)', `page_content`='$_POST[inputcontent]'

Oh nice one, didn't notice the brackets!

 

Edit: Apologies, I'm not as up to speed on PHP as I'd like. :sorry:

Edited by Lyndsey

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.