-4

both of my codes have

Parse error: syntax error, unexpected end of file

how can I solve. Im just a student, this is a homework. sorry if theres too much mistake tho , still learning.

UPDATE CODE:

<?php include "dbConfig.php";
error_reporting(E_ALL);
$msg = "";


        $db_id=$_POST['db_id'];
                        $sql="SELECT * FROM registry WHERE db_id='$db_id'";
        $result=mysql_query($sql);
        $count=mysql_num_rows($result);
<?php
        while($rows=mysql_fetch_array($result)){
?>

<?php

DELETE CODE:

<?php include "dbConfig.php";
error_reporting(E_ALL);
$msg = "";

                    if(isset($_POST['Submit'])){
                    $db_id = $_GET['db_id'];

                        $sql = mysql_query("DELETE from registry WHERE db_id 
     ='$db_id',db name = '$name', db_age = '$age', db_gender = '$gender',  
    db_birthdate = '$bdate', db_phone = '$phone', db_address = '$address'");

        if($sql > 0)
        {
           echo"record successfully deleted";
        }
        else
        {
        echo "error in deleting";
        }  
        ?>

    <div id='cssmenu'>
        <ul>
                <li class='active'><a href='home.php'><span>Home</span></a> 
            </li>
               <li><a href='save.php'><span>Save</span></a></li>
               <li><a href='update.php'><span>Update</span></a></li>
               <li class='last'><a href='delete.php'><span>Delete</span></a> 
    </li>
        </ul>
    </div>




    <form name="frmregister"action="<?php echo $_SERVER['PHP_SELF']?>"  
    method="post" >
    <table class="form" border="0">

        <tr>
        <td></td>
            <td style="color:red;">
            <?php echo $msg; ?></td>
        </tr>
        <tr>
            <th><label for="name"><strong>Employee ID:</strong></label></th>
            <td><input name = "db_id" type = "text" id = "db_id" size="30"  
    /></td>
        </tr>
        <td class="button">
    <a href="delete.php?id=<?php echo $row['db_id'] ?>"><input type="button"  
    name="delete" value="Delete"></a> 


     </td>
    </table>

    </form>


    </body>

    </html>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Pauline R
  • 1
  • 2
  • 2
    That isn't how DELETE works. RTM http://dev.mysql.com/doc/refman/5.7/en/delete.html add `or die(mysql_error())` to `mysql_query()` and you'll see the syntax error, besides the other syntax error you have which is "off-topic". You're using UPDATE syntax. and your UPDATE code doesn't "update" it SELECT's. – Funk Forty Niner Nov 30 '15 at 13:08
  • 2
    Please don't use `mysql_*` anymore, as it is deprecated. Use `mysqli_*` instead – Lino Nov 30 '15 at 13:11
  • For your SQL syntax errors... `WHERE` clauses don't separate individual elements with commas, they separate them with logical operators such as `AND` or `OR`. For your PHP syntax errors... When you open a block of code with a `{` you eventually need to close it with a `}`. – David Nov 30 '15 at 13:11
  • also why are you opening 2 times ` – Lino Nov 30 '15 at 13:13
  • 1
    Good catch on that ^ – Funk Forty Niner Nov 30 '15 at 13:14
  • this code's stitched with syntax errors. – Funk Forty Niner Nov 30 '15 at 13:14
  • @Fred-ii- yeah, its probably just poorly copied and pasted ^^ – Lino Nov 30 '15 at 13:16
  • 1
    @lino all the more reasons I don't post answers for questions like these. I've been down that "rocky road" before ;-) and they usually end up being a big can of worms. Nope, "been there, done that, got the T-shirt, blah blah blah". – Funk Forty Niner Nov 30 '15 at 13:23
  • 1
    @Fred-ii- exactly :-) Altough i sometimes post an answer, as i want to get some more reputation ._. – Lino Nov 30 '15 at 13:25
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 30 '15 at 13:26
  • 1
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Nov 30 '15 at 13:26
  • 1
    @lino Believe me and I've been there before; if I knew back then what I now know about questions like these, I wouldn't have wasted a LOT of time in trying to solve questions like these. It's full of syntax errors and we don't know their db schema, nor do we know if their HTML form isn't also failing and if `if(isset($_POST['Submit'])){...}` will even fire up for that matter. Nope; take it from experience Lino; stick to the questions you know for a fact where the problems are and how to fix them, rather than "hoping" it will fix it. It's all nice and dandy to help, but we can't save them all. – Funk Forty Niner Nov 30 '15 at 13:29
  • 1
    Then using `delete.php?id` and `$_GET['db_id']`. Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Nov 30 '15 at 13:31
  • @Fred-ii- It's so true what you've said. I promise, i'll carry your wisdom on ;-) – Lino Nov 30 '15 at 13:33
  • @lino You'll be the wiser ;-) *Cheers* – Funk Forty Niner Nov 30 '15 at 13:33
  • 3
    *"Im just a student, this is a homework"* - Oh... I see. Well, I don't do someone's else's "homework". Plus, I'm sure many others feel the same way as I do. Why should "you" do all of your class buddies' homework too? There you go (wink). – Funk Forty Niner Nov 30 '15 at 13:35

4 Answers4

3

the while($rows=mysql_fetch_array($result)){ doesn't have an ending }

Tdelang
  • 1,298
  • 2
  • 12
  • 20
  • 1
    yet alone nothing to "show" in that `while{...}` loop. Probably missing some code. – Funk Forty Niner Nov 30 '15 at 13:12
  • 1
    you beat me to it:D. also I want to mention that you(OP) should not use `mysql_*` functions use mysqli_* or PDO instead. As mysql_* functions are deprecated and in PHP 7.0 deleted from the library. Look at [this](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) post for more information.[PDO](http://php.net/manual/en/book.pdo.php) [mysqli](http://php.net/manual/en/book.mysqli.php) – BRoebie Nov 30 '15 at 13:14
0

You haven't ended the if(isset($_POST['Submit'])){ code block. You need a }. I'll let you figure out where that goes.

Mark Eriksson
  • 1,455
  • 10
  • 19
0

<?php include "dbConfig.php";
error_reporting(E_ALL);
$msg = "";

$db_id=$_POST['db_id'];
$sql="SELECT * FROM registry WHERE db_id='$db_id'";
        $result=mysql_query($sql);
        $count=mysql_num_rows($result);
        while($rows=mysql_fetch_array($result)){

}
?>

if(isset($_POST['Submit'])){
  $db_id = $_GET['db_id'];
   $sql = mysql_query("DELETE from registry WHERE db_id 
     ='$db_id'");

        if($sql > 0)
        {
           echo"record successfully deleted";
        }
        else
        {
        echo "error in deleting";
        }
}
        ?>
Virendra Nagda
  • 673
  • 5
  • 9
  • 2
    Why should the OP try this? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO. – Jay Blanchard Nov 30 '15 at 13:27
  • I think that between the many comments and answers Sam, that the OP ***might*** get a solution. @JayBlanchard Maybe, just maybe. – Funk Forty Niner Nov 30 '15 at 13:37
0

For DELETE You can use:

 if(isset($_GET['delete_id']))
   {
     $sql ="DELETE from registry WHERE db_id=".$_GET['delete_id'];
     $result=$mysqli->query($sql);
     header("Location:filename.php");
   }
Fameless
  • 345
  • 3
  • 17