Welcome! Log In Create A New Profile

Advanced

Deleting rows form student table

Posted by Johnny - 72985186 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Deleting rows form student table
April 23, 2011 02:43PM
Alright so trying to add the delete function in the student table after getting the info to display on the page etc. What I'm trying to do is make the deletion process into 3 pages e.g select-confirm-delete. So you select the student you want to delete, then you get taken to a confirmation page and after confirming, the student gets deleted. I'm having a really odd error though:
Heres my first page where I'm getting the error:
Language: PHP
<?php   include 'includes/config.php'; $delete_sql ="SELECT sno,cname, sname FROM student ORDER BY sno DESC"; $delete_query = mysql_query($delete_sql) or die(mysql_error()); $rsDelete = mysql_fetch_assoc($delete_query); ?>     <html>   <head>   </head>     <body> <p> select student to delete </p> <?php do { ?> <p><a href="delstudentcomfirm.php?sno=<?php echo $rsDelete['sno']; ?>"> <?php echo $rsDelete['cname']; ?> by <?php echo $rsDelete['fname']; ?> </a> </p> <?php } while ($rsDelete = mysql_fetch_assoc($delete_query)) ?>       </body>   </html>

Error:
Warning: mysql_query() [function.mysql-query]: Access denied for user ''@'localhost' (using password: NO) in C:\Program Files\EasyPHP-5.3.3\www\Project\selectdelstudent.php on line 5

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files\EasyPHP-5.3.3\www\Project\selectdelstudent.php on line 5
Access denied for user ''@'localhost' (using password: NO)

I'm assuming this is due to my page not being able to connect to the database properly or something along those lines. Although I haven't changed anything with my database or my config.php page which works perfectly for my other pages. Anyone got any ideas?
avatar Re: Deleting rows form student table
April 23, 2011 03:16PM
And for interest sake here are my other 2 pages:
Confirm page:
Language: PHP
<?php   include 'includes/config.php'; session_start(); $_SESSION['deletestudent']['sno'] = $_GET['sno']; $confirm_sql = "SELECT * FROM student WHERE sno='".$_GET['sno']."' "; $confirm_query = mysql_query($confirm_sql); $rsconfirm = mysql_fetch_assoc($confirm_query); ?> <html> <head> </head> <body> <p> confirm student to delete</p> <p> <?php echo $rsConfirm['cname']; ?> </p> <p> <?php echo $rsConfirm['sname']; ?> </p> <p> <?php echo $rsConfirm['fname'];?> </p> <p><a href="selectdelstudent.php"> Oops, made a mistake</a></p> <p><a href="studentdeentdelete.php"> Delete this student</a></p>     </body> </html>

Delete page:
Language: PHP
<?php include 'includes/config.php'; session_start(); $delete_sql = "DELETE FROM student WHERE sno = '".$_SESSION['deletestudent']['sno']."'"; $delete_query = mysql_query($delete_sql); unset($_SESSION['deletestudent']); ?> <html> <body> <p> Student has been deleted </p> </body> </html>

Am I on the right track? If anyone has any improvements or comments feel free to throw em at me
Re: Deleting rows form student table
April 23, 2011 03:50PM
Just did a quick test, the error you are getting seems to occur when you have not done a mysql_connect statement before.

Try changing the include 'includes/config.php'; to require_once 'includes/config.php'; to see if you script can find the config file. Where are you creating the db connection?

The design looks good, I am doing a similar thing as well.

--

Student Number: 7298-786-3
avatar Re: Deleting rows form student table
April 23, 2011 03:52PM
Are your username, passwords etc for your database in your config.php file?

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
avatar Re: Deleting rows form student table
April 23, 2011 04:10PM
Language: PHP
<?PHP   define('DB_NAME', 'registration'); define('DB_USER', 'root'); define('DB_PASSWORD',''); define('DB_HOST', 'localhost');   ?>

Yeah this is my config file in my includes folder. The pages are in the same folder where my other pages are e.g the student form etc. and they connect to the database and work fine. Same path 'includes/config.php'
avatar Re: Deleting rows form student table
April 23, 2011 04:13PM
Try change localhost to 127.0.0.1, localhost doesn't work by me

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
avatar Re: Deleting rows form student table
April 23, 2011 04:23PM
Dont think I gave the command to connect properly, I adapted the code as followed:

Language: PHP
<?php   include 'includes/config.php'; //connect to database $link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);   //error check if (!$link) { die('could not connect: ' . mysql_error()); }   $db_selected=mysql_select_db(DB_NAME, $link);       // error check if (!$db_selected) { die('can\t use ' . DB_NAME . ': ' . mysql_error()); } // Connected to database   $delete_sql ="SELECT sno,cname, sname FROM student ORDER BY sno DESC"; $delete_query = mysql_query($delete_sql) or die(mysql_error()); $rsDelete = mysql_fetch_assoc($delete_query); ?>     <html>   <head>   </head>     <body> <p> select student to delete </p> <?php do { ?> <p><a href="delstudentcomfirm.php?sno=<?php echo $rsDelete['sno']; ?>"> <?php echo $rsDelete['cname']; ?> by <?php echo $rsDelete['fname']; ?> </a> </p> <?php } while ($rsDelete = mysql_fetch_assoc($delete_query)) ?>       </body>   </html>

Seems to be connecting fine now. Got a few notices and it's not quite displaying properly. But its progress grinning smiley
avatar Re: Deleting rows form student table
April 23, 2011 04:31PM
Yip apart from loads of notices of undefined variables etc and some display issues, it seems to be working fine I can delete students in my database from the page grinning smiley
avatar Re: Deleting rows form student table
April 23, 2011 04:54PM
paste the errors lets see smiling smiley And say when they happen

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
avatar Re: Deleting rows form student table
April 24, 2011 02:40AM
Haha sorted them quickly wasn't enough bad. Working fine now. Don't worry I'll bother you soon enough with helping me with the edit section. smile
Sorry, only registered users may post in this forum.

Click here to login