Shout Box

richm8026

New Member
Messages
138
Reaction score
0
Points
0
I am going to insert some HTML Codes, can anybody here help with the PHP Scripts?

Code:
<table style="width: 40%; background-color: #FFF" align="right">

<tr>

<td valign="top">

<p class="style1">Shout Box</p>

<form method="post" action="">

<p>UserName: <input type="text" id="username" value="Guest and/or username" /></p>
<p>Message:<input type="text" id="message" value="Your Message Here" /></p> <br />
<p><input type="submit" id="submit" value="Submit" size="10" /></p>

<textarea wrap="soft" readonly="readonly" id="text">

</textarea>

</form>


</td>

</tr>

</table>
Thanks for the help
 

quantum1

New Member
Messages
68
Reaction score
0
Points
0
<?php
// define function that will output text with dos newlines so that view
// source will show human readable html; f_say will be used in place of
// php echo statement when generating html
function f_say($text)
{
echo $text."\r\n";
}

f_say("<table style=\"width: 40%; background-color: #FFF\" align=\"right\">");
f_say("<tr>");
f_say("<td valign=\"top\">");
f_say("<p class=\"style1\">Shout Box</p>");
f_say("<form method=\"post\" action=\"\">");
f_say("<p>UserName: <input type=\"text\" id=\"username\" value=\"Guest and/or username\" /></p>");
f_say("<p>Message:<input type=\"text\" id=\"message\" value=\"Your Message Here\" /></p> <br />");
f_say("<p><input type=\"submit\" id=\"submit\" value=\"Submit\" size=\"10\" /></p>");
f_say("<textarea wrap=\"soft\" readonly=\"readonly\" id=\"text\">");
f_say("</textarea>");
f_say("</form>");
f_say("</td>");
f_say("</tr>");
f_say("</table>");
?>
 

richm8026

New Member
Messages
138
Reaction score
0
Points
0
Hmm, I must have goofed up, it didn't work

am I supposed to put the table stuff f_say in the <body> </body> sections?
 
Last edited:

quantum1

New Member
Messages
68
Reaction score
0
Points
0
No problem. The double quotes that are actually part of you HTML are escaped with a backslash to indicate that we actually want to output a double quote character. If you use single quotes in your HTML you would not have to escape them. However, variable handling in PHP is different inside double quotes versus single quotes. If you are new to PHP and are not using PHP variables yet as part of building your HTML (that is, you are just using PHP to create straight non-changing HTML output) then I would use single quotes. That way it would look like below, without the need for escape backslashes:

<?php
// define function that will output text with dos newlines so that view
// source will show human readable html; f_say will be used in place of
// php echo statement when generating html
function f_say($text)
{
echo $text."\r\n";
}

f_say("<table style='width: 40%; background-color: #FFF' align='right'>");
f_say("<tr>");
f_say("<td valign='top'>");
f_say("<p class='style1'>Shout Box</p>");
f_say("<form method='post' action=''>");
f_say("<p>UserName: <input type='text' id='username' value='Guest and/or username' /></p>");
f_say("<p>Message:<input type='text' id='message' value='Your Message Here' /></p> <br />");
f_say("<p><input type='submit' id='submit' value='Submit' size='10' /></p>");
f_say("<textarea wrap='soft' readonly='readonly' id='text'>");
f_say("</textarea>");
f_say("</form>");
f_say("</td>");
f_say("</tr>");
f_say("</table>");
?>
 

richm8026

New Member
Messages
138
Reaction score
0
Points
0
Thanks, it didn't work, maybe I can just use JavaScript for that, not sure if I can though, I do want it to save all of the messages that way people who sign on later that day can see what everybody has said, I would have to write to a file I guess, so, I would have to use PHP, I'll learn it eventually, and yes, I am new to PHP, I am not sure if I keep the PHP Scripts above the <!doctype> or not, or if I am supposed to keep the echo part in there, or move that part between the <textarea> area.... So, for now, I'll just work on the rest of the site. Thanks for your time.. :)
 

quantum1

New Member
Messages
68
Reaction score
0
Points
0
Sorry! I responded without reading your post about it not working. You can use PHP anywhere in your HTML. Instead of creating a *.HTM or *.HTML file extension create a *.PHP file extension and then you can put plain HTML or a mixture of HTML and PHP or just straight PHP in that file. It's just that you create the HTML output using the PHP echo command (or in my case a function that then uses echo). You would then point your browser to myfile.php and the server would run php against your file. At that time the PHP program would generate the HTML to go back to the browser. Since PHP is in charge in a PHP scenario, you can use PHP to "echo" back to the browser the HTML needed for your web page. You can visit www.w3schools.com to get free training and information on HTML, PHP, Javascript and much more. They have examples that will probably answer your questions. PHP allows you to generate dynamic HTML, that is, you can build HTML on the fly that changes as you need it to. The browser will get just HTML (or HTML with javascript, depending on what your generate with your PHP).
 
Top