Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old October 7th, 2003, 12:26 PM
boettger boettger is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ontario, Canada
Posts: 11 boettger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.


Reply With Quote
  #2  
Old October 7th, 2003, 12:42 PM
rsa_dude rsa_dude is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: South Africa
Posts: 29 rsa_dude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rsa_dude Send a message via AIM to rsa_dude Send a message via Yahoo to rsa_dude
RE: Using delete

Are you using a button or url to delete?

Reply With Quote
  #3  
Old October 7th, 2003, 02:52 PM
mdhall mdhall is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 158 mdhall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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...

Reply With Quote
  #4  
Old October 7th, 2003, 03:11 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: Using delete

Quote:
Error Message
Page cannot be found


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.

Reply With Quote
  #5  
Old October 8th, 2003, 11:44 AM
boettger boettger is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ontario, Canada
Posts: 11 boettger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #6  
Old October 8th, 2003, 01:02 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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>");
}

Reply With Quote
  #7  
Old October 8th, 2003, 01:20 PM
tkarkkainen's Avatar
tkarkkainen tkarkkainen is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: Finland
Posts: 2,320 tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 10700 Folding Title: Novice Folder
Time spent in forums: 6 Days 8 h 46 m 16 sec
Reputation Power: 4
RE: Using delete

Do what anonymous suggested, but ALSO do what mdhall suggested:

Quote:
make the query something like this...
php Code:
Original - php Code
  1.  
  2. $sql = ("DELETE FROM student WHERE st_num='$Student_Number', st_lname='$Last_Name',st_fname='$First_Name'");



That way it will use your PHP variables...

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Using delete


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway