Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   PHP again! (https://www.cableforum.uk/board/showthread.php?t=48446)

Strzelecki 08-06-2006 19:05

PHP again!
 
I'm hoping someone can help, there's a really obvious problem here but I've stared at it for too long and can't see it! Here the code:
http://www.strzelecki.co.uk/rsvp.phps
It's an RSVP script for my wedding website that pull the guests details from a database and allows them to amend them and tell me whether they are coming and then updates the database with this info, normally simple, but it refuses to do the update, I think I've done the loops wrong but a fresh pair of eyes will be able to spot that!
For reference the array(s) produced to update the data seem ok
Code:

Array
(
    [last_name_upd] => Strzelecki
    [first_name_upd] => Array
        (
            [0] => Andy
            [1] => Sue
            [2] => Rob
            [3] => Chris
        )

    [id_upd] => Array
        (
            [0] => 7
            [1] => 8
            [2] => 9
            [3] => 10
        )

    [surname_id] => Array
        (
            [0] => 2
            [1] => 2
            [2] => 2
            [3] => 2
        )

    [address_upd] => An Address
    [postcode_upd] => SA62 2PW
    [telephone_number_upd] => 01234567891
    [email_address_upd] => a@a.com
    [song_artist] => example
    [song_name] => example name
    [updateinvite] => Submit
)

Cheers!

greencreeper 08-06-2006 23:21

Re: PHP again!
 
PHP Code:

if(isset($last_name_upd)) { 
    
update_details(); 
    } 
    else { 
    
//print something 
    
} 

Replace the "print something" with a line of HTML or something similar. Suspect that this is the point of failure, though I'm struggling to follow the variables in my head.

---------- Post added at 23:21 ---------- Previous post was at 23:15 ----------

I would have used frm and db prefixes for the form and database variables, to avoid the possibility of confusion, which if the else above is true, would be most likely what has happened.

Strzelecki 08-06-2006 23:36

Re: PHP again!
 
Ok I'll give that a try! Although I think if it was that it wouldn't print out the array content as this comes afterwards.

greencreeper 08-06-2006 23:39

Re: PHP again!
 
Hmmm :scratch: Is there not a built-in result variable :erm: Trying to recall from the last time I wrote PHP - pretty certain you can check the result of the last SQL statement executed.

Strzelecki 08-06-2006 23:42

Re: PHP again!
 
something like
PHP Code:

$result = mysql_query($sql); 

?

greencreeper 08-06-2006 23:46

Re: PHP again!
 
Yeah - looks right. Should also be an error variable I think.

I can always read code, even if I can't write it. It's been a few years since I wrote in PHP - wrote an ecommerce website for a project at Uni. Condom shop. Caused a bit of a stir :D

Strzelecki 08-06-2006 23:53

Re: PHP again!
 
:D
Well I think I see a problem, now getting:
Code:

Ian4Array
(
    [last_name_upd] => surname
    [first_name_upd] => Array
        (
            [0] => Ian
            [1] => Sue
            [2] => Jo
        )

    [id_upd] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
        )

    [surname_id] => Array
        (
            [0] => 1
            [1] => 1
            [2] => 1
        )

    [address_upd] => an address
    [postcode_upd] => a postcode
    [telephone_number_upd] => 01234567891
    [email_address_upd] => a@a.com
    [song_artist] =>
    [song_name] =>
    [updateinvite] => Submit
)
Sue5Array
(
    [last_name_upd] => surname
    [first_name_upd] => Array
        (
            [0] => Ian
            [1] => Sue
            [2] => Jo
        )

    [id_upd] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
        )

    [surname_id] => Array
        (
            [0] => 1
            [1] => 1
            [2] => 1
        )

    [address_upd] => an address
    [postcode_upd] => a postcode
    [telephone_number_upd] => 01234567891
    [email_address_upd] => a@a.com
    [song_artist] =>
    [song_name] =>
    [updateinvite] => Submit
)
Jo6Array
(
    [last_name_upd] => surname
    [first_name_upd] => Array
        (
            [0] => Ian
            [1] => Sue
            [2] => Jo
        )

    [id_upd] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
        )

    [surname_id] => Array
        (
            [0] => 1
            [1] => 1
            [2] => 1
        )

    [address_upd] => an address
    [postcode_upd] => a postcode
    [telephone_number_upd] => 01234567891
    [email_address_upd] => a@a.com
    [song_artist] =>
    [song_name] =>
    [updateinvite] => Submit
)

The update condition is right, I can get it to print out each first name together with the relevant ID and all the variables to do the update are correct but now I'm not sure what is wrong with that output.

greencreeper 08-06-2006 23:56

Re: PHP again!
 
Now getting :confused:

Strzelecki 08-06-2006 23:59

Re: PHP again!
 
Well
PHP Code:

<pre><?php //testing output from form
print_r($_POST); ?></pre>

will print out what is stored in the $_POST array (which is shown above) after the user had sumitted their updated info, it's from this that I want to do the update.

greencreeper 09-06-2006 00:23

Re: PHP again!
 
Array output looks ok to me :erm: Is the connection being closed at the end of the script, once all the updates are done?

Strzelecki 09-06-2006 00:31

Re: PHP again!
 
Yeah tried
PHP Code:

mysql_close($rsvp); 

, no luck. If I get it to echo all the variables I want to do the update with they all print out ok as well.
and it not having problems pulling the database up twice, just tried
PHP Code:

mysql_select_db($database_rsvp, $rsvp)
    or die (
'Error, cannot select mysql database'); 

just before the update.

greencreeper 09-06-2006 00:33

Re: PHP again!
 
If the data is all there and the query is definitely being execute, then I haven't a clue :( One of the PHP gurus on here may have an idea tomorrow - when they're awake.

Strzelecki 09-06-2006 00:36

Re: PHP again!
 
ok, i really appriciate your help! I'll crack this somehow, usually pretty good with PHP but this is so simple!

greencreeper 09-06-2006 00:38

Re: PHP again!
 
You do know for certain that it's not doing the update - if you view the database outside of PHP, it's not got the data...

Strzelecki 09-06-2006 00:42

Re: PHP again!
 
correct. No update whatso ever. Although you have just given me an idea, swap it for a delete and see if that works!

greencreeper 09-06-2006 00:43

Re: PHP again!
 
If you change the UPDATE query to a SELECT query, and then output what it's SELECTed, has it selected anything?

Might not be updating because it can't find the row to update - was my thinking

[edit] Found what I thought existed - mysql_affected_rows

Strzelecki 09-06-2006 00:54

Re: PHP again!
 
Getting somewhere! Changed to a delete and got an mysql_real_escape_string cannot connect error. So delete that and the delete worked. Now put the update back without the mysql_real_escape_string and I'm getting a connection error.

greencreeper 09-06-2006 01:04

Re: PHP again!
 
So it looks your database gubbins at fault, then


All times are GMT. The time now is 15:55.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum