I use text,textarea,combobox,checkbox,radio button in my php with mysql project.how i insert those values to database
Checkboxinsert multiple checkbox values to mysql database using php
Page 1 of 1
6 Replies - 2849 Views - Last Post: 27 May 2009 - 06:13 AM
Replies To: Checkbox
#2
Re: Checkbox
Posted 20 May 2009 - 02:45 AM
insert into tablename values(val1,val2,val3)
#3
Re: Checkbox
Posted 26 May 2009 - 06:18 AM
Hi,
All the element values will come in the $_post array and can accessthem accrodingly -
Please visit w3schools.com
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
#4
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.
#5
Re: Checkbox
Posted 26 May 2009 - 02:50 PM
AlienWebguy, 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
#6
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.
#7
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
I think in these cases there are many ways to skin a cat just a matter of what you like the most
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
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|