SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with php and javaScript confirmaion

    Hi;
    I have problem with my javaScript confirmation code :
    content.php

    Code:
    $sql = "SELECT * FROM content";
    $query = mysql_query ( $sql);
    query_check ( $query );
    echo "<ul>";
    while ( $content = mysql_fetch_array ( $query ) )
    {
    $mic = $content ['conID'];
    echo "<li>";
    echo "<a>{$content ['title']}</a>";
    echo "<a href=\"edit_content.php?con=" . urlencode ( $content ['conID'] ) . "\" >Edit</a>";
    //echo "<a href=\"delete.php?con=" . urlencode ( $content ['conID'] ) . "\" >Delete</a>";
    echo "<a href=\"javascript:confirmDelete('delete_content.ph p?con={$content ['conID']}') \" class=\"de\">Delete</a>";
    echo "</li>";
    }
    echo "</ul>";

    and delete.php

    Code:
    $current_con = $_GET ['con'];
    $sql = "DELETE FROM content WHERE conID = $current_con LIMIT 1 ";
    $query = mysql_query($sql);
    
    if (mysql_affected_rows() == 1)
    {
    echo "<div>Content Deleted</div>"."<br>";
    
    
    
    }
    else
    {
    
    echo "<p>Cant delete content</p>";
    echo "<p>" . mysql_error() . "</p>";
    
    }
    when i use :

    Code:
    echo "<a href=\"javascript:confirmDelete('delete.php?con={$content ['conID']}') \" class=\"de\">Delete</a>";
    content deleted but with error message:

    Code:
    echo "<p>Cant delete content</p>";
    javascript:
    Code:
    <script type="text/javascript">
    function confirmDelete(delUrl) {
    if (confirm("do you want to delete this content?")) {
    document.location = delUrl;
    }
    }
    </script>
    what is wrong with javascript? thanks in advance

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_GET['con'];
    not
    $_GET ['con'];

    always debug your code.
    if you get an error in the query - print this query to the screen, to see what is wrong

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot Shrapnel_N5;
    But there is only the error when i using javascript confirmation.
    Content deleted but there is my written php error
    echo "<p>Cant delete content</p>";
    and i catn unerstand this.
    $_GET['con'];
    not
    $_GET ['con'];

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to debug your code. to see where is the problem
    step by step.
    But there is only the error when i using javascript confirmation.
    okay.
    print your query to the screen only then using javascript confirmation
    just add this line:
    PHP Code:
    print $sql
    and see what it say
    also, take a look onto address string
    are there an address you expected?

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the same problem by using javascript.
    BTW, thank you very much for help.

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the code above working perfect in local host, but working ugly in linux server


Bookmarks

Posting Permissions

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