ripcurlksm Posted January 12, 2007 Share Posted January 12, 2007 I have a login system for users to get reports.... On the backend, I have an admin function which allows the admin to set privileges for each user, so that the user only gets the reports they purchased. In the admin section, a series of checkboxes appear for each report. I need to gather this data and write it to the database. [B]In short, I need is to get a JavaScript function that takes all the reports that have a checked box, and then write them into the permissions table of the database.[/B]How do I pass the values of each checked box from JavaScript, then pass it to PHP to write an SQL statement for each entry, for example here is what I would need to transfer from checkbox's with the value of 200, 322, and 505 for user with the user_id of 1.PERMISSIONS TABLE------------------------user_id | report_id------------------------ 1 | 200 1 | 322 1 | 505JavaScript to PHP to MYSQL... any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/ Share on other sites More sharing options...
ted_chou12 Posted January 12, 2007 Share Posted January 12, 2007 I dont see how javascript comes into this, so is this basically a permission kind of thing for your users? and are the permissions only: 200, 322, and 505.btw, please paste some codes for us to get an idea of what you are doing.Ted Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/#findComment-158934 Share on other sites More sharing options...
Cep Posted January 12, 2007 Share Posted January 12, 2007 I am a little confused how are you using Javascript? Your form checkboxes are html elements, your form if its being submitted is being passed to PHP, and from PHP you can send the form data to MySQL. So where is the Javascript coming into this? It doesn't make sense. Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/#findComment-158935 Share on other sites More sharing options...
ripcurlksm Posted January 14, 2007 Author Share Posted January 14, 2007 I am trying a set of different code that I am close to getting running but I keep getting an error with the following: [QUOTE]Warning: Invalid argument supplied for foreach() in /home/content/l/s/i/lsintelligence/html/emt/admin/editsubscriber3.php on line 75insert into user_reports (user_id, report_id) values[/QUOTE][B]Here is the code that prints the form checkbox's:[/B][CODE]<form name='form1' method='post' action='editsubscriber3.php'><?dbConnect(); // This gets all of the reports so that the admin can set permissions for individual reports$sql = "SELECT * FROM emt_report ORDER BY date_year DESC, date_month DESC, company ASC"; $result = mysql_query($sql) or user_error("mysql error " . mysql_error());$rank = 1;while($row = mysql_fetch_assoc($result)) { $id = $row['id']; print("<input name='reportbox[]' type='checkbox' value='$id'>"); $rank++;}?>[/CODE][B]Here is the page that handles receiving the data and writing to the database.[/B][CODE]<?$user = $_GET['user'];// --------THIS LINE BELOW IS THROWING THE ERROR --------$buf = array();foreach ($_POST['reportbox'] as $reportbox) { $buf[] = sprintf('(%d, %d)', $userid, $id);}echo dbConnect();echo $sql = "insert into user_reports (user_id, report_id) values " . implode(",\n ", $buf); ?>[/CODE]What am I doing wrong? I kept testing and modifying but I cant get this error to stop... :sick: Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/#findComment-160358 Share on other sites More sharing options...
corbin Posted January 14, 2007 Share Posted January 14, 2007 Youre trying to insert 1 value into two columns... Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/#findComment-160361 Share on other sites More sharing options...
ripcurlksm Posted January 14, 2007 Author Share Posted January 14, 2007 Doesn't $buf equal two values? Already set through:$buf[] = sprintf('(%d, %d)',[b] $userid, $id[/b]); Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/#findComment-160365 Share on other sites More sharing options...
Cep Posted January 15, 2007 Share Posted January 15, 2007 No I think you'll find your just formatting two values into 1 value and then trying to place it in two columns. Quote Link to comment https://forums.phpfreaks.com/topic/33868-javascript-to-php-to-mysql-checkbox/#findComment-161044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.