Genesis730 Posted August 30, 2011 Share Posted August 30, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246040-jquery-help/ Share on other sites More sharing options...
AyKay47 Posted August 30, 2011 Share Posted August 30, 2011 BEFORE LOOKING AT THIS CODE I WILL SUGGEST THAT YOU USE FIREFOX'S FIREBUG TO HELP YOU IN PINPOINTING ANY JS ERRORS.. OR GOOGLE CHROMES BUILT IN DEBUGGER.. Quote Link to comment https://forums.phpfreaks.com/topic/246040-jquery-help/#findComment-1263641 Share on other sites More sharing options...
Genesis730 Posted August 30, 2011 Author Share Posted August 30, 2011 I tried Chrome's debugger with no avail Quote Link to comment https://forums.phpfreaks.com/topic/246040-jquery-help/#findComment-1263645 Share on other sites More sharing options...
AyKay47 Posted August 30, 2011 Share Posted August 30, 2011 no errors? Quote Link to comment https://forums.phpfreaks.com/topic/246040-jquery-help/#findComment-1263650 Share on other sites More sharing options...
Genesis730 Posted August 30, 2011 Author Share Posted August 30, 2011 none at all, it just doesn't do anything... Quote Link to comment https://forums.phpfreaks.com/topic/246040-jquery-help/#findComment-1263652 Share on other sites More sharing options...
Genesis730 Posted August 31, 2011 Author Share Posted August 31, 2011 Bump any other input would be awesome Quote Link to comment https://forums.phpfreaks.com/topic/246040-jquery-help/#findComment-1264082 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.