Jump to content

form method=post and isset submit


Noesis

Recommended Posts

Please can people review this code:

<!doctype html>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">    
<html>
<head>
<title>Pilot Codex Recording</title>
</head>
<body>

<?php

if (isset($_POST['codexsubmit']))
{

$run = "running";
print_r($run);

// initial database stuff
$host = "localhost";
$user = "root";
$pass = "pwd";
$db = "codexdb";

$connection = mysqli_connect($host, $user, $pass);
mysqli_select_db($db);

// Assign Variables

// Pilot id name
$pilot_id = $_POST['Pilot'];
// consider getting as forum user id or name

print_r($pilot_id); // debug

if (!(empty($pilot_id)))
{

// Banner id
$banner_id = $_POST['Banner'];

// reference date
$ref_date = date("Y-m-d");

// MECHS
$mech_text = $_POST['mech_textarea'];

print_r($mech_text); // debug

$lines_count = count(explode("\n", $mech_text));
$lines_array = explode("\n", $mech_text);

for ( $l=0; $l<=$lines_count; $l++ )
{
 
 $mech_string_raw = "";    
 $mech_string_raw = $lines_array[$l];
 $mech_string = str_replace("\n", "", $mech_raw_string);
 
 if (empty($mech_string))
 {
  continue;
 }
 
 if (stripos($mech_string, "Statistics"))
 {
  continue;    
 }
 
 if (stripos($mech_string, "Matches"))
 {
  continue;
 }

 // parsing mech stuff
 $count = 0;
 $mech_info = "";
 $mech_desc = "";
 $matches = 0;
 $win = 0;
 $loss = 0;
 $kills = 0;
 $deaths = 0;
 $damage = 0;
 $xp = 0;
 $time_string = "";

 $tmp_string = str_replace(",", "", $mech_string);
 $tmp_string2 = str_replace("/", "", $tmp_string);
 $tmp_string3 = str_replace("-", "", $tmp_string2);
 $tmp_string4 = str_replace("%", "", $tmp_string3);
 $tmp_string5 = str_replace(" day ", ":", $tmp_string4);
 $tmp_string6 = str_replace(" days ", ":", $tmp_string5);

 $count = count(explode(" ", $tmp_string6));
 $mech_info = explode(" ", $tmp_string6);

 $matches = $mech_info[$count-10];
 $win = $mech_info[$count-9];
 $loss = $mech_info[$count-8];
 $kills = $mech_info[$count-6];
 $deaths = $mech_info[$count-5];
 $damage = $mech_info[$count-3];
 $xp = $mech_info[$count-2];
 $time_string = $mech_info[$count-1];

 $time_count = 0;
 $time_count = count(explode(":", $time_string));
 $time_info = explode(":", $time_string);

 $time_second = 0;
 $time_second = $time_info[$time_count-1];
 $time_minute = 0;
 $time_minute = $time_info[$time_count-2];
 $time_hour = 0;
 $time_hour = $time_info[$time_count-3];
 $time_day = 0;
 $time_day=$time_info[$time_count-4];
 
 $total_time = (( $time_second ) + ( $time_minute * 60 ) + ( $time_hour * 3600 ) + ( $time_day * 86400 ));

 // mech description
 
 $text_count = $count - 11;
 $mech_desc = "";
 for ( $x=0; $x<=$text_count; $x++ )
 {
  $mech_desc = $mech_desc + $mech_info[$x] + " ";
 }
 $mech_desc = trim($mech_desc);

 // insert mech stuff
  $sql_qry = "IF EXISTS (SELECT * FROM pilot_stats_mech WHERE pilot_id = '$pilot_id' AND ref_date = '$ref_date' AND mech_desc = '$mech_desc') "
 + " THEN "
 + " UPDATE pilot_stats_mech SET banner_id = '$banner_id', matches = '$matches', win = '$win', loss = '$loss', kills = '$kills', deaths = '$deaths', damage = '$damage', xp = '$xp', total_time = '$total_time' "
 + " WHERE pilot_id = '$pilot_id' AND ref_date = '$ref_date' AND mech_desc = '$mech_desc' "
 + " ELSE "
 + " INSERT INTO pilot_stats_mech (pilot_id, banner_id, ref_date, mech_desc, matches, win, loss, kills, deaths, damage, xp, total_time) "
 + " VALUES ('$pilot_id', '$banner_id', '$ref_date', '$mech_desc', '$matches', '$win', '$loss', '$kills', '$deaths', '$damage', '$xp', '$total_time') ";

 print_r($sql_qry); // debug

 $result = mysqli_query($connection, $sql_qry);

} // for $l

} // if !empty $pilot_id

}

else

{
 $not_run = "Not running";
 print_r($not_run);
}

?>

<BR><BR>
<form method="post" action="<?php echo $PHP_SELF; ?>">
<fieldset>
<BR>

<label for="Pilot">Pilot name: </label><input id="Pilot" type="text" name="Pilot"><BR><BR>

<label for="Banner">Banner: </label><select id="Banner" name="Banner">
<option>None</option><option>Alpha</option><option>Bravo</option>
<option>Delta</option><option>Echo</option><option>Hotel</option>
<option>India</option><option>Juliette</option><option>Kilo</option>
<option>1st EG</option><option>2nd EG</option><option>3rd EG</option>
</select><BR><BR>

<label for="mech_textarea">Mech Stats: </label> <textarea rows="3" cols="150" name="mech_textarea"> </textarea><BR><BR>

<input type="submit" name="codexsubmit" value="Submit Codex"><BR>

</fieldset>
</form>

</body>
</html>

The problem I have is that despite debug with the print_r statements when I run the php in a browser it does not appear to do anything other than provide the form. It does not appear to run the php scripting elements.

 

I relatively new to php/html but not to programming.

 

Any assistance with this would be appreciated as I find it frustrating.

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.