Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-24-2007, 01:59 PM Two Questions
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
First; I'm working on setting up a PhP program that allows the user to choose (using a checkbox), how many sides are on a die. Following this, there would be a "rand" for that, all on the same document. The following is my current progress:

Code:
<html>

<head>

<title>Checkbox Demo</title>

</head>

<body>

<?

print <<<HERE

chk4S: "$4S" <br>
chk6S: "$6S" <br>
<hr>

HERE;

if (!empty($4roll))
{
$4roll = rand(1,4);
print "You rolled a $4roll";
print "<br>";
} //end if

if (!empty($6roll))
{
$6roll = rand(1,6);
print "You rolled a $6roll";
print "<br>";
} //end if



?> 

<h1>Checkbox Demo</h1>

<h3>Demonstrates checkboxes</h3>


<h3>Please input the amount of sides of the die.</h3>
  

<form action ="<? php echo $_SERVER['PHP_SELF']; ?>">

<ul>

<li> <input type = "checkbox"
            name = "4roll"
             >  4-Sided Die
</li>
<li> <input type = "checkbox"
            name = "6roll"
            > 6-Sided Die
</li>


</ul>

<input type = "submit">


</form>

</body>
</html>
However I get the following error:

"Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/rbthrdso/public_html/chapter4/index.php on line 21"Anyone capable of assisting would be greatly appreciated.

And second. I'm also working on getting a program (in PhP), that can allow a user to pick and choose what options (IE: Font color, background color, etc) go into the generated HTML page.

Please and Thank You

Last edited by MGT-Evelath; 09-24-2007 at 02:04 PM..
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-24-2007, 02:02 PM Re: Two Questions
ablaye's Avatar
Ultra Talker

Posts: 437
Location: WebmasterGround.com
Trades: 5
You should have quotes around your print statement.

print <<<HERE
chk4S: $4S <br>
chk6S: $6S <br>
<hr>
HERE;
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
ablaye is offline
Reply With Quote
View Public Profile Visit ablaye's homepage!
 
Old 09-24-2007, 02:04 PM Re: Two Questions
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Ok; took care of the quotes. The error persists, but thanks for catching something that likely was next on the error list.
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 03:17 PM Re: Two Questions
Skilled Talker

Posts: 51
Trades: 0
I'm just now learning php myself, but I don't think you can start a variable with a number.
__________________
A bad Vista launch means 4 more years of IE6

Please login or register to view this content. Registration is FREE
Sandman420 is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 03:22 PM Re: Two Questions
Ultra Talker

Posts: 483
Trades: 0
Sandman420: good pick up. I didn't notice that but you are correct (as per http://php.net/variables , "A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.").

I would also suggest a couple of other 'improvements'. Your code is assuming that register_globals is on. You shouldn't assume that and so before:
if (!empty($4roll))

you should put:
$4roll = $_REQUEST['4roll'];
$6roll = $_REQUEST['6roll'];

(remembering to rename those variables to whatever the new variable names will be). That may help.

Also be aware that although '<?' obviously works for you here, you should use '<?php' instead as short_tags is being phased out.
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 04:30 PM Re: Two Questions
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Awesome; thanks for the info!

So would a HTML-page generator be very similar; however it would look something like:

Code:
<?php

if (!empty($bgred))
{
background-color: red;
}
?>
Or something different?

PS: The code for the die-rolling program works perfectly, thank you!
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 05:00 PM Re: Two Questions
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Alright, this is what I've got now:

Code:
<html>

<head>

<title>HTML Generator</title>

</head>

<body>

Select your background color:
<form>
<input type ="button"
       name ="bluebg"
       value ="Blue Background"
       onclick = "document.bgColor='#0000ff'">
<br>
<br>
<input type ="button"
       name ="redbg"
       value ="Red Background"
       onclick = "document.bgColor='ff0000'">
<br>
<br>
<input type ="button"
       name ="greenbg"
       value ="Green Background"
       onclick = "document.bgColor='00FF00'">
<br>
<br>
Select your font color:
<br>
<input type ="button"
       name ="redfont"
       value="Red Font"
       onclick = "document.fontColor='ff0000'">
<br>
<br>
</body>

</html>
However there is an error on the "if" statement. I don't see how I would go about assigning the background color, or font size as variables. Any assistance would be great =]

Quote:
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/rbthrdso/public_html/chap3-2/index.php on line 27

Last edited by MGT-Evelath; 09-24-2007 at 05:26 PM..
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 06:05 PM Re: Two Questions
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
You shouldn't start variables with numbers either??
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Two Questions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47785 seconds with 12 queries