Log in

View Full Version : Stuck with PHP & MySQL update function



Total_me
05-06-2010, 10:31 AM
I tried lot functions of internet, however it doesn't works, and I can't find out where is mistake :S
This is my edit.php:
<?
////////////////////////////////////////////////////////
// Prisegame MySQL nustatymus //
////////////////////////////////////////////////////////
include('_include/dbsettings.php');
/////// Jungiames prie MySQL ir pasirenkame lentele
mysql_connect(host,user,pass) or die(mysql_error());
mysql_select_db(db_table);
$id = $_GET["id"];
$sql = "SELECT * FROM naujienos WHERE id=$id";
$result = mysql_query($sql);

$i=0;

$id=mysql_result($result,$i,"id");
$tema=mysql_result($result,$i,"tema");
$naujiena=mysql_result($result,$i,"naujienos");

echo "<form action=\"update.php\" method=\"post\">
<span style='visibility:hidden;'><input type='text' name='id' value=".$id." /></span>
Tema: <input name='tema' type=\"text\" size=\"9\" value=".$tema."> <br />
Naujiena: <textarea name='naujiena'>".$naujiena."</textarea>
<input type=\"submit\" value=\"Save Changes\">
</form>";

mysql_close();
?>

It's working perfectly, however.. If I write a new information and post it into my this update.php:
<?
////////////////////////////////////////////////////////
// Prisegame MySQL nustatymus //
////////////////////////////////////////////////////////

include('_include/dbsettings.php');
/////// Jungiames prie MySQL ir pasirenkame lentele
mysql_connect(host,user,pass) or die(mysql_error());
mysql_select_db(db_table);

$ud_id=$_POST['id'];
$ud_tema=$_POST['tema'];
$ud_naujiena=$_POST['naujiena'];

$query="UPDATE naujienos SET tema='$tema', naujienos='$naujiena' WHERE id='$id'";
mysql_query($query);
echo "Record Updated";
mysql_close();

?>
It's not updating the row I need. Actually it's only shows that record updated however it's not.

Any ideas?

bluewalrus
05-06-2010, 01:19 PM
You dont have $tema, $naujiena or $id set in your sql update you have them called $ud_id, $ud_tema, and $ud_naujiena.