Jump to content

Help with javascript/php mysql record updating


Darkmatter5

Recommended Posts

I have a checkbox in a form that has the following code.

 

<input type='checkbox' name='display_boxart' value='1' " .($userprefs['display_boxart']=='1'?"checked":""). " onchange='change_pref(\"display_boxart\",this.value,\"$userprefs[member_id]\")'>

 

Now here's the Javascript function change_pref

function change_pref(pref,str,id) {
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="change_prefs.php";
    url=url+"?p="+pref;
    url=url+"&t="+url;
    url=url+"&i="+id;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

 

And here's change_prefs.php as referenced in the javascript function

<?php
  include('library/config.php');
  require_once('library/vein_funcs.php');
  ($_GET['t']==""?$_GET['t']==0:$_GET['t']==1);
  $query="UPDATE members SET $_GET[p]=$_GET[t] WHERE member_id=$_GET[i]";
  $result=mysql_query($query) or die(mysql_error());
?>

 

My intent is when the user changes the check box to checked or not checked the members display_boxart value should be changed to 0 if display_boxart is unchecked or 1 if display_boxart is checked.

 

Am I on the right track? Is this the wrong way to do this? Is there an easier way to do this?

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.