Page 1 of 1

MySQL Update won't work [SOLVED]

Posted: Sat Jul 22, 2006 4:02 pm
by thiscatis
I'm rather new to PHP, here is the PHP code :

Code: Select all

// We willen de ID van de pagina kennen.
if (isset($_GET['pid'])) {
     $pageid = preg_replace('/[^a-zA-Z0-9\_]/', '', $_GET['pid']);     // delete chars NOT in that set
} else {
     $pageid = 'page1';
} 

// We hebben de benodigde files nodig.
include('../../functions.php');
include('../../functions_willem.php');

// Naam user
$localuser = getcurrentuser(realpath('.'));

// We openen de verbinding met de database.
$db = opendatabase();
opendatabase();


// Update als nodig is.

if (isset($_POST['content_a'])) {

$content_a =  $_POST['content_a'];
$sqlquery =("UPDATE SET tblContent (content_a) VALUES ('$content_a') WHERE page='$pageid' AND username='$localuser' ");
$results = mysql_query($sqlquery);
 } 

else { };
and my HTML code :

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Update</title>
</head>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
  <br />
  <br />
  <textarea id="content_a" name="content_a" rows="15" cols="80"></textarea>
  <br />
  <input type="submit" name="save" value="Submit" />
  <input type="reset" name="reset" value="Reset" />
</form>
</body>
</html>
Why doesn't it work?

Connection to database = OK.

Posted: Sat Jul 22, 2006 4:07 pm
by John Cartwright
Next time, please tell us exactly what is happening, simply don't say why isn't this working. Secondly you are checking for $POST['content_a'] -- this should be $_POST['content_a'].

Posted: Sat Jul 22, 2006 4:15 pm
by thiscatis
Ok,

I've got it.

Code: Select all

if (isset($_POST['content_a'])) {

$content_a =  $_POST['content_a'];
$sqlquery =("UPDATE tblContent SET content_a='$content_a' WHERE page='$pageid' AND username='$localuser' ");
$results = mysql_query($sqlquery) or die(mysql_error()); 
 } 

else { };
works!