Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts

    Update Mysql with function

    PHP Code:
    function accept($id)
    {
        mysql_query("UPDATE applications SET pending = 'Accepted' WHERE id = '$id'");
    }

    <input type="button" value="Accept" onclick="accept(<? echo $row['id']; ?>);">
    The mysql connection is correct and eveything, it just says error in the bottom left with the little yellow warning sign.

  • #2
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    You're trying to use a php function as a javascript function. Wont work.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    lol, im always so confused about functions.

    I thought this would work becuase of http://www.w3schools.com/php/php_functions.asp

    How could I make it work?

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Many months ago, I explained, step by step, to you how to do almost this exact thing in This Thread.

    Javascript, that needs to do server side functions requires using the ajax framework, to call and process other server pages in the background, so you'd have to call the php script with javascript.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    Ndogg (03-04-2010)

  • #5
    Regular Coder
    Join Date
    Dec 2008
    Posts
    133
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Javascript:
    Code:
    function confirmation_query(wmqueryID) {
    	var answer = confirm("Delete this submitted query?")
    	if (answer==true){
    	window.location = "?id=delete&queryID="+wmqueryID+"";
    	return true;
    	}
    	else{
    	return false;
            }
    }
    Button:
    PHP Code:
    <a onclick="confirmation_query(<?php echo $query['wmqueryID'];?>)">
    <img src="../images/global/button_archive/small_delete.png" width="65" height="21" /></a>

    Corresponding PHP:

    PHP Code:
    //code executes if admin decides to delete query
    if($id == "delete") {
            
            
    $query_id $_GET['queryID']; //Gets the querie's ID
            
                    //Rest of db code etc.

            
    }//if ID=delete 

    May not be the best way but thats how i do it.
    Last edited by CallumJohnson; 03-02-2010 at 10:38 AM.

  • #6
    New Coder
    Join Date
    Feb 2010
    Location
    UK, North West
    Posts
    36
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello,
    Please escape the values before passing them into the database, this helps to minimize the rick of SQL injection.

    To escape values use this PHP function:

    PHP Code:

    $_GET
    ["yourAttribute"] = mysql_real_escape_string($_GET["yourAttribute"]);

    #Of if you're using the MySQLI extention which you need to have your server also supporting use this function below:

    $_GET["yourAttribute"] = mysqli_real_escape_string($connection$_GET["yourAttribute"]); 
    The above helps to escape any double quotes etc...

    Happy coding,
    Shaun

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by CallumJohnson View Post
    Javascript:
    Code:
    function confirmation_query(wmqueryID) {
    	var answer = confirm("Delete this submitted query?")
    	if (answer==true){
    	window.location = "?id=delete&queryID="+wmqueryID+"";
    	return true;
    	}
    	else{
    	return false;
            }
    }
    Button:
    PHP Code:
    <a onclick="confirmation_query(<?php echo $query['wmqueryID'];?>)">
    <img src="../images/global/button_archive/small_delete.png" width="65" height="21" /></a>

    Corresponding PHP:

    PHP Code:
    //code executes if admin decides to delete query
    if($id == "delete") {
            
            
    $query_id $_GET['queryID']; //Gets the querie's ID
            
                    //Rest of db code etc.

            
    }//if ID=delete 

    May not be the best way but thats how i do it.
    Then why even use javascript at all if all your js does go to a link? Why not simply this
    Code:
    <a href="?id=delete&queryID=<?php echo $query['wmqueryID'];?>" onclick="return confirm('Delete this submitted query?')">
    <img src="../images/global/button_archive/small_delete.png" width="65" height="21" /></a>
    Then in your php
    PHP Code:
    //code executes if admin decides to delete query
    if($id == "delete") {
            
            
    $query_id intval($_GET['queryID']); //Gets the querie's ID
            
                    //Rest of db code etc.

            
    }//if ID=delete 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Regular Coder
    Join Date
    Dec 2008
    Posts
    133
    Thanks
    15
    Thanked 0 Times in 0 Posts
    @_Aerospace_Eng_:

    Oh! Didn't know i could do it like that! Cheers

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by CallumJohnson View Post
    @_Aerospace_Eng_:

    Oh! Didn't know i could do it like that! Cheers
    That way it will still work if JS is disabled but they just don't get the confirm message. As for the OP, a simple ajax request to a php file that takes in a GET or POST and then echos the result would be all you need.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Zangeel View Post
    Many months ago, I explained, step by step, to you how to do almost this exact thing in This Thread.
    Lol, i forgot about that.


    But, for everything else, I already new how to do this by going to a different page or w/e, you know the ?=page thing, but what I want to try is make it all be done without changing or refreshing the page at all.

  • #11
    Regular Coder
    Join Date
    Dec 2008
    Posts
    133
    Thanks
    15
    Thanked 0 Times in 0 Posts
    But, for everything else, I already new how to do this by going to a different page or w/e, you know the ?=page thing, but what I want to try is make it all be done without changing or refreshing the page at all.
    you might want to have a look at AJAX then


  •  

    Posting Permissions

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