Page 1 of 1

Operator Problem

Posted: Mon May 23, 2005 9:57 am
by Hammer136
Hi

I have a problem in which i have a table with some numbers in it and i wish to multiply the number in the table by a number given in from a form so i came up with this

Code: Select all

$multiplier[priv] = "select Multiplier from Strength where Unit = Private";
$multiplier[cnsrpt] = "select Multiplier from Strength where Unit = Conscript";

$priv = '".$_POST["private"]."';
$cnsrpt = '".$_POST["conscript"]."';

$score[att] = ($multiplier[priv] * $priv);
$score[def] = ($multiplier[cnsrpt] * $cnsrpt);

echo "$score[def]";

?>
This however when i run it with the html always gives me an answer of 0.

Any suggestions welcome

Thanks
Hammer

Posted: Mon May 23, 2005 9:58 am
by JayBird
where do you execute the queries?

Posted: Mon May 23, 2005 10:03 am
by Wayne
Why are you trying to multiply a integer by a string?

Code: Select all

$scoreї&quote;def&quote;] = ($multiplierї&quote;cnsrpt&quote;] * $cnsrpt);

Code: Select all

<?
$multiplier["priv"] = "select Multiplier from Strength where Unit = Private";
$multiplier["cnsrpt"] = "select Multiplier from Strength where Unit = Conscript"; 
$priv = $_POST["private"];
$cnsrpt = $_POST["conscript"]; 
$score["att"] = ($multiplier["priv"] * $priv);
$score["def"] = ($multiplier["cnsrpt"] * $cnsrpt); 
echo $score["def"]; 
?>
also make sure you are using a POST form not a GET form.

Posted: Mon May 23, 2005 10:10 am
by Hammer136
Thanx but what uve just given me gives out the same results.

It could be the values in the tables but im sure ive got those right

Im multiplying a number which is entered in from a form by a number in a table. Is there an easier way to do this?

Thanx

Posted: Mon May 23, 2005 10:14 am
by JayBird
please tell me where the execution of the querioes occur.

At the moment, you code makes no sense

Posted: Mon May 23, 2005 10:19 am
by Hammer136
The code is executed from a html file with the code

Code: Select all

<html>
<head>
</head>

<body>

<form action="battle.php" method="post">
Privates: <input type="text" name="private" size="20"><br>
Conscripts: <input type="text" name="conscript" size="20"><br>
<input type="submit" value="Log In">
</form>

</body>
</html>
Is this what you mean?

Posted: Mon May 23, 2005 10:25 am
by JayBird
perhaps i am not being clear!?

I am guessing that this...

Code: Select all

select Multiplier from Strength where Unit = Private
...is as query and you are returning some results from a database.

A not point do you execute that query to return any information from the table in your database.

Posted: Mon May 23, 2005 10:28 am
by Hammer136
Oh right i get you. Wat do i need to add to execute it?

Posted: Mon May 23, 2005 10:42 am
by JayBird
You really should learn the basics of PHP and MySQL

Heres a starter http://uk2.php.net/manual/en/function.mysql-result.php