Forum Moderators: coopster

Message Too Old, No Replies

help with UPDATE

me again

         

gswahla

10:38 am on Jul 18, 2003 (gmt 0)

10+ Year Member



Hey all, me again, I have been asking many questions over the last few days regarding this work I am doing. I thank everyone for their responses. As you migth have noticed I am a PHP/MySQL newbie, so please forgive these trivial questions...

OK I have a database which contains certain records that I wish to change (UPDATE) through a webpage. I have created two seperate .php files:

'MILTON_EDIT.php'
and
"MILTON_EDITIT.php"

What is happening at the moment is that the table is shown on the site. The user can click on the first column (The date) and be taken to the records for that date, with the current details for that day filled in. when they edit some values and click on 'SUBMIT' on the first form (milton_edit.php) instead of being sent to 'milton_edittit.php the page just refreshes giving the error "Sorry, no information" from 'milton_edit.php'

I am at a loss as to what is happening, again any pointers appreciated!

[edited by: jatar_k at 4:56 pm (utc) on July 18, 2003]
[edit reason] see charter regarding code dumps [/edit]

Robber

1:02 pm on Jul 18, 2003 (gmt 0)

10+ Year Member



It looks as though you might have missed the = in your form action, you have:

echo "<FORM METHOD=GET ACTION\"milton_editit.php\">";

but it should be

echo "<FORM METHOD=GET ACTION=\"milton_editit.php\">";

gswahla

8:01 pm on Jul 18, 2003 (gmt 0)

10+ Year Member



sorry bout posting the whole code, didnt know it was against the rules...thought it might aid people in giving me better advice...

but I will put the relevant bits here and hope I havent left any important bits out. I really need this sorted out, am stuck and cnt move forward till I get this sorted...


$sql="UPDATE milton SET date='$date', counter='$counter',cash='$cash',cards='$cards',cheques='$cheques'
,paid_out='$paid_out',total='$total',total_scripts='$total_scripts'
,total_purchases='$total_purchases',comments='$comments' WHERE ID='$ID'";

if(!mysql_query($sql,$connection)) {
echo "Error cannot Amend record<BR>";
echo "Go Back";
exit;
}else{
#amend OK inform user
echo "Table Updated<BR>";
echo "Record amended";
}

this bit of code doesnt seem to work for me...the vales dont get changed when I alter them...anyone see anything wrong with this?

[edited by: jatar_k at 8:35 pm (utc) on July 18, 2003]
[edit reason] split line for sidescroll [/edit]

jatar_k

8:38 pm on Jul 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



have you tried echo'ing the value of $sql to the browser so you can look at it manually? Sometimes that helps me be able to assess errors better.

another litlle trick is to use

mysql_query($sql) or die (mysql_error [ca.php.net]);

that will give you the actual error from mysql instead of your own generated error message.

gswahla

9:20 pm on Jul 18, 2003 (gmt 0)

10+ Year Member



I echoed the value of $sql and got this:

UPDATE `milton` SET `date`='2003', `counter`='2000', `cash`='1500', `cards`='250', `cheques`='250', `paid_out`='200', `total`='1800', `total_scripts`='200', `total_purchases`='12', `comments`='' WHERE `ID`=''

I noticed right at the end it says WHERE `ID`=''

though I told it to do WHERE `ID`='$ID'";

whats happening here?

[edited by: jatar_k at 9:38 pm (utc) on July 18, 2003]
[edit reason] edit for sidescroll [/edit]

willybfriendly

9:35 pm on Jul 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For some reason $ID was never set. Where are you expecting this value to come from? Is it passed from a form? If so, you may need to extract $ID from the $_POST array.

Put an echo $ID; before the SQL query.

WBF