Jump to content
MakeWebGames

Submit Fails


Recommended Posts

So, I was trying to create a staff file for the education courses I have for my game, however when ever I hit submit the fields reset and nothing happens.

 

function addcourse()
{
   global $db, $ir, $c, $h, $userid;
   $name =
           (isset($_POST['name'])
                   && preg_match(
                           "/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i",
                           $_POST['name']))
                   ? $db->escape(strip_tags(stripslashes($_POST['name'])))
                   : '';
   $description =
           (isset($_POST['description'])
                   && preg_match(
                           "/^[a-z0-9_.]+([\\s]{1}[a-z0-9_.]|[a-z0-9_.])+$/i",
                           $_POST['description']))
                   ? $db->escape(strip_tags(stripslashes($_POST['description'])))
                   : '';

$clicks_needed_total =
           (isset($_POST['clicks_needed_total']) && is_numeric($_POST['clicks_needed_total']))
                   ? abs(intval($_POST['clicks_needed_total'])) : '';
$clicks_max_hourly =
           (isset($_POST['clicks_max_hourly']) && is_numeric($_POST['clicks_max_hourly']))
                   ? abs(intval($_POST['clicks_max_hourly'])) : '';
$clicks_max_daily =
           (isset($_POST['clicks_max_daily']) && is_numeric($_POST['clicks_max_daily']))
                   ? abs(intval($_POST['clicks_max_daily'])) : '';
$cost_money =
           (isset($_POST['cost_money']) && is_numeric($_POST['cost_money']))
                   ? abs(intval($_POST['cost_money'])) : '';
$award_STR =
           (isset($_POST['award_STR']) && is_numeric($_POST['award_STR']))
                   ? abs(intval($_POST['award_STR'])) : '';
$award_GUARD =
           (isset($_POST['award_GUARD']) && is_numeric($_POST['award_GUARD']))
                   ? abs(intval($_POST['award_GUARD'])) : '';
$award_LABOUR =
           (isset($_POST['award_LABOUR']) && is_numeric($_POST['award_LABOUR']))
                   ? abs(intval($_POST['award_LABOUR'])) : '';
$award_AGIL =
           (isset($_POST['award_AGIL']) && is_numeric($_POST['award_AGIL']))
                   ? abs(intval($_POST['award_AGIL'])) : '';
$award_IQ =
           (isset($_POST['award_IQ']) && is_numeric($_POST['award_IQ']))
                   ? abs(intval($_POST['award_IQ'])) : '';

   $_POST['mustBeTakenBefore'] =
           (isset($_POST['mustBeTakenBefore']) && is_numeric($_POST['mustBeTakenBefore']))
                   ? abs(intval($_POST['mustBeTakenBefore'])) : '';


   if ($name && $description && $mustBeTakenBefore && $clicks_needed_total && $clicks_max_hourly && $clicks_max_daily && $cost_money && $award_STR && $award_GUARD && $award_LABOUR && $award_AGIL && $award_IQ)
   {
       staff_csrf_stdverify('staff_addcourse',
               'staff_education.php?action=addcourse');
       $q =
               $db->query(
                       "SELECT COUNT(`ID`)
                        FROM `education_courses`
                        WHERE `name` = '{$name}'");
       if ($db->fetch_single($q) > 0)
       {
           $db->free_result($q);
           error('Sorry, you cannot have two courses with the same name.');
       }
       $db->free_result($q);
       $db->query(
               "INSERT INTO `education_courses`
                VALUES('', '$name', '$description', '$mustBeTakenBefore', '$clicks_needed_total', '$clicks_max_hourly', '$clicks_max_daily', '$cost_money', '$award_STR', '$award_GUARD', '$award_LABOUR', '$award_AGIL', '$award_IQ')");
       confirmation('Course ' . $name
               . ' added to the game.');
       stafflog_add("Created course $name");
   }
   else
   {
       $csrf = request_csrf_html('staff_addcourse');
       echo "
       <h3>Add Course</h3>
       <hr />
       <form action='staff_education.php?action=addcourse' method='post'>
       Name: <input type='text' name='name' />
       <br />
       Previous Course Required: " . course_dropdown(NULL, "mustBeTakenBefore")
               . "
       <br />
       Total Clicks: <input type='text' name='clicks_needed_total' />
       <br />
       Maximum Clicks Hourly: <input type='text' name='clicks_max_hourly' />
       <br />
       Maximum Clicks Daily: <input type='text' name='clicks_max_daily' />
       <br />
       Course Cost: <input type='text' name='cost_money' />
       <br />
       Strength Reward: <input type='text' name='award_STR' />
       <br />
       Agility Reward: <input type='text' name='award_AGIL' />
       <br />
       Guard Reward: <input type='text' name='award_GUARD' />
       <br />
       Labour Reward: <input type='text' name='award_LABOUR' />
       <br />
       IQ Reward: <input type='text' name='award_IQ' />
       <br />
       	{$csrf}
       	<input type='submit' value='Add Course' />
       </form>
          ";
   }
}

 

[ATTACH=CONFIG]1705[/ATTACH]

297336389_ScreenShot2014-10-06at17_38_00.thumb.png.7b906eb036724efd6321c725084481ed.png

Link to comment
Share on other sites

First rule of debugging; echo out your results to compare with expected.

 

For this, use this within the post and post the outcome;

 

echo '<pre style="text-align: left;">';
print_r($_POST);
echo '</pre>';

 

With that said, I always find it easier to have a function to do the above, which makes it quick to dump an array out for viewing, like this;

 

function pr_arr($array) {
   echo '<pre style="text-align: right; border: solid 1px red; background: white; color: black;">';
   print_r($array);
   echo '</pre>';
   exit;
}

 

With that function, you simply go;

 

pr_arr($_POST);

 

Anyway, sort that out and post results, then we'll move on with bug finding techniques :)

Edited by Guest
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...