sugarplum_19 Posted January 6, 2011 Share Posted January 6, 2011 I am trying to delete a row of data in the data base, but in this table the primary key is a composite key, (SID, CID). How can i delete a row of data below shows the code that I have done function delete_studentcourse($SID, $CID) { $esc_SID = mysql_real_escape_string($SID, $this->conn); $esc_CID = mysql_real_escape_string($CID, $this->conn); $sql = "DELETE FROM studentcourses where SID && CID='($SID, $CID, $grade, $comments)'"; $result = mysql_query($sql, $this->conn); if (!$result) die("SQL Error: " . mysql_error()); else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } <?php include 'db_studentcourse.php'; //import the class in this web page ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Delete Student-course</title> </head> <body> <?php if (!$_POST) { //page loads for the first time ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Enter the student id you want to delete:<input type="text" name="SID" /><br /> Enter the course id you want to delete:<input type="text" name="CID" /><br /> <input type="submit" value="Save" /> </form> <?php } else { $db1 = new db_studentcourse(); $db1->openDB(); $numofrows = $db1->delete_studentcourse($SID); $numofrows = $db1->delete_studentcourse($CID); echo "Success. Number of rows affected:<strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.