this is my selection option database from "lecturer" table from subjects

No.  subject  credit_hour  capacity
1   (111) AAA     3           20
2   (222) BBB     4           10
3   (333) CCC     3           30

This is my option which is displaying the option using ajax which is testing1.php

$conn = mysql_connect('localhost','root','password');

if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();


function showUser(str)
if (str==="")
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState===4 && xmlhttp.status===200)
    <form action="" method="post">

<select name="sub" onchange="showUser(this.value)">
    <option value="">Select a subject:</option>  
<?php $result= mysql_query('SELECT * FROM subjects'); ?>
    <?php while($row= mysql_fetch_array($result)) { 

    <option value=<?php echo $row['No']?> >
          <?php echo htmlspecialchars($row['subject'] ); ?>

          <?php echo"credit hour";
          echo htmlspecialchars($row['credit_hour'] ); ?>

        <?php echo"capacity";
          echo htmlspecialchars($row['capacity'] ); ?>

    } ?>

        <input type="submit">
<div id="txtHint"><b>subject info will be listed here.</b></div>


this is the one is displaying it into table which is selected in the option testing2.php

$q = intval($_GET['q']);

$con = mysqli_connect('localhost','root','password','lecturer');
if (!$con)
  die('Could not connect: ' . mysqli_error($con));

$sql="SELECT * FROM subjects WHERE No = '".$q."'";

$result = mysqli_query($con,$sql);

echo "<table border='1'>


while($row = mysqli_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['subject'] . "</td>";
  echo "<td>" . $row['credit_hour'] . "</td>";
  echo "<td>" . $row['capacity'] . "</td>";
  echo "</tr>";
echo "</table>";


i am trying to create a button which is when i selected the option which is (111)AAA credit hour 3 capacity 20 and submit it will automatically insert into a new table which is user_subject

how to make the submit button???
thank you

Recommended Answers

All 2 Replies

Why do you not use the JQuery ?

Member Avatar

If your data is static, i.e. it's almost never updated, and there's not much of it, why not store the whole lot in a json object on page load. Then you don't need to make round trips to the server every time an user selects a different lecturer. Just a thought. Not useful for DB data that's changed often though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.