Which cart? How do you want the saving of data from the "cart" to your DB?
This could be achieved using this logic:
My bet is that you will be using the select element. You can call a function onchange
The function should connect to your DB, and on ready state (4), pass the value to a page that will accept the value and store it on DB. Something like this:
Code:
<script type="text/javascript">
function addDb(val){
// Do some error checking for XMLHTTP request
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4){
// Do something here
}
}
xmlHttp.open("GET","acceptdb.php?val="+val,true);
xmlHttp.send(null);
}
</script>
<select onchange="addDb(this.value)">
<option value="val1">Option 1</option>
<option value="val2">Option 2</option>
<option value="val3">Option 3</option>
<option value="val4">Option 4</option>
<option value="val5">Option 5</option>
</select>
sorry..,i am not familiar with that XMLHTTPrequest..,i wish i could study that but i really have no time ..,by the way..,i have this code to help you relate to my problem
function updateDb(url,method,obj){
var xmlHttp;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
alert(xmlHttp.responseText); // If successful, will alert the "echoed" part of your php
}
}
xmlHttp.open(method,url+'?val1='+obj.fields[0]+'&val2='+obj.fields[1]+'&val3='+obj.fields[2],true);
xmlHttp.send(null);
}
...as an example, I'm assuming that the name of your page that will add the data to your DB is mysql_page.php:
PHP Code:
$user = "root"; // DB Username $pass = "database_password"; // DB pass $name = "database_name"; // DB Name $host = "localhost"; // DB Host $webmaster = "webmaster@domain.com" ; // Set the webmaster's email here
$db=mysql_connect($host,$user,$pass) or die("Connection refused. Please check your database or contact the <a href='mailto:".$webmaster."'>webmaster</a>.");
$val1 = clean($_GET['val1']); // Get val1 and rectify it $val2 = clean($_GET['val2']); // Get val2 and rectify it $val3 = clean($_GET['val3']); // Get val3 and rectify it
$sQuery = "INSERT INTO table_name (column1,column2,column3) values ('$val1','$val2','$val3')"; // Create query string mysql_query($sQuery) or die(mysql_error()); // Execute query
echo mysql_affected_rows()?'Values were added on DB':'Query fails.';
function clean($str){ return mysql_real_escape_string($str); }