Hi
I am selecting exercise and repetition to see progression with graph and a table.
And i want to make it possible to copy the link and send it to others with the selected criteria.
Here is my code…
Fetch the variables after clicking on submit:
if(isset($_POST['select']))
{
$ex_id2 = $_POST['select_exercise'];
$nr_reps2 = $_POST['reps'];
}
The form:
<form method="post" action="index.php?action=profile&sub=stats_progress&id=<?php echo $USER_PROFILE->getId(); ?>&exid=<?php if(isset($_POST['select'])){ echo $ex_id2; } ?>&rep=<?php if(isset($_POST['select'])){ echo $nr_reps2; } ?>">
Now i get the variables to the form after submiting, then when i submit again or reload the page it get to the url.
Notice: Its the same page, just selecting which exercise to view.
How can i make them go to the url directly?
use method=“get” instead of “post”
Forbidden
You don’t have permission to access /mysite/< on this server.
In the url it says: http://localhost/mysite/<?=$url?>
<?php
if(isset($_POST['select']))
{
$ex_id2 = $_GET['select_exercise'];
$nr_reps2 = $_GET['reps'];
$user_id2 = $_GET['user_id'];
echo $ex_id2;
}
?>
<form method="get" action="index.php?action=profile&sub=stats_progress&id=<?php echo $USER_PROFILE->getId(); ?>&exid=<?php if(isset($_GET['select'])){ echo $ex_id2; } ?>&rep=<?php if(isset($_GET['select'])){ echo $nr_reps2; } ?>">
<table border="0">
<tr>
<td>
<b><?php echo ucf(translate('exercise')); ?>:</b>
</td>
<td>
<select name="select_exercise">
<?php
$sql= mysql_query("SELECT * FROM exercise_name ORDER BY ex_name ASC");
while($row = mysql_fetch_assoc($sql))
{
$ex_id = $row['ex_id'];
$ex_name = $row['ex_name'];
echo '<option name="ex_id" value='. $ex_id.'';
if(isset($_POST['select']) && $_POST['select_exercise']== $ex_id) { echo " selected='selected'"; }
echo '>'. translate($ex_name) . '</option>';
}
?>
</select>
</td>
<td align="right">
<b><?php echo ucf(translate('reps')); ?>:</b>
</td>
<td>
<select name="reps">
<option name="reps" value="1" <?php if(isset($_POST['select']) && $_POST['reps']== 1) { echo " selected='selected'"; } ?>>1RM</option>
<option name="reps" value="2" <?php if(isset($_POST['select']) && $_POST['reps']== 2) { echo " selected='selected'"; } ?>>2RM</option>
<option name="reps" value="3" <?php if(isset($_POST['select']) && $_POST['reps']== 3) { echo " selected='selected'"; } ?>>3RM</option>
<option name="reps" value="4" <?php if(isset($_POST['select']) && $_POST['reps']== 4) { echo " selected='selected'"; } ?>>4RM</option>
<option name="reps" value="5" <?php if(isset($_POST['select']) && $_POST['reps']== 5) { echo " selected='selected'"; } ?>>5RM</option>
<option name="reps" value="6" <?php if(isset($_POST['select']) && $_POST['reps']== 6) { echo " selected='selected'"; } ?>>6RM</option>
<option name="reps" value="7" <?php if(isset($_POST['select']) && $_POST['reps']== 7) { echo " selected='selected'"; } ?>>7RM</option>
<option name="reps" value="8" <?php if(isset($_POST['select']) && $_POST['reps']== 8) { echo " selected='selected'"; } ?>>8RM</option>
<option name="reps" value="9" <?php if(isset($_POST['select']) && $_POST['reps']== 9) { echo " selected='selected'"; } ?>>9RM</option>
<option name="reps" value="10" <?php if(isset($_POST['select']) && $_POST['reps']== 10) { echo " selected='selected'"; } ?>>10RM</option>
<option name="reps" value="11" <?php if(isset($_POST['select']) && $_POST['reps']== 11) { echo " selected='selected'"; } ?>>11RM</option>
<option name="reps" value="12" <?php if(isset($_POST['select']) && $_POST['reps']== 12) { echo " selected='selected'"; } ?>>12RM</option>
<option name="reps" value="13" <?php if(isset($_POST['select']) && $_POST['reps']== 13) { echo " selected='selected'"; } ?>>13RM</option>
<option name="reps" value="14" <?php if(isset($_POST['select']) && $_POST['reps']== 14) { echo " selected='selected'"; } ?>>14RM</option>
<option name="reps" value="15" <?php if(isset($_POST['select']) && $_POST['reps']== 15) { echo " selected='selected'"; } ?>>15RM</option>
<option name="reps" value="16" <?php if(isset($_POST['select']) && $_POST['reps']== 16) { echo " selected='selected'"; } ?>>16RM</option>
<option name="reps" value="17" <?php if(isset($_POST['select']) && $_POST['reps']== 17) { echo " selected='selected'"; } ?>>17RM</option>
<option name="reps" value="18" <?php if(isset($_POST['select']) && $_POST['reps']== 18) { echo " selected='selected'"; } ?>>18RM</option>
<option name="reps" value="19" <?php if(isset($_POST['select']) && $_POST['reps']== 19) { echo " selected='selected'"; } ?>>19RM</option>
<option name="reps" value="20" <?php if(isset($_POST['select']) && $_POST['reps']== 20) { echo " selected='selected'"; } ?>>20RM</option>
</select>
</td>
<td>
<input type="hidden" name="user_id" value="<?php echo $USER_PROFILE->getId(); ?>" />
<input type="submit" style="font-weight:bold;" name="select" value=" <?php echo ucf(translate('show')); ?> " />
</td>
</table>
</form>
Code to display table and graph
<?php
if(isset($_GET['select']))
{
$ex_id = $_GET['select_exercise'];
$nr_reps = $_GET['reps'];
$user_id = $_GET['user_id'];
echo "<br /><h1>" . ucf(translate(getExercisename($ex_id))) . " - ". $nr_reps . "RM</h1><br />";
// Get all the data
$result = mysql_query("SELECT DISTINCT
training.date,
lifts.kg,
lifts.url,
training.training_id,
training.place,
training.bodyweight
FROM lifts, training
WHERE training.training_id=lifts.training_id AND lifts.rep = ". $nr_reps ." and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
ORDER BY training.date") or die(mysql_error());
// Get the PB
$result_pb = mysql_query("SELECT DISTINCT
training.date,
max(lifts.kg) as kg,
training.training_id
FROM lifts, training
WHERE training.training_id=lifts.training_id AND lifts.rep = ". $nr_reps ." and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
ORDER BY training.date LIMIT 1") or die(mysql_error());
// Get the last/badest lift
$result_bpb = mysql_query("SELECT DISTINCT
training.date,
lifts.kg,
training.training_id
FROM lifts, training
WHERE training.training_id=lifts.training_id AND lifts.rep = ". $nr_reps ." and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
ORDER BY training.date LIMIT 1") or die(mysql_error());
$num = mysql_num_rows($result);
$i=1;
$strXML = "<chart caption='" . ucf(translate('myprogress')) . " - " . ucf(translate(getExercisename($ex_id))) . " ". $nr_reps . "RM" . "' subCaption='" . ucf(translate('for')) . " " . getNameFromId($USER_PROFILE->getId()) . "' showBorder='1' formatNumberScale='0' numberSuffix='". $w_metric ."' baseFont='Arial' exportEnabled='1' exportAtClient='0' exportHandler='Charts/ExportHandlers/PHP/FCExporter.php' exportAction='download' exportTargetWindow='_blank' exportFileName='" . ucf(translate('myprogress')) . "'>";
if($i <= $num)
{
echo "<table><tr><td>
<table border='1'>";
echo "<tr><th>" . translate('date') . "</th><th>". ucf(translate('place')) ."</th><th>" . ucf(translate('bodyweight')) . "</th><th>". translate('lifted') ."</th></tr>";
$max_kg = 0;
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result))
{
if(r_nr(calcFromKg($row['kg'])) > $max_kg)
{
$max_kg = r_nr(calcFromKg($row['kg']));
// Print out the contents of each row into a table
echo "<tr><td width='140' align='center'>";
echo formatDate($row['date'], $dateformat);
echo "</td><td width='160' align='center'>";
echo $row['place'];
echo "</td><td width='100' align='center'>";
echo r_nr2(calcFromKg($row['bodyweight'])). $w_metric;
echo "</td><td width='130' align='center'>";
echo "<a href='index.php?action=profile&sub=show&tid=". $row['training_id'] ."'>";
if($w_metric == "kg")
{
echo r_nr2(calcFromKg($row['kg'])). $w_metric . "</a>";
$strXML .= "<set label='" . formatDate($row['date'], $dateformat) . "' value='" . $row['kg'] . "' tooltext='" . r_nr2(calcFromKg($row['kg'])). $w_metric . "{br}". formatDate($row['date'], $dateformat) ."{br}". $row['place'] ."' />";
if($row['url'] != "")
{
echo " <a href='" . $row['url'] . "' target='_blank'><img title=". translate('show_video') ." src='img/video.png' /></a>";
}
}
else
{
echo r_nr(calcFromKg($row['kg'])). $w_metric . "</a>";
$strXML .= "<set label='" . formatDate($row['date'], $dateformat) . "' value='" . $row['kg'] . "' tooltext='" . r_nr(calcFromKg($row['kg'])). $w_metric . "{br}". formatDate($row['date'], $dateformat) ."{br}". $row['place'] ."'/>";
if($row['url'] != "")
{
echo " <a href='" . $row['url'] . "' target='_blank'><img alt=title=". translate('show_video') ." title=". translate('show_video') ." src='img/video.png' /></a>";
}
}
echo "</td></tr>";
$i++;
$counter = $i;
}
}
$strXML .= "</chart>";
$check = $counter-1;
echo "</table></td>
<td valign='top' style='padding-left: 50px;'>
<table border='0'>
<tr>
<td>";
if($check >= 2)
{
while($row2 = mysql_fetch_array($result_pb))
{
echo translate('mycurrentpris') . ": <b>" . r_nr(calcFromKg($row2['kg'])). $w_metric . "</b> (" . formatDate($row2['date'], $dateformat) . ")";
$curpr = r_nr(calcFromKg($row2['kg']));
$curdate = $row2['date'];
}
echo "
</td>
</tr>";
echo "<tr>
<td>";
while($row3 = mysql_fetch_array($result_bpb))
{
echo translate('myfirstprwas') . ": <b>" . r_nr(calcFromKg($row3['kg'])). $w_metric . "</b> (" . formatDate($row3['date'], $dateformat) . ")";
$oldpr = r_nr(calcFromKg($row3['kg']));
$olddate = $row3['date'];
}
echo "
</td>
</tr>
<tr>
<td colspan='2'>";
$diff = $curpr-$oldpr;
$diff_pro = round((($curpr-$oldpr)/$oldpr*100), 2);
echo "<b>" . $diff. $w_metric . "/" . $diff_pro . "%</b> " . translate('increase') . " " . strtolower(translate('in')) . " ca. " . getHowLongAgo2($olddate, $curdate) . ".";
echo "
</td>
</tr>";
}
echo "</table>
</td>
</tr>
</table><br />";
if($check >= 2) //graph start
{
echo renderChart("Charts/Line.swf", "", $strXML, "".ucf(translate('myprogress'))."", 900, 400, false, true);
}
echo "<div class='fixed'>
</div>
</div>
</div>
<div class='fixed'>
</div>
<div id='footer'>
<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
<div align='center' id='copyright'>© " . translate('copyrightyear') . " " . translate('header_text'). " - " . translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
</div>";
exit;
}
else
{
echo translate('noresultshof');
echo "<div class='fixed'>
</div>
</div>
</div>
<div class='fixed'>
</div>
<div id='footer'>
<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
<div align='center' id='copyright'>© " . translate('copyrightyear') . " " . translate('header_text'). " - " . translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
</div>";
exit;
}
}
}
else
{
echo "<br /><br /><br /><br /><br /><br /><br /><br /><br />
<center><h2>" . translate('addanewtrainingtostart') . "</h2></center>";
}
?>
You are using get as a method now, so $_POST[‘select’] doesn’t exist anymore. It’s $_GET[‘select’] now.
And where does that <?=$url> in the link come from? You don’t have $url in the script you posted?
guido2004:
You are using get as a method now, so $_POST[‘select’] doesn’t exist anymore. It’s $_GET[‘select’] now.
And where does that <?=$url> in the link come from? You don’t have $url in the script you posted?
if(!checkSession())
{
function redirect($url)
{
?>
<script type="text/javascript">
{
window.location = "<?=$url?>";
}
</script>
<?php
}
redirect("index.php?action=login");
exit;
}
Maybe there’s a space missing after $url?
Anyway, I wouldn’t use the short hand version if I were you. I prefer:
window.location = "<?php echo $url; ?>";
guido2004:
Maybe there’s a space missing after $url?
Anyway, I wouldn’t use the short hand version if I were you. I prefer:
window.location = "<?php echo $url; ?>";
It happens the same thing…
What does the url look like now?
It blinks
index.php?select_exercise=2&reps=10&user_id=49&select=+Show+
before
%3C?=$url?%3E
returns and forbidden page …
Strange since i have decleared
<form method=“get” action=“index.php?action=profile&sub=stats_progress&id=<?php echo $USER_PROFILE->getId(); ?>&exid=<?php if(isset($_GET[‘select’])){ echo $ex_id2; } ?>&rep=<?php if(isset($_GET[‘select’])){ echo $nr_reps2; } ?>”>
So you used this
window.location = "<?php echo $url; ?>";
And the url still gives %3C?=$url?%3E?
Did you check the HTML code of the page? Find window.location and see what the code looks like exactly.