php functions and forms.
Posted: Mon Nov 17, 2008 11:30 pm
Hi, Im developing an online auction site for an assignment as part of my final year project for uni.
And i was wondering if it were possible to instead of, when using forms, sending the data taken from the user ie. a checkbox, and send it to a function vs. sending to a new page(script)??
Here's what i've got so far.
And i was wondering if it were possible to instead of, when using forms, sending the data taken from the user ie. a checkbox, and send it to a function vs. sending to a new page(script)??
Here's what i've got so far.
Code: Select all
[color=#0000FF]function[/color] addAdmin($info[[color=#FF0000]'UserID'[/color]]){
$userID = $info[[color=#FF0000]'UserID'[/color]];
$query = [color=#FF0000]"UPDATE users SET Type = 'Admin' WHERE UserID =2 LIMIT 1"[/color];
$result = [color=#0000FF]mysql_query[/color]($query)[color=#0000FF] or die[/color] ([color=#FF0000]"Couldn't execute query"[/color]);
}
...
...
...
$query = [color=#FF0000]"SELECT * FROM users ORDER BY Username ASC"[/color];
$result = [color=#0000FF]mysql_query[/color]($query);
[color=#0000FF]echo[/color] [color=#FF0000]"<form action='"[/color].addAdmin().[color=#FF0000]"' method='post'>"[/color];
[color=#008000]while[/color]($info = [color=#0000FF]mysql_fetch_array[/color]( $result )){
[color=#FFBF00]// Output Check List[/color]
[color=#008000]if[/color]($info['Type'] != [color=#FF0000]"Admin"[/color]){
[color=#0000FF]echo[/color] [color=#FF0000]"<input type='checkbox' name='Username[]' value='"[/color].$info['Username'].[color=#FF0000]"'> "[/color].$info['Username'].[color=#FF0000]"<br>"[/color];
[color=#0000FF]echo[/color] [color=#FF0000]"<input type='hidden' name='hidden' value='"[/color].$info['UserID'].[color=#FF0000]"'"[/color];
}
}