I have a DB with a number of telephone numbers for each person. I am using a while loop to extract and store them in an array. I then display the telephone numbers on the form.
The echo I have when storing the data displays “Home” and “Business” (correct for this person). However, when I display the data on the form all three fields contain “Array[0]”. What am I doing wrong?
<?php //Connect to the database. $link=mysql_connect("127.0.0.1","root") OR die("Couldn't connect to MySQL"); $db=mysql_select_db("db1",$link) OR die("Couldn't open db1: " .mysql_error());
//Extract the Telephone numbers. $sql_query4 = sprintf("SELECT * FROM tbl_telephone_number WHERE Name_Key = %s", $_SESSION['NameKey']); $result = mysql_query($sql_query4); $affected = mysql_num_rows($result); if ($affected = 0) { session_unset(); echo "<font face='Verdana' size='2' color=red>Error in getting Name Key from tbl_telephone_number.<br>"; echo "<center> <input type='button' value='Retry' onClick='history.go(-1)'></center>"; exit(); } else { $i=0; while ($row = mysql_fetch_array($result)){ $_SESSION[TelephoneType][$i] = $row['Telephone_Type']; $_SESSION[TelephoneNumber][$i] = $row['Telephone_Number']; $_SESSION[TelephoneExtension][$i] = $row['Telephone_Extension']; echo $_SESSION[TelephoneType][$i]; $i++; } }
//Dissconnect from the database. mysql_close($link); ?>
<form class="form" name="UpdateDetails" action="CheckUpdate.php" method="POST"> <table cellspacing="1" cellpadding="1" width="100%" border="0"> <tr> <td bgcolor="#cccccc" colspan="3"> <div align="center">Please enter your details below: </div></td></tr> <tr> <td bgcolor="#cccccc" colspan="3"> <div align="left">The fields indicated with an asterisk (*) are required to complete the transaction; other fields are optional. If you do not want to provide us with the required information, please use the back button on your browser, or close the window or browser session that is displaying this page, to return to the previous page.</div></td></tr>
I'm not sure if you've changed the code, but the reason why i asked you to do that was because i thought "Array" was printing out because the value of $_SESSION[TelephoneType] was an array.
To get the word 'business' to show at that point you would need $_SESSION[TelephoneType][1], but i can't seem to find where this goes in your post. Sorry to be of no help!