0

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>
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by sajohnson05
0

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.

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.