PDA

View Full Version : [php] update mysql database



alapimba
October 6th, 2004, 12:26 PM
hello
can anyone explain me what can be wrong in this code or give me some extra lines of code to find what can wrong to this thing don't work?



<?php
$dbhost = "localhost";
$dbuser = "xxxx";
$dbpwd = "xxxx";
$dbname = "comuna"; // change this to your database name
$connection = mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db("$dbname",$connection);

$id = "4";
$sala = "5";
$titulo = "5";
$info = "5";
$descriccao = 5;

mysql_query("UPDATE emcena SET sala='$sala', titulo='$titulo', info='$info' descricao='$descriccao', WHERE id='$id' ");
echo "File " . $id . " " . $sala . " " . $info . " " . $descriccao . " " . $titulo . " uploaded successfuly.";
//header("Location: cena.php");
?>


if i write this in a file and open in my server.. it should add the data to database right? or i need any submit button or something like that? this is probably stupid but ok... i just want to understand why i can't update the data in this table, cause i can in the other table in the same database.. help me please :/

Hans Kilian
October 6th, 2004, 04:03 PM
Two things:
You say "it should add the data to database". That sounds like you expect it to insert a new row. It doesn't. It updates any existing row(s) with id = 4. If there aren't any rows with id = 4, then your script does nothing.

Also, you should have a comma after info='$info' and no comma after descricao='$descriccao' so your SQL looks like
UPDATE emcena SET sala='$sala', titulo='$titulo', info='$info', descricao='$descriccao' WHERE id='$id'

Hope that helps.

alapimba
October 6th, 2004, 04:08 PM
hi, nop i don't expect it to add a new row, i want it to update and existing row,i have been working with id 4 because i know it exists.
about that problem with commas i'll check when i'm back to work to see if the problem was that. do you think that's the problem that make it don't update the row?

Hans Kilian
October 6th, 2004, 04:19 PM
I think so. It's the only thing that I can spot that's wrong with the script.