hi all,
i had a php page which contains a list of images in a table.
When i click on submit button i those values should be inserted into database. I need this by using ajax. I had tried something but i am not getting values inserted into database.
so can any one help me.
thank you,
here is the code i had tried.
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(str)
{
if (str=="")
{
document.getElementById("myDiv").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
</head>
<body>
<form action="test.php" method="post">
<table border="1" align="center" id="customers" style="width: 90%">
<tr>
<th>S.no</th>
<th>Imageid</th>
<th>Name</th>
<th>Size</th>
<th>Type</th>
<th>Assigned to</th>
</tr>
<?php
include 'connection.php';
$query= mysql_query("SELECT id,imageid,name,size,type from images where uploadeddate='07/21/2010'");
mysql_error();
$num=mysql_num_rows($query);
$i=0;
while ($i < $num)
{
$f1=mysql_result($query,$i,"id");
$f2=mysql_result($query,$i,"imageid");
$f3=mysql_result($query,$i,"name");
$f4=mysql_result($query,$i,"size");
$f5=mysql_result($query,$i,"type");
?>
<tr>
<td><input type="text" name="sno" value="<?php echo $f1;?>"></td>
<td><input type="text" name="imageid<?php echo $i;?>" value="<?php echo $f2;?>"></td>
<td><input type="text" name="name<?php echo $i;?>" value="<?php echo $f3?>"></td>
<td><input type="text" name="size<?php echo $i;?>" value="<?php echo $f4;?>"></td>
<td><input type="text" name="type<?php echo $i;?>" value="<?php echo $f5;?>"></td>
<td><input type="text" name="assignedto<?php echo $i;?>" value="<?php echo assignedto;?>"></td>
</tr>
<?php
$i++;
}
?>
<div id="myDiv"><h2></h2></div>
<input type="button" name="submit" value="submit" onclick="loadXMLDoc(this.value)">
</form>
</body>
</html>
<?php
$q=$_GET["q"];
if($q=='submit')
{
//echo $num;
$i=0;
while($i<$num)
{
$sql=mysql_query("insert into test (imageid,name,size,type,assignedto) values ('".$_POST['imageid'.$i]."','".$_POST['name'.$i]."','".$_POST['size'.$i]."','".$_POST['type'.$i]."','".$_POST['assignedto'.$i]."')");
mysql_error();
//$num=mysql_num_rows($sql);
$i++;
}
}
?>