|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Using delete
Operating System Windows 98
PHP Version 4.2.3 Error Message Page cannot be found I'm trying to get the delete to work but I'm just being frustrated. Any idea what I'm doing wrong. I'm using a table called Student with the fields Student_Number, Last_Name, First_Name. Here's my code for delete if (isset($deletestudent)) { $sql = "DELETE From student WHERE 'st_num' = Student_Number"; // '$st_lname' = Last_Name, // '$st_fname' = First_Name"; if (@mysql_query($sql)) { echo("<p>The student has been deleted.</p>"); } else { echo("<p>Error deleting student: " . mysql_error() . "</p>"); } } Thanks for any help you can give me. |
|
#2
|
|||
|
|||
|
RE: Using delete
Are you using a button or url to delete?
|
|
#3
|
|||
|
|||
|
RE: Using delete
Maybe make the query something like this...
$sql = ("DELETE FROM student WHERE st_num='$Student_Number', st_lname='$Last_Name',st_fname='$First_Name'"); Just a thought... |
|
#4
|
|||
|
|||
|
RE: Using delete
Quote:
First make sure you specify the correct URL to delete the recrod. The error message tells that the URL you requeted is invalid, not that the problem in SQL statment. |
|
#5
|
|||
|
|||
|
RE: Using delete
I'll enclose all my code. I think I'm trying to delete from a url.
<html> <head> <title> The Student Registration Database </title> </head> <body> <?php // If the user wants to add a student. if (isset($addstudent)): ?> <form action="<?=$PHP_SELF?>" method="post"> <p>Student Number: <textarea name="st_num" rows="1" cols="40" wrap> </textarea><br /> <p>Student Last Name: <textarea name="st_lname" rows="1" cols="40" wrap> </textarea><br /> <p>Student First Name: <textarea name="st_fname" rows="1" cols="40" wrap> </textarea><br /> <input type="submit" name="submitstudent" value="SUBMIT" /> </p> </form> <?php else: //Default page display $dbcnx = @mysql_connect("localhost", "user"); if (!$dbcnx) { echo( "<p>Unable to connect to the " . "database server at this time.</p>" ); exit(); } if (! mysql_select_db("enrollment") ) { echo( "<p>Unable to locate the enrollment " . "database at this time.</p>" ); exit(); } // If a student has been submitted, add it to the database. if ($submitstudent == "SUBMIT") { $sql = "INSERT INTO Student SET Student_Number ='$st_num', Last_Name ='$st_lname', First_Name ='$st_fname'"; if (@mysql_query($sql)) { echo("<p>The student has been added.</p>"); } else { echo("<p>Error adding student: " . mysql_error() . "</p>"); } } //If the user wants to delete a student. if (isset($deletestudent)) { $sql = "DELETE From student WHERE st_num = '$Student_Number', st_lname = '$Last_Name', st_fname = '$First_Name'"; if (@mysql_query($sql)) { echo("<p>The student has been deleted.</p>"); } else { echo("<p>Error deleting student: " . mysql_error() . "</p>"); } } echo("<p> Here are all the students in the Student Registration database:"."</p>"); $result = @mysql_query("SELECT Student_Number, Last_Name, First_Name FROM Student"); if (!$result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } ?> <table border> <tr> <th>Student # <th>Student Last Name <th>Student First Name <th>Delete </tr> <?php while ( $row = mysql_fetch_array($result) ) { echo("<tr><td>".$row["Student_Number"]. "<td>".$row["Last_Name"]. "<td>".$row["First_Name"]. "<td><p><a href='PHP_SELF?deletestudent={$row['Student_Number']}'>". "Delete this Student</a></p>". "</tr>"); } // When clicked, this link will load this page // with the student submission form displayed. echo("<p><a href='$PHP_SELF?addstudent=1'>Add a Student</a></p>"); endif; ?> </table> </body> </html> |
|
#6
|
|||
|
|||
|
RE: Using delete
href='PHP_SELF?deletestudent={$row['Student_Number']}'>".
"Delete this Student</a></p>". "</tr>"); } try putting a dollar before php_self and see what happens i think thats the problem. href='$PHP_SELF?deletestudent={$row['Student_Number']}'>". "Delete this Student</a></p>". "</tr>"); } |
|
#7
|
||||
|
||||
|
RE: Using delete
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Using delete |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|