Jump to content

jQuery help


Genesis730

Recommended Posts

I have some js files I want to use to be able to change values in a DB without reloading the page, also with just 1 click.. As it is, when I click the link to change the DB, nothing happens at all... :( and I don't know if I just have a simple mistake or what... Here's what I have

 

*** jQuery.js ***

$(document).ready(function() {
    $(".wrench").click(function() {
        var anchor = $(this).attr("id").split("-");
        var span = $("#span-" + anchor[1]);
        var textBox = $("#text-" + anchor[2]);
        var userID = anchor[3];
        var type = anchor[4];
        $.getJSON('../admin_click_update_db.php', {
            'text': textBox.val(),
            'UID': userID,
            'type': type
        }, function(data) {
            if (data.error == false) {
                if (span.text() == 1) {
                    span.text(0);
                } else {
                    span.text(1);
                }
               } else {
                alert(data.errorMessage);   
            }
        });
    });
    $(".textBox").change(function() {
        var id = $(this).attr("id").split("-");
        var val = $(this).val();
        
         $.getJSON('../admin_field_update_db.php', { // not used yet...
             
        }
    });
});

*** ADMIN_CLICK_UPDATE_DB.PHP ***

<?PHP
$data = array(); $data['error'] = false; $data['change'] = false;
if(isset($_GET['param1']) && isset($_GET['param2']) && isset($_GET['param3'])) {
  $data['change'] = true;
  $UID = mysql_real_escape_string($_GET['UID']);
  $type = mysql_real_escape_string($_GET['type']);
  $text = mysql_real_escape_string($_GET['text']);
if($type == 0) {
        $new = 1;
        $query = mysql_query("SELECT activated FROM JQtest WHERE ID = '$UID'" );
        if(mysql_result($query,0) == 1){
                $new = 0;
        } 
    } elseif($type == 1) {
         $new = 1;
        $query = mysql_query("SELECT disabled FROM JQtest WHERE ID = '$UID'" );
        if(mysql_result($query,0) == 1){
                $new = 0;
        } 
      $query = mysql_query("UPDATE `JQtest` SET disabled='$new' WHERE username='$UID' ");
    if(!$query){
            $data['error'] = true;
            $data['errorMessage'] =  mysql_error();
    } else {
        $data['error'] = false;
    }
} else {
  $data['error'] = true;
}
echo json_encode($data);
}
?>

 

*** admincenter.php ***

<?PHP
require_once('user_functions.php');
echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write("<script src=\'js/jquery-1.6.2.js\'>\x3C/script>")</script> 
      <script type="text/javascript" language="javascript" src="js/javascript.js"></script>';
$title = "Admin Center";
require_once "header.php";
$username = $_SESSION['username'];
$result = mysql_query("SELECT ulevel FROM `JQtest` WHERE username = '$username'");
$row = mysql_fetch_array($result);
$rank = $row['ulevel'];
$span = 0;
$text = 0; // or textbox
if (!LoggedIn()) {
    header("Location: index.php");
}
echo '<div id="main" align="center">';
$result = mysql_query("SELECT * FROM `JQtest` ORDER BY registered DESC LIMIT 10");
if((mysql_num_rows($result) < 1)) {
    echo "There are no accounts yet";
} else {
    echo '<table cellspacing="2" cellpadding="5" border="0" align="center">
    <tr align="center">
        <td><b>Username</b></td>
        <td><b>Email</b></td>
        <td><b>Rank</b></td>
        <td><b>Activated</b></td>
        <td><b>Disabled</b></td>
        <td><b>Delete Acct</b></td>
    </tr>';
    while( $row = mysql_fetch_array($result)){
        echo '
    <tr align="center">
        <td>'.$row[2].'</td>
        <td>'.$row[6].'</td>
        <td> <input type="text" value="'.$row[1].'" id="text-'.$text.'" size="1"></td>
        <td><span id="span-'.$span.'">'.$row[14].'</span><a href="#" id="w-'.$span.'-'.$text.'-'.$row[0].'-0"><img src="images/wrench.png"></td>'; ++$span;
        echo '
        <td><span id="span-'.$span.'">'.$row[11].'</span><a href="#" id="w-'.$span.'-'.$text.'-'.$row[0].'-1"><img src="images/wrench.png"></td>'; ++$span;
        echo '
        <td><a href="#"><img src="images/cross.png"></td>
    </tr>';
        ++$text;
        $span = 0;
    }
}
echo '</table>
</div>';
require_once "footer.php";
?>

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.