PDA

View Full Version : Creating Bra Size Calculator - form connecting to DB



cvwd
11-28-2011, 05:01 PM
Hi Guys

Could do with a bit of help here.

I am using osCmax v2.5 RC2

I have created a bra size calculator and tested it on another site and it works perfectly but when trying to add it to oscmax I am having issues.

I have created a table containing under bust and bust measurements and a result field

example

id band bust result
1 70 84 14/b
2 75 84 16/b


I have added the code to its own side box content and also to the index_default.tpl and neither work, I am assuming it is not connecting to the database.

My Code


<?

if (!$act)
{
?>

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type=hidden name=act value=search>
<label>Band
<input type="text" name="band" id="band" />
</label>
<label>Bust
<input type="text" name="bust" id="bust" />
</label>
<label>Submit
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
<label>Result
<input type="text" name="result" id="result" />
</label>
</form>

<?
}

if ($act)
{
$sql_query = ("SELECT * FROM `bra_calculator` WHERE `band` = '$band' AND bust = '$bust' LIMIT 1");
//store the SQL query in the result variable
$result = mysql_query($sql_query) or die('Query Error:<br />'.$sql_query.'<br /><br />'.mysql_error());
if(mysql_num_rows($result))
{
//output as long as there are still available fields
?><table><?
while($row = mysql_fetch_row($result))
{
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type=hidden name=act value=search>
<label>Band
<input type="text" name="band" id="band" />
</label>
<label>Bust
<input type="text" name="bust" id="bust" />
</label>
<label>Submit
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
<label>Result
<input type="text" name="result" id="result" value=<?echo "$row[1]";?>/>
</label>
</form>
<?
}
?></table>
<?
}
//if no fields exist
else
{
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type=hidden name=act value=search>
<label>Band
<input type="text" name="band" id="band" />
</label>
<label>Bust
<input type="text" name="bust" id="bust" />
</label>
<label>Submit
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
<label>Result
<input type="text" name="result" id="result" value="NA"/>
</label>
</form>
<?
}
?>
<?
}
?>


After getting this to work I would hope to then be able to use ajax to have it show the result without a refresh.

cvwd
11-28-2011, 07:52 PM
I have come up with a different method and it now retrieves the relevant data however if there is no data it does nothing and I would like to have it display N/A

I have tried adding if elses but none work.


<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD=get>
<input type="text" name="band" value="<?php echo $_GET['band']; ?>" />
<input type="text" name="bust" value="<?php echo $_GET['bust']; ?>" />

<INPUT TYPE=submit VALUE="Calculate">
</FORM>


<?php
$band = $_GET['band'];
$bust = $_GET['bust'];

$query = sprintf("SELECT size FROM bra_calculator WHERE band='%s' AND bust='%s'", mysql_real_escape_string($band), mysql_real_escape_string($bust));
$result = mysql_query($query);

if (!$result) {
echo "no";
}
else {
while ($row = mysql_fetch_assoc($result)) {
echo $row['size'];
}
}
mysql_free_result($result);
?>

Any help would be much appreciated

pgmarshall
11-29-2011, 04:44 AM
Would it not be a lot easier to simply use Javascript to do this? Afterall, you only have 2 parameters and need an instant restult ...Just a thought!

pgmarshall
11-29-2011, 04:55 AM
And 5 seconds on google finds you JavaScript Bra Size Calculator - Ajaxian (http://ajaxian.com/archives/javascript-bra-size-calculator)

niallb
11-29-2011, 09:25 AM
i was going to post a similar request for a condom size calculator, then I found out that only 2 sizes are made, large and huge

cvwd
12-11-2011, 08:15 PM
The javascript ajax ones werent what I needed as my client has more specific needs. I have since gotten this to work.