Nothing is being updated because $id is empty and in fact is not even set.
You need to pass the id via a hidden form variable in order to get the
results you expect.

Advertising

In the future I suggest always debugging your scripts by echoing your
variables so that you can determine if they contain what you think they
contain.
Fred
Chris Janes <[EMAIL PROTECTED]> wrote in message
000e01c177c1$79a78620$a25ffea9@d7e5f4">news:000e01c177c1$79a78620$a25ffea9@d7e5f4...
> Ok, this may well turn out to be a total newbie question. But it's got me
> stumped.
>
> I'm trying to create a small, simple news system for a personal website.
> I've gotten sections to insert the news into the database. but I can't
seem
> to get it to update itself.
>
> So far I have
>
> <?php
>
> include("accesscontrol.php");
>
> (This is a login script to authenticate users, so they cannot access pages
> by merely typing the address into the address bar.
> It references the database connection script, so that I shouldn't need to
> call that again. Is that right?)
>
> dbconnect(My_db_name);
>
> mysql_query ("UPDATE news SET subject='$newsubject', content='$newcontent'
> WHERE id='$id'");
>
> ?>
>
> The $newsubject and $newcontent variables are taken from the results of a
> form on an earlier page. when the script is run through in full, I get no
> errors, but the database is not updated.
>
> The table has the following format
>
> id, date, subject, content, user
>
> I can get the correct news entry displayed in the forms on previous
screen,
> where the altering takes place. (code for the form is below)
>
> <form name="news" method="get" action=alternews.php>
> <input type="hidden" name="user" value="<?=$username?>">
> <p>Subject:
> <input type="text" name="newsubject" maxlength="120"
> value="<?=$subject?>">
> </p>
> <p>Content:<br>
> <textarea name="newcontent" rows="6"
> cols="60"><?=$content?></textarea>
> </p>
> <p align="right">
> <input type="submit" name="Submit" value="Submit">
> <input type="reset" name="reset" value="Reset">
> </p>
> </form>
>
> The variables are passed through to the page that actually performs the
> update, but the update never takes place. I don't get an error from MySQL,
> or a parsing error from PHP, all the pages display as if the update had
> taken place.
>
> Can anyone see what I'm doing wrong?
>
> This all seemed like a good way of learning PHP and MySQL, it's just
leading
> to further hair loss!
>
> Oh, and I'm sorry if this really should go to another list, but this was
the
> first one that leapt to mind.
>
> Cheers,
>
> Chris Janes
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]