Checkbox

insert multiple checkbox values to mysql database using php

Page 1 of 1

6 Replies - 4401 Views - Last Post: 27 May 2009 - 06:13 AM Rate Topic: -----

#1 rkjyothesre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 09

Checkbox

Post icon  Posted 20 May 2009 - 02:42 AM

I use text,textarea,combobox,checkbox,radio button in my php with mysql project.how i insert those values to database
Is This A Good Question/Topic? 0
  • +

Replies To: Checkbox

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Checkbox

Posted 20 May 2009 - 02:45 AM

:code:
insert into tablename values(val1,val2,val3)

Was This Post Helpful? 0
  • +
  • -

#3 multicoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-April 09

Re: Checkbox

Posted 26 May 2009 - 06:18 AM

Hi,
All the element values will come in the $_post array and can accessthem accrodingly -
<?
//connect to database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
	or die('Could not connect: ' . mysql_error());

	echo 'Connected successfully';
//select database
mysql_select_db('my_database') or die('Could not select database');

// Performing SQL query

if(isset($_post['btn']) && $_post['btn']!='')
{

$query = "insert table_name (Col1,col2,col3) values ('".$_post['txtName']."','".$_post['sOpt']."','".$_post['chk']."')";
$exQuery = mysql_query($query);
if($exQuery=="false"}{echo "Not inserted";}
else{ echo "Inserted successfully";}
}
?>

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
</head>
<body>
<form id='frm' name='frm' >
<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
	<td>
	<input type='textbox' id='txtName' name='txtName' />
	</td>
	<td>
	<select id='sOpt'>
	<option>opt1</option>
	<option>opt2</option>
	<option>opt3</option>
	</td>
	<td>
	<input type='checkbox' id='chk' name='chk' />
	</td>
  </tr>
  <tr>
	<td>
		<input type='Submit' id=btn' name='btn' value='Submit'>
	</td>
  </tr>
</table>
</form>
</body>
</html>



Please visit w3schools.com
Was This Post Helpful? 0
  • +
  • -

#4 AlienWebguy  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 84
  • Joined: 04-March 09

Re: Checkbox

Posted 26 May 2009 - 12:05 PM

It should be added that the only way they'll appear in the $_POST array is if you add method="post" to your form tag - otherwise they will only appear in the $_GET and $_REQUEST arrays.
Was This Post Helpful? 0
  • +
  • -

#5 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Checkbox

Posted 26 May 2009 - 02:50 PM

View PostAlienWebguy, on 26 May, 2009 - 11:05 AM, said:

It should be added that the only way they'll appear in the $_POST array is if you add method="post" to your form tag - otherwise they will only appear in the $_GET and $_REQUEST arrays.


Actually this is not entirely true for a user utilizing AJAX, in which instance you might see a simple <form> with no attributes. But hey no one said we were getting THAT complicated ;)
Was This Post Helpful? 0
  • +
  • -

#6 AlienWebguy  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 84
  • Joined: 04-March 09

Re: Checkbox

Posted 26 May 2009 - 04:50 PM

Interesting. My understanding was that if you don't actually "submit" the form and just do an onclick="javascriptFunctionToGrabFormValuesAndExecuteAjaxCall();" then all the values get put into a query string and passed via the $_GET array, which of course is part of the $_REQUEST array.
Was This Post Helpful? 0
  • +
  • -

#7 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Checkbox

Posted 27 May 2009 - 06:13 AM

No i , personally, am using JQuery and it actually will make the submit as a post ( by the documentation of course ) lol

JQuery Ajax Options

Check it out there, i have been doing alot of reading on AJAX so if you see something different please enlighten me. But from what i see you can specify the method that the form uses...

I am using this on a couple of simple one input forms and in the PHP im actually accessing everything through the $_POST array. And your idea of the onclick event could be used on the submit button to access a Javascript function OR simply add the onsubmit="javascriptajaxfunction()" into your form attributes OR even better just assign the function through JQuery

$(document).ready(function(){

  $(".submit_btn").click(function(){
	javascriptajaxfunction();
  }

});



I think in these cases there are many ways to skin a cat just a matter of what you like the most :)

This post has been edited by RPGonzo: 27 May 2009 - 06:14 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1