I am trying to check for duplicates prior to insert. I am not able to insert into mySQL with the following code. Any help?
<?php
# editout.php
# Seth Johnson
# Assingment 3
# ITEC 325
# perform update or insertion and then forward back to graform.php
# where can do another selection
?>
<html>
<head><title>Assignment 3</title></head>
<body>
<?php
//header('Refresh: 1; URL=https://php.radford.edu/~sajohnson/gpaform.php');
//database connection
if (isset($_POST['submitted'])){
require('dbconn.php');
$radio = $_POST["radio"];
$sem = $_POST["semester"];
$dept= $_POST["dept"];
$course = $_POST["courseNo"];
$hours = $_POST["semesterHour"];
$grade = $_POST["grade"];
$im = $_POST["inMajor"];
if ($radio == "ins")
{
echo "<h2>Perform Table Insert</h2>";
$query="select * from $table where 'courseNo'='{$course}'";
$results = mysql_query($query);
//$results = mysql_query($SQLcmd, $conn);
if(mysql_num_row($results)>1)
{
echo 'Course No. already exists';
}
else
{
$SQLcmd = "INSERT INTO $table (semester,dept,
courseNo,semesterHour,grade,inMajor) VALUES
'$sem','$dept','$course','$hours','$grade','$im')";
}
// if ($results)
// {
// echo "insert exec";
//}
//else
// {
// echo "insert didn't work";
//}
}
else
{
echo "<h2>Perform Record Delete</h2>";
$sqlcmd = "DELETE FROM $table WHERE courseNo = '$course'";
$results = mysql_query($sqlcmd,$conn);
if ($results)
{echo "it worked<br />";}
else
{echo "NO WORK";}
}
}
?>
<h2>Source Code</h2>
<?php
show_source(__FILE__);
?>
</body>
</html>