Reply to Re: Help- checkboxes to mysql

Your name:

Reply:


Posted by AlexVN on 06/19/06 21:11

Harold wrote:
> Hello Harold,
> > here is a snippet of some of the checkbox options...
> >
> > <tr>
> > <td><input type=checkbox name=skill04/>Ad Design</td>
> > <td><input type=checkbox name=skill05/>Animation</td>
> > <td><input type=checkbox name=skill06/>ASP</td>
> > </tr>
> > what i want to do is pass a user id( lets call that userid) along with
> > any of the items that are checked only.
> More information as requested
>
> userid is from a text box entry
>
> so if ad design and ASP are only selected i want both of them in the table
>
>
> user id | skill
> ----------------
> 123 | Ad design
> 123 | ASP
>
> i hope i cleared that up

Harold,

As I understand you have the textbox with user id and a few checkboxes.
Then you want them in one database table as you described.
For this you need to create a form which will submit the data to the
script:
<form action="myscript.php" method="post">
User: <input name="user_id"><br>
Options:<br>
<input type=checkbox name=skill04/>Ad Design<br>
<input type=checkbox name=skill06/>ASP<br>
....
</form>

The myscript.php should get values from the $_POST array and write to
the database using INSERT SQL statement. It may look like this:

<?php
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$cn = mysql_connect('host', 'login', 'password');
mysql_select_db('database', $cn);
$user_id = $_POST['user_id'];
unset($_POST['user_id']);
foreach ($_POST as $key => $value) {
mysql_query('INSERT INTO table VALUES (' . (int)$user_id .', ' .
(int)substr($key, 5) .')');
}
}
?>

Please note that I did not test this code and it shows only concept.
Please check the PHP's manual about used functions and read about SQL
Injection vulnerability (you can find a lot about it on Google) before
writing actual application.

Sincerely,
Alexander
http://www.alexatnet.com/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация