if (!isset($_SESSION['user']))
 die ("Access Denied");

  if ($_POST['submit']=='Update Information')
         		$name_box = $_REQUEST['name_box'];
while (list ($key_check,$val_check) = @each ($name_box))	
{						$value_check .= $val_check.",";
$all_value_check = substr($value_check, 0, -1);



include 'dbc.php';

$user = $_SESSION['user'];
$query  = "SELECT * FROM student WHERE user_email = '$user'";

$result = mysql_query($query);

while($row=mysql_fetch_array($result, MYSQL_NUM))

               <html><head><script type='text/javascript'>

	function check()
	var c_value = '';
	for (var i=0; i < document.length; i++)
   		if (document.pro.name_box[i].checked)
      c_value = c_value + document.pro.name_box[i].value + '\n';

	"<form action='processupdate.php' method='post' name='pro'> <table border=1>".
	"<tr><td colspan=4 width=15% bgcolor=black><font color=white><h1>Registered User ID: $row[0]</font></td>".
	"<tr><td>Interested in the following Musical Instruments: <br> (current)</td><td>". $row[14].
	" <td align='right'>Update to: <br>(new)</td>
    				<td colspan=2 align=left>
<input name='name_box[]' type='checkbox' value='Cello' />Cello <br>
<input name='name_box[]' type='checkbox' value='Flute' />Flute <br>
<input name='name_box[]' type='checkbox' value='Clarinet' />Clarinet <br>
<input name='name_box[]' type='checkbox' value='Saxophone' />Saxophone <br>
<input name='name_box[]' type='checkbox' value='Vocal' />Vocal <br>
         "<tr><td colspan=4><input type='submit' name='submit' value='Update Information' style='height: 35px; width: 100%'></td></tr></table></form>";                 


<?php session_start();

if (!isset($_SESSION['user'])){ die ("Access Denied"); } ?>
<?php if (isset($_SESSION['user'])) 
include ('dbc.php'); 
$server = $_SERVER['HTTP_HOST'];
$host = ereg_replace('www.','',$server);

$user = $_SESSION['user'];

$full_name = addslashes($_REQUEST['full_name']);
$email = addslashes($_REQUEST['email']);
$hp = addslashes($_REQUEST['hp']);
$loc = ($_REQUEST['loc']);
$cloc = ($_REQUEST['cloc']);
//$test = ($_REQUEST['name_box']);
$test = addslashes ($_REQUEST['name_box']);
$test2 = $_REQUEST['c_value'];


	//run function

$query  = "SELECT * FROM student WHERE user_email = '$user'";
$data = mysql_query("SELECT image FROM em.testblob") or die(mysql_error()); 

$result = mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_NUM))

/*echo $row[1].$row[4].$row[10].$row[11].$row[12].$row[14];*/
echo $full_name. $test. $test2;

	$sql = "UPDATE student SET full_name = '$full_name' , user_email = '$email' , hp = '$hp' , plocation = '$loc' , llocation = '$cloc' , test = '$test' WHERE id = '$row[0]'";

	$result = MYSQL_QUERY($sql);

echo $_SESSION['user'];
echo $user;


{ ?>

<?php } ?>

i cant seems to get the array when i post the checkbox to another page......tried javascript

the variable i requested becomes the word "Array".

Notice: Array to string conversion in C:\wamp\www\em\student\processupdate.php on line 19

8 Years
Discussion Span
Last Post by diafol

this is because you've created an array by having multiple checkboxes with the same name.

if you do a quick print_r($_POST), you should see the output of all checked checkboxes.

Votes + Comments
yea the printr showed the values

how can i insert the results into mysql ? i tried a few ways but it doesn't works.

$sql = "UPDATE student SET full_name = '$full_name' , user_email = '$email' , hp = '$hp' , plocation = '$loc' , llocation = '$cloc' , test = "$_POST['name_box']" WHERE id = '$row[0]'";

could you tell me the right way to do it ?


test = "$_POST" will give 'Array'.

First of all, in which format do you want the instrument data saved? Would you like the data as a list or array of instruments (strings - no pun intended!), as a list or array of unique instrument ids (integers)?

I would suggest that you either make an integer list or create more tables. You may think that this is a waste of time, but it allows a greater degree of flexibility and is easier to maintain:

TABLES (3): student; instrument; student_instrument

id (autoincrement; primary key; integer)
name ... (etc, etc)

id (autoincrement; primary key; integer OR tinyint)
name ... (etc etc)

id (autoincrement; primary key)
student_id (foreign key; integer)
instrument_id (foreign key; integer/tinyint)

With the above structure, you only ever need to display the instrument name on the form, everything else is done through the instrument's unique id.

The checkboxes can be built dynamically via php, even if you add new instruments. You can also check for existing records in the STUDENT_INSTRUMENT table in order to pre-fill checked/unchecked states.


A quick and less complicated way of doing this would be to just have 2 tables: students and instruments and have a 'varchar' field for instruments in the student table, where a list of ids, separated by commas could be held.

For example, 1,4,6 may equate to piano, harp, violin.

You'd still be able to dynamically create your checkboxes and after placing the instrument id values (from the student table) into an array, you could check whether the instrument was listed to the student.

Sorry, got carried away again..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.