Jump to content

Character Id


Xtremer360

Recommended Posts

I know via firebug that the correct parameters were passed to my process page and the parameter being passed that in caused issues on the process page is $characterIDList. What's causing the issue is that its not inserting the value into the insert query. The rest of the insert query works fine.

 

process page

 

$characterIDs = explode(',', $_POST['characterIDList']); 
    foreach($characterIDs as $itm){
         $id = (int)$itm;
     }
    $defaultcharid = (int)$characterIDs[0];

$query = "INSERT INTO `handlers` (username, password, firstname, lastname, email, status_id, isadmin, default_character_id, creator_id, datecreated) VALUES ('$username','$password','$firstname','$lastname','$email','$status','$admin', '$defaultcharid', 1, NOW())";

Link to comment
Share on other sites

Firebug only works client side, so it isn't going to provide much help in determining a server-side issue.

 

You should echo the server-side variables you are having problems with. First, your post processing appears to have some unneccessary code. There is a foreach loop that is continually redefining the variable $id. That loop has no purpose since you aren't even using the value. However, you are trying to use the first value in the array and convertning it to an int. But, you need to be sure that there is a legitimate value that can be converted to an int.

 

I also see that you "seem" to have the admin and default_character_id fields/values switched between the field list and the values list in the query. That is probably the problem. That is why I always write my code with appropriate line breaks and spacing to enhance readability of the code.

 

Give this a try:

$characterIDs = explode(',', $_POST['characterIDList']);
$defaultcharid = (int) $characterIDs[0];
  
$query = "INSERT INTO `handlers`
              (username,    password,   firstname,   lastname,   email,
               status_id, isadmin, default_character_id, creator_id, datecreated)
          VALUES
              ('$username','$password','$firstname','$lastname','$email',
               '$status','$admin', '$defaultcharid',     1,          NOW())";

echo "<b>Debugging info:</b><br />\n";
echo "POST['characterIDList']: {$_POST['characterIDList']}<br />\n"
echo "defaultcharid: {$defaultcharid}<br />\n"
echo "Query: {$query}<br />\n";

Link to comment
Share on other sites

That works great thank you however I want to add something to it. I want it to basically before it runs through check to make sure that in that table called handlers that there isn't someone already with that characer as there default_character_id and if there is a match then it kicks it back to my form with an alert since I am also using jquery on my front end.

Link to comment
Share on other sites

I can help with the server-side code, but since I don't know what format to return the error, I'll leave it to you to coordinate the logic with your AJAX response.

 

Anyway, here is a rough example:

$characterIDs = explode(',', $_POST['characterIDList']);
$defaultcharid = (int) $characterIDs[0];

$query = "SELECT FROM `handlers` WHERE default_character_id = '$defaultcharid'";
$result = mysql_query($query);
if(!$result)
{
    echo "Error running query (1).";
}
elseif(mysql_num_rows($result)!==0)
{
    echo "That default character already exists.";
}
else
{
    $query = "INSERT INTO `handlers`
                  (username,    password,   firstname,   lastname,   email,
                   status_id, isadmin, default_character_id, creator_id, datecreated)
              VALUES              ('$username','$password','$firstname','$lastname','$email',
                   '$status','$admin', '$defaultcharid',     1,          NOW())";
    $result = mysql_query($query);

    if(!$result)
    {
        echo "Error running query (2).";
    }
    else
    {
        echo "New default character ID saved.";
    }
}

Link to comment
Share on other sites

Amazing work. What do you mean format? If you mean what I'm using on client side scripting on my front end it's jquery.

 

What I mean is that if you are returning the results to an AJAX query, then the data will need to be in the format that you want to use in the jquery code to display on the page. For example, you could have the PHP code format the error message to display in red

echo "<span style="color:#ff0000;">Error message here</span>";

 

Or you might send the data to return multiple parameters that are deliniated in some fashion. For example, you might want to return a true/false along with an appropriate message. Then use the javascript code to pull apart the individual parameters and handle accordingly in the javascript, such as enabling/diabling buttons, or whatever

echo "1|Query executed succesfully";

echo "0|Query failed due to db error";

etc.

 

 

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.