Jump to content

Error in code


Johnnyboy123

Recommended Posts

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 :D

Link to comment
Share on other sites

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. :D

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.