+3  A: 

Edited answer to reflect discoveries found in comment thread below for future readers

In your PHP files you need to update

$_POST[id] 

to be

$_POST['id']

PHP will not now what id is, and therefor will evaluate to false, causing your script to exit, and fall into the loop you are describing.

This is also the case when you are using your $_SESSION array

$_SESSION[valid]

should be

$_SESSION['valid']

$_SESSION, $_POST, $_GET, $_REQUEST, etc are all associative arrays, in order to refer to any of their contents you need to specify the string that refers to the key they are located in.

Ok, in your if statement

if (!$_POST['id']) {
    header( "Location: pick_modcontact.php");
    exit;
} else {
    session_start();
}
if ($_SESSION['valid'] != "yes") {
    header( "Location: pick_modcontact.php");
    exit;
}

You are checking to see if $_SESSION['valid'] does not equal yes, this will evaluate to true because you never set $_SESSION['valid'] = "yes" so it will always go back to pick_modcontact.php here.

Try updating it to be

if (!$_POST['id']) {
    header( "Location: pick_modcontact.php");
    exit;
} else {
    session_start();

    // let the script know that this is a valid contact
    $_SESSION['valid'] = 'yes';
}
if ($_SESSION['valid'] != "yes") {
    header( "Location: pick_modcontact.php");
    exit;
}

Also

$option_block .= "<option value\"$id\">$f_name, $l_name</option>";

should be (you're misssing an equals sign) which means that on submit, it wont know the value of 'id'

$option_block .= "<option value=\"$id\">$f_name, $l_name</option>";
Rabbott
Thanks for the suggestion I wont change that bit as I am working off an example from a php book, the less it differes from the example the easier it will be for me to understand. Thanks!
Jacksta
So you've copied the example entirely.. this would assume there are no code errors (my other suggestion would be to make sure you are creating a session using session_start()) so are you sure that your database settings are correct? Can you create a simple script to output the validity of your db connection - I see that you have different db credentials in two scripts.. admin/user and admin_cantsayno/cantsayno maybe that is your issue?
Rabbott
@rabbott yeh database credentials are correct I forgot to edit them out in the second script before posting here. opps! Yeh I know it shouldnt have code errors but I just cant seem to find where I have faulted, its killing me!
Jacksta
also is start_session(); supposed to be session_start()); ?
Jacksta
haah woops, yes, session_start()
Rabbott
Trial and error by illimanation tells me that 'id' isnt being passed on and this is causing it to exit;if (!$_POST[id]) { header( "Location: pick_modcontact.php"); exit;}Its something wrong with pick_modcontact.php not passing the variable "id"
Jacksta
updated my answer, youre using id, not 'id', it doesnt know what id is, needs to be a string 'id'
Rabbott
is that on show_modcontact.php or pick_modcontact.php?
Jacksta
Both, it will NEVER understand id it has to be $id if it was a variable, or 'id' if its a string, in your case, its 'id' which tells it to grab the 'id' parameter from the POST array
Rabbott
When I have added that like this $sql = "SELECT f_name, l_name, address1, address2, address3, postcode, prim_tel, sec_tel, email, birthday FROM $table_name WHERE id = '$_POST['id']'"; it gets an error due to '$_POST['id']'"; to many '''''
Jacksta
$sql = "SELECT f_name, l_name, address1, address2, address3, postcode, prim_tel, sec_tel, email, birthday FROM $table_name WHERE id = '" . $_POST['id'] . "'";
Rabbott
ok thats changed, now it still doesnt work, goes back to other file. What chenges should have been made in pick_modcontact.php?
Jacksta
$_SESSION, added to answer.
Rabbott
I have updated my code, It still doesnt work :) thanks for helping Rabbott your a life saver, were so close to cracking it now!
Jacksta
make sure you update the SESSION and POST issue in ALL files, I still see it in your question.. I dont know if youve updated them or not though..
Rabbott
Ok I have another look over it and realised I hadent chenged this line <input type="id" value="<? echo "$_POST['id']"; ?>" /> I have not included 'id' not id . All code is updated. Now I get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/admin/domains/domain.com.au/public_html/show_modcontact.php on line 45
Jacksta
<? echo "$_POST['id']"; ?> should be <? echo $_POST['id']; ?> and shorthand version would <?= $_POST['id'] ?> there is no reason to enclose the variable in quotes here
Rabbott
ok, changed that in code, still reverts back to pick_modcontact.php if I could give you +1000 i would
Jacksta
can you update your question to reflect your current code, please?
Rabbott
sure Rabbott, it's update now
Jacksta
ok if ($_SESSION[valid] != "yes") {} in pick_modcontact.php.. should be 'valid'
Rabbott
changed, still no luck
Jacksta
When you say you POST it to the other file.. are you submitting a form in some way or another? Or are you just clicking on a link that is passing an id or something in the url?
Rabbott
I am clicking on a submit button in the form, which has an action="show_modcontact.php"
Jacksta
<input type="id" value="<? echo $_POST['id']; ?>" /> should be <input type="text" name="id" value="<? echo $_POST['id']; ?>" /> in show_modcontact.php
Rabbott
well spotted, I changed that and still the same problem
Jacksta
Your form is submitting to do_modcontact.php, is that another file that you can post, or is that a typo?
Rabbott
That is correct, that is a third script yet to be written. doesn't matter as it is only called afer submit button is pressed
Jacksta
updated answer, if that doesnt work, remove the if statement that checks for $_SESSION['valid']. That is what is causing the redirect issue.
Rabbott
ahhh tried both and no luck. so frustrated. thanks again
Jacksta
We'll weve run through nearly 15 problems.. I think you need to look through your example again and make sure you are copying things correctly - we can look at it again tomorrow after youve done so - repost your code if you make updates
Rabbott
Thanks Rabbott for all your help. I appriciate it heaps!!!!!! have a great day
Jacksta
FYI I asked it again and got a answer which made it workhttp://stackoverflow.com/questions/2712021/php-mysql-editing-table-data
Jacksta
Well, through the other multiple fixes, that solution wouldnt have been possible.. I'll add it to my solution, and would appreciate a selection of the answer..
Rabbott
more then happy to give you the answer. Thanks again your a legend
Jacksta