Reputation: 37
I have two tables(measurementurl and webmeasurements) in a single database(probe_config) The first table measurementurl has the following fields
The second table webmeasurements has the following fields
I have a php page(wm.php) for inserting webmeasurements datas to the database in the second table(webmeasurements).i have given the database connections and my job is to bring the id values of the first table(measurementurl) to the second table (webmeasurements) on clicking the submit button of the wm.php page.I have attached the coding.can anyone spot out the mistake.
details of wm.php:
timeout(text box)
url(two radio buttons) and a submit button.
Following is the coding of wm.php:
<?php
include_once("connection.php");
$sql="select * from measurementurl";
// _Execute query_
$result=mysql_query($sql,$conn);
?>
<form method="post" action="base.php">
Timeout :
<input type="text" name="timeout" />
<?php
while ($row = mysql_fetch_array($result))
{
?>
<input type="radio" name="urls" value="<?php echo $row['id']?>" /><?php echo $row['url']?>
<?php
}
?>
<input type="submit" value="submit" name="submit" />
</form>
<?php
if(isset($_POST)){
echo " < pre>";
print_r($_POST);
}
?>
following is base.php of the action part:
<?php
//Begin of Checking Loop
$idarray = array();
$db = mysql_connect("localhost:3306", "root","mysql") or die("Could not connect.");
if(!$db)
die("no db");
if(!mysql_select_db("probe_config",$db))
die("No database selected.");
$acc1="SELECT id from measurementurl";
$acc2=mysql_query($acc1) or die("Could not select accounts.");
while($acc3=mysql_fetch_assoc($acc2))
$idarray[] = $acc3[id];
echo "<table border=1>\n";
echo " <tr>\n";
echo " <td>\n";
echo "<b>id</b>";
echo " </td>\n";
echo " <td>\n";
echo "<b></b>";
echo " </td>\n";
echo " </tr>\n";
// Display the URLS being processed.
foreach($idarray as $K => $id)
{
echo "<tr>\n";
echo "<td>\n";
echo $id;
echo "</td>\n";
ob_flush();
flush();
}
echo "</table>\n";
$timeout=$_POST['timeout'];
$url=$_POST['url'];
$name=$_POST['name'];
$url_id=$_POST['acc3[$id]'];
echo "$timeout";
echo "<br />$name";
$sql= "INSERT INTO webmeasurements (url_id, name, timeout) values
($url_id,'$name',$timeout)";
if (!mysql_query($sql,$db))
{
die('Error: ' . mysql_error());
}
else
{
echo "adding Done";
}
mysql_close('$db');
?>
Upvotes: 1
Views: 1677
Reputation: 125244
$sql= "INSERT INTO webmeasurements (url_id) SELECT id FROM measurementurl";
Upvotes: 2