Johnnyboy123 Posted April 21, 2011 Share Posted April 21, 2011 I have a page that displayes a table from my database. What I'm attempting to do is create a page where you can delete rows of that table. I'm creating 3 pages 1( select the student or row to delete) 2( comfirm whether you want to delete that student) and 3( where the student has been deleted) I'm already having trouble with my first page. This is my code to select the row or student you want to delete: <?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="deletecomfirm.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> ?> I keep getting this error: Parse error: syntax error, unexpected $end in C:\Program Files\EasyPHP-5.3.3\www\Project\selectdelstudent.php on line 32 I'm assuming this error indicates an improper closing tag or something? Though I can't see my mistake. Also if you have any tips on improving my code feel free to comment Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/ Share on other sites More sharing options...
Johnnyboy123 Posted April 21, 2011 Author Share Posted April 21, 2011 Also this is my code for the other pages: Comfimation Page: <?php <?php include 'includes/config.php' sesseion_start(); $_SESSION['deletestudent']['sno'] =$_GET['snp']; $confirm_sql = "SELECT * FROM student WHERE sno='".$_GET['sno']." "; ?> <html> <head> </head> <body> <p> comform 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="deleteselect.php"> Oops, made a mistake</a></p> <p><a href="deletestudent.php"> Delete this student</a></p> </body> </html> ?> Delete page: <?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']; ?> <body> <p> Student has been deleted </p> </body> <html> ?> I haven't quite looked through the code to debug it yet only wrote it with the aid of an tutorial. For now before I get 2 these 2 pages of code I have to sort out my error on the first. This is just to show more or less what I'm doing and how I'm planning on going about it. Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/#findComment-1204419 Share on other sites More sharing options...
gergy008 Posted April 21, 2011 Share Posted April 21, 2011 sesseion_start(); On the first of the other pages. I don't know if this effects anything but I just spotted it. Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/#findComment-1204428 Share on other sites More sharing options...
kenrbnsn Posted April 21, 2011 Share Posted April 21, 2011 I would change your first script to <?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("Problem with the query: $delete_sql<br>" . mysql_error()); $tmp = array(); while ($rsDelete = mysql_fetch_assoc($delete_query)) { $tmp[] = "<p><a href='deletecomfirm.php?sno={$rsDelete['sno']}'>{$rsDelete['cname']} by {$rsDelete['fname']}</a></p>"; } ?> <html> <head> </head> <body> <p> select student to delete </p> <?php echo implode("\n",$tmp) . "\n"; ?> </body> </html> In your Confirmation page, you had some misspellings and left out some code: <?php session_start(); include 'includes/config.php' $_SESSION['deletestudent']['sno'] =$_GET['snp']; $confirm_sql = "SELECT * FROM student WHERE sno='{$_GET['sno']}'"; $rs = mysql_query($confirm_sql) or die("Problem with the query: $confirm_sql<br>" . mysql_error()); // you left out this line $rsConfirm = mysql_fetch_assoc($rs); //you left out this line ?> <html> <head> </head> <body> <p> Confirm student to delete:</p> <?php echo "<p>{$rsConfirm['cname']}</p>\n"; echo "<p>{$rsConfirm['sname']}</p>\n"; echo "<p>{$rsConfirm['fname']}</p>\n"; ?> <p><a href="deleteselect.php"> Oops, made a mistake</a></p> <p><a href="deletestudent.php"> Delete this student</a></p> <body> </html> The Delete page had a few errors: <?php session_start(); include 'includes/config.php' $delete_sql = "DELETE FROM student WHERE sno = '{$_SESSION['deletestudent']['sno']}'"; $delete_query = mysql_query($delete_sql) or die("Problem with the query: $delete_sql<br>" . mysql_error()); unset($_SESSION['deletestudent']; ?> <html> <body> <p> Student has been deleted </p> </body> <html> Ken Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/#findComment-1204436 Share on other sites More sharing options...
Johnnyboy123 Posted April 21, 2011 Author Share Posted April 21, 2011 Thank you. Know my last 2 pages had some errors etc haven't checked them for errors yet just provided them as an idea of what I'm doing but thanks for the error check . Alright will try the adjustments out. Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/#findComment-1204440 Share on other sites More sharing options...
Johnnyboy123 Posted April 21, 2011 Author Share Posted April 21, 2011 I changed all my pages accordingly and getting the following errors, I'm still very new to php so would just like to know what these errors are an indication of: First page: 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 4 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 4 Problem with the query: SELECT sno,cname, sname FROM student ORDER BY sno DESC Access denied for user ''@'localhost' (using password: NO) I'm assuming theres some problem with accessing the database? What should I look at when I get this error? And for the other 2 pages I get: Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\EasyPHP-5.3.3\www\Project\studentdelete.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/#findComment-1204447 Share on other sites More sharing options...
kenrbnsn Posted April 21, 2011 Share Posted April 21, 2011 As for the mysql error, that is tell you that your username and/or password is incorrect or something else is wrong in your config.php. The other error, the semi-colon is missing from the end of <?php include 'includes/config.php' ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/234332-error-in-code/#findComment-1204449 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.