Forum Moderators: coopster

Message Too Old, No Replies

UPDATE command problem with php / mysql

         

socal_local

5:52 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



I made a web-based job board where certain users with passwords can post a job opening. I made it so when they login via HTTP authentication, only their listing(s) will show up and they can DELETE it. But, I'm having problems making it possible so they can UPDATE their current listing(s). Here's what I got so far.

<a href='edit.php?id=$row[id]'>Edit</a>

//this works OK to bring up their listings tied to the password assigned. Then on edit.php:

$x1 = "SELECT * FROM table WHERE id='$id'";
$x2 = mysql_query($x1);
$x3 = mysql_fetch_array($x2);

I use this so the form will show the values already set and it will be easier to make edits. This part's OK too.

The form action when the user clicks the submit button goes to another file with this:

$sql = "UPDATE table SET skills='$skills' WHERE id='$id'";

I think the problem is with the WHERE part. It's not updating the new changes, but when I put in a hard value for id (i.e. '138'), then it works.

Sorry, if this seems a little confusing but I've tried a lot of ways around this, to no avail.

ChadSEO

6:05 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



socal_local,

If you are having problems with the WHERE clause, the first thing I would check is that $id is set correctly. Try echoing it out to make sure it has the correct value. You can also trying printing out $sql to make sure they were substituted correctly. Other than that, it looks like that should work.

Chad

dreamcatcher

6:05 pm on Aug 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi socal_local,

Is your $id variable being carried over to the next page? Try echoing the vaiable to see if it holds any data. If not try passing the value of $id in a hidden field when you update the entry.

Depending on your form method, access the variable using $_GET['id'] or $_POST['id'].

dc

[edit]ChadSEO, you been me to it[/edit]

LOL.

socal_local

7:20 pm on Aug 24, 2005 (gmt 0)

10+ Year Member



thanks....making a hidden field worked.

<input name="id" type="hidden" value="<?php print $x3['id'];?>">