1

I have two tables(measurementurl and webmeasurements) in a single database(probe_config) The first table measurementurl has the following fields

  1. id
  2. url
  3. comment

The second table webmeasurements has the following fields

  1. timeout
  2. url
  3. wm(id of the particular table,set to autoincrement)
  4. url_id

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');

?>

2
  • could you please reformat the code? Commented Mar 21, 2011 at 7:15
  • @ Mark Baker ..thanks for editing Commented Mar 22, 2011 at 4:35

1 Answer 1

2
$sql= "INSERT INTO webmeasurements (url_id) SELECT id FROM measurementurl";
Sign up to request clarification or add additional context in comments.

1 Comment

I have one more doubt.say for example ,the user enters in the measurementurl the following two details 1)id-1 2)url-www.yahoo.com 3)comment-yahoo and 1)id-2 2)url-www.google.com 3)comment-google. So the url yahoo now has the value 1 and google has the value 2.Then user reaches the next page namely the webmeasurements.php page and enters the details there,namely the 1)timeout and 2)url(radio buttons),where he has to choose any one of the url's i.e.(in our case,either yahoo or google).my job is to enter only the id corresponding to the chosen url into the database .plz correct my coding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.