Results 1 to 8 of 8

Thread: javascript delete

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2011
    Posts
    55

    javascript delete

    here i have written to delete using javascript......
    it is "del.php"
    Code:
    <script>
    function fundel(sno)
    {
    rv=confirm("u want to delete");
    if(rv==true)
    {
    location="delete.php?seno="+sno;
    }
    }
    </script>
    <table border="2">
    <?php
    mysql_connect("localhost","root","");
    mysql_select_db("test");
    $data=mysql_query("select * from emp");
    while($rec=mysql_fetch_row($data))
    {
    echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>
    <input type="button" value="delete" onclick='fundel($rec[2])'>";
    }
    ?>
    also is the "delete.php"
    Code:
    <?php
    $qs=$_REQUEST['seno'];
    mysql_connect("localhost","root","");
    mysql_select_db("test");
    mysql_query("delete from emp where sno=$qs");
    header("location:getrec.php");
    ?>
    it is displaying the error as Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\del.php on line 19

    tell me what went wrong....
    whether it will delete the values.....

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: javascript delete

    Not to disappoint you but javascript and php have nothing to do with each other. Javascript is client-side code while php is server-side code.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    Re: javascript delete

    What is on line 19 of del.php?
    The one you have shown has only 7 lines.

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: javascript delete

    del.php is the first snippet he posted, PBertie. Your problem is here:
    PHP Code:
    echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>
    <input type="
    button" value="delete" onclick='fundel($rec[2])'>"
    PHP can't do multi-line strings like that.

    Edit: the above is full of stupid. Below is a possible correction you can use (also see techgnome's below), and some other fun ways you can write strings:
    PHP Code:
    //Escape the double quotes:
    echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>
    <input type=\"button\" value=\"delete\" onclick='fundel(
    $rec[2])'>"

    //Use a single line:
    echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr><input type=\"button\" value=\"delete\" onclick='fundel($rec[2])'>";

    //Use concatenation:
    echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>".
    "<input type=\"button\" value=\"delete\" onclick='fundel($rec[2])'>";

    //Use heredoc notation:
    echo <<<DOC
    <tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>
    <input type="button" value="delete" onclick='fundel(
    $rec[2])'>
    DOC; 
    Last edited by SambaNeko; Aug 18th, 2011 at 02:19 PM.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: javascript delete

    "PHP can't do multi-line strings like that." -- what? SHENNANIGANS! It can too... I do it all the time (usually when I'm dealing with SQL queries)... the problem is the " that are in the middle of the string... around button and delete.... they should be enclosed in single quote marks:


    PHP Code:
    echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]</tr>
    <input type='button' value='delete' onclick='fundel(
    $rec[2])'>"
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: javascript delete

    Whoops, sorry, don't know what I was thinking (something stupid, clearly). Post edited for clarity++

    I should also add it's usually best not to echo a bunch of HTML anyway; write your PHP as an embedded language:
    PHP Code:
    <?php
    //php here...
    ?>
    <tr><td><?php echo $rec[0];?><td><?php echo $rec[1];?><td><?php echo $rec[2];?></tr>
    <input type="button" value="delete" onclick='fundel(<?php echo $rec[2];?>)'>
    <?php
    //more php here... 
    ?>
    So I am being stupid and lazy lately.
    Last edited by SambaNeko; Aug 18th, 2011 at 02:24 PM.

  7. #7
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: javascript delete

    Quote Originally Posted by SambaNeko View Post
    I should also add it's usually best not to echo a bunch of HTML anyway
    I would also add that its usually best not to allow direct SQL injection attacks
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  8. #8
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: javascript delete

    Picky, picky.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width