hi. am new to php. got a problem with inserting data into another table in mysql database afta.
Here is the code

<td><form action="ProCollegePrograms.php" method="post">
      <table  width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
      <td><span class="textblack">College Code</span><span class="required"><font color="#CC0000">*</font></span><br></td>
      <td><input name="CollegeCode" type="text" class="required username" id="CollegeCode" size="40" minlength="2" ></td>
       <tr>
       </
      </tr>
        <tr>
          <th width="50%" height="39">Check off the programs you offer</th>
          <th width="50%">Course  Name </th>
        </tr>
  <?php
$sql = "SELECT course_no,Name FROM courses ";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);

while($row=mysql_fetch_array($result))
{
$Name=$row['Name'];
?>
     <tr>
<td><input type="checkbox" name="Name[]" value="<?php echo $Name; ?>"  align="middle"/></td>
<td><?php echo $Name; ?>
 <td>&nbsp;</td>
</tr>
<?php

}

?>

and the PropCollegePrograms.php is

<?php
include 'admin/dbc.php';

$code=$_POST["CollegeCode"];

if (isset($_POST))
{
foreach ($_POST as $name)
{
//$ints .= "$value, ";
$allnames .= $style . ", ";
$allnames = substr($allnames, 0, -2);
}
else
{
echo 'You forgot to enter a course.';
}

$sql="INSERT INTO procourses ( CollegeCode,Name) VALUES ('code','$allnames')";
$result=mysql_query($sql);
if($result)
{
echo"good";
}
else
{
echo"baaad";
}

?>

Member Avatar

TechySafi

Try this,

$sql="INSERT INTO procourses ( CollegeCode,Name) VALUES ('$code','$allnames')";

If the problem still remain then explain what kinda error/problem it is! You just said

got a problem with inserting data

but wouldn't it be easier for us to check your code if we would know what problem you are facing?

Apply that code, and let me know the result.