How can I execute Multiple MySQL Query with PHP looping
Posted: Sun Jun 28, 2009 9:56 am
Dear,
I need to execute Multiple MySQL Query with PHP looping. In the below PHP page i have created 2 field for adding name ... and i want that when i will press SUBMIT then every value of this field will be inserted to one table field in MySQL.
I need the solution. Please give this solution
###### PHP File which i have created to do this ########
<?php
require_once('dbconfig.php');
?>
<form name="name" method="post" action="">
Assign Number with Name:
<table width="329">
<?php
$sql = "SELECT * FROM `name`";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
?><tr>
<td width="166" bgcolor="#CC9966"><?php echo $row['NAME'];?></td>
<td width="180" bgcolor="#CC9966"><input type="text" name="number" /></td>
</tr>
<?php
}
?>
<tr><td></td><td><input type="submit" name="submit" value="Go" /></td></tr>
</table>
</form>
<form name="name" method="post" action="">
Create Name:
<table width="329">
<tr>
<td width="166" bgcolor="#CCCC33"></td>
<td width="180" bgcolor="#CCCC33"><input type="text" name="name" /></td>
</tr>
<tr><td></td><td><input type="submit" name="submit" value="Go" /></td></tr>
</table>
</form><br>
<?php
$name=$_REQUEST['name'];
$number=$_REQUEST['number'];
?>
<?php
//mysql_query
if($name!=="")
{
$sql = "INSERT INTO `practice`.`name` (`ID`, `NAME`) VALUES (NULL, '$name');";
$result=mysql_query($sql);
if($result)
{
echo "Name Added";
}
else
{
echo "Failed (Name)";
}
}
else
echo"Filled up";
?>
########## End of the PHP Page ########
I need to execute Multiple MySQL Query with PHP looping. In the below PHP page i have created 2 field for adding name ... and i want that when i will press SUBMIT then every value of this field will be inserted to one table field in MySQL.
I need the solution. Please give this solution
###### PHP File which i have created to do this ########
<?php
require_once('dbconfig.php');
?>
<form name="name" method="post" action="">
Assign Number with Name:
<table width="329">
<?php
$sql = "SELECT * FROM `name`";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
?><tr>
<td width="166" bgcolor="#CC9966"><?php echo $row['NAME'];?></td>
<td width="180" bgcolor="#CC9966"><input type="text" name="number" /></td>
</tr>
<?php
}
?>
<tr><td></td><td><input type="submit" name="submit" value="Go" /></td></tr>
</table>
</form>
<form name="name" method="post" action="">
Create Name:
<table width="329">
<tr>
<td width="166" bgcolor="#CCCC33"></td>
<td width="180" bgcolor="#CCCC33"><input type="text" name="name" /></td>
</tr>
<tr><td></td><td><input type="submit" name="submit" value="Go" /></td></tr>
</table>
</form><br>
<?php
$name=$_REQUEST['name'];
$number=$_REQUEST['number'];
?>
<?php
//mysql_query
if($name!=="")
{
$sql = "INSERT INTO `practice`.`name` (`ID`, `NAME`) VALUES (NULL, '$name');";
$result=mysql_query($sql);
if($result)
{
echo "Name Added";
}
else
{
echo "Failed (Name)";
}
}
else
echo"Filled up";
?>
########## End of the PHP Page ########