Image

Imagedevolve_absolve wrote in Imagephp 😯confused

Listens: Down - Underneath Everything

Yet another slight flaw... I hope

First off, I'd like to thank everyone who posted on my earlier question. You guys all kick ass and it's working beautifully now. I just have to go through and correct the issues that have been raised once I have things fully working (namely the "select * " bits :P )

However, I have a small problem now, and I know it's a small problem. I am trying to create a diceroller which effectively takes the persons name, the number of dice they wish to roll, and what they are rolling for (note: I am aware of my engineering flaws in this code, and will fix them at a later date before I actually publish these things :) )




function droller($dice, $name, $action) {
echo "$name rolls $dice dice for $action: ";
$i=0;
while ($i < $dice) {
srand((double)microtime()*1000000);
$randval = rand(1, 10);
echo "$randval, ";
++$i;
}
}


var=$res;
$res=droller($dnum, $name, $action);
echo "$res
";


$username="xxx";
$password="xxx";
$database="xxx";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO diceroller VALUES ('$res','')";
mysql_query($query);

mysql_close();



mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM diceroller";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$results=mysql_result($result,$i,"results");

echo "$results
";

++$i;
}





OK, so that's the code. What I am trying to do is:

  1. take the loop and random number grabber up the top

  2. formulate it in to a single string

  3. set a variable ($res) to that string

  4. insert it in to the database

  5. finally print out all the current values held within that database



Currently I am getting a null return from the database, so I can only assume that nothing is being inserted in to the fields, though I can't see anything wrong with the coding as such.

Any idea of where I am going wrong would be great.

and again, Thanks for the help last time. Frustration level has definitely lowered ^_^

EDIT: Actually, the error I am now getting is Parse error: parse error in /home/cameron/public_html/roller1.php on line 47 which would be the var=$res;