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>

Recommended Answers

All 4 Replies

Why are you checking for >1 on line 37. I would think that you'd want to check for >0. As it is, your insert may fail because there is already one on file.

That makes sense i am not sure why i at >1. But i am still getting an error, could it be with isSet?

post your error please

Thats the thing i am not getting an error when i run my error test but when i try to insert i am getting the HTTP 500 error on the page

Be a part of the DaniWeb community

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