Jump to content

Help with form processing, checkboxes and posting to MySQL


Paul_W

Recommended Posts

So I'm trying to work out an issue on a project which requires to post some data from a form and send it to multiple databases via several user selected checkboxes. I think I have this somewhat figured out but could use some help making sure it looks ok and I'm doing things the right way. Would appreciate some input if anyone has some ideas how to do this better or what have you... thanks very much!!

So the form itself is fairly straight forward:

<FORM action="process.php" method="post" name="frmJob">
...
bunch of text areas and other checkboxes
...
<input type="checkbox" class="radio" name="post_1" id="id_a" value="1"<?php if($t_result['post_1'] == "1") { echo " checked";}?>>
</FORM>

so in process.php I have this:

$query = '<Database INSERT/UPDATE query here>';

if(isset($_POST['post_1'])) {
// connect to db 1
$db_link = mysql_connect ( $db_hostname, $db_server_username, $db_server_password );
if ( $db_link ) {
      if ( ! mysql_select_db ( $db_database ) ){
          die("Mysql connection failed");
      }
      else{
mysql_query($query);

//close the database connection
          @mysql_close ( $db_link );

    //connect back to normal database server
  xx_db_connect() or die('Unable to connect to database server!');
      }
} else {
          die("Mysql connection failed");

repeat for more checkboxes....

One thing I'm curious about is can I use a function in the  $query = ''; so something like this
$query = 'db_insert(compid,title,categoryid,subcategoryid,description,locationid,skills)';


Any further examples or comments or suggestions are welcome!!!

Thanks,

Paul

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.