PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dstefani
Forum Contributor
Posts: 140 Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA
Post
by dstefani » Fri Jan 09, 2004 4:44 pm
Hello,
The following code will not print to the browser using a variable to hold it until returning it from a function. It will output if I use print instead of a variable.
I'm trying not to print directly from a function as a practice.
The weird thing is, this method works fine in other functions in the same file. This problem started with the last function I wrote. The code was cut and pasted from earlier functions, but I don't see why that should matter. When I view LF's they look the same as the functions that work. I'm stumped.
TIA,
- D
Code: Select all
$htmlout = <<<HTML
<h2>Accounts: Insert Record</h2>
<h3>$db_cust_company: $db_cust_fname $db_cust_lname</h3>
<form name="frm_accounts" action="$page" method="POST">
<input type="hidden" name="view" value="acc_insert" />
<input type="hidden" name="cust_id" value="$cust_id" />
<table id="ns_input">
<tr><td class="right" nowrap="1">Webmaster email:</td><td class="field">
<input type="text" size="40" name="acc_webmaster_email" value="acc_webmaster_email /></td></tr>
<tr><td class="right">Domain name:</td><td class="field"><input type="text" size="40" name="dom_name" value="dom_name" /></td></tr>
<tr><td class="right">Hostname:</td><td class="field"><input type="text" size="40" name="acc_hostname" /></td></tr>
<tr><td class="right">Username:</td><td class="field"><input type="text" size="40" name="acc_username" /></td></tr>
<tr><td class="right">Password:</td><td class="field"><input type="text" size="40" name="acc_password" /></td></tr>
<tr><td class="right">IP address:</td><td class="field"><input type="text" size="40" name="dom_ip" /></td></tr>
<tr><td class="right" nowrap="nowrap">Primary Nameserver:</td>
<td class="field">
HTML;
$sql = "SELECT * FROM nameservers";
$results = mysql_query($sql, $dblink);
$htmlout .= "<select name="prim_ns_id" size="1">\n";
while($rows = mysql_fetch_assoc($results))
{
$db_ns_id = $rowsї'ns_id'];
$db_ns_name = $rowsї'ns_name'];
$db_ns_ip = $rowsї'ns_ip'];
$htmlout .= "<option value="$db_ns_id">$db_ns_name</option>\n";
}
$htmlout .= "</select>\n</td></tr>";
$htmlout .= "<tr><td class="right" nowrap=\nowrap">Secondary Nameserver:</td><td>\n";
$htmlout .= "<select name="sec_ns_id">\n";
$sql = "SELECT * FROM nameservers";
$results = mysql_query($sql, $dblink);
while($rows = mysql_fetch_assoc($results))
{
$db_ns_id = $rowsї'ns_id'];
$db_ns_name = $rowsї'ns_name'];
$db_ns_ip = $rowsї'ns_ip'];
$htmlout .= "<option value="$db_ns_id">$db_ns_name</option>\n";
}
$htmlout .= "</select>\n</td></tr>";
$htmlout .= <<<HTML2
<tr><td class="right">POP incoming email::</td><td class="field"><input type="text" name="acc_pop" size="40" /></td></tr>
<tr><td class="right">SMTP outgoing email:</td><td class="field"><input type="text" name="acc_smtp" size="40" /></td></tr>
<tr><td class="right">Frontpage:</td><td class="field"><input type="checkbox" name="acc_frontpage" value="1" /></td></tr>
<tr><td class="right">Autoresponder:</td><td class="field"><input type="checkbox" name="acc_autoresp" value="1" /></td></tr>
<tr><td class="right">Database:</td><td class="field"><input type="checkbox" name="acc_database" value="1" /></td></tr>
<tr><td class="right">SSL:</td><td class="field"><input type="checkbox" name="acc_ssl" value="1" /></td></tr>
<tr><td class="right">Email-filter:</td><td class="field"><input type="checkbox" name="acc_email_filter" value="1" /></td></tr>
<tr><td class="rightT">Notes:</td><td class="field"><textarea cols="45" rows="15" name="acc_notes"></textarea></td></tr>
<tr><td class="center" colspan=2><input type="submit" class="submit" value="Insert Record"></td></tr>
</table>
HTML2;
return $htmlout;
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Fri Jan 09, 2004 8:14 pm
Probably everyone was waiting for
me to answer it eh?
Anyhow:
You'll need a space before the HTML2.
-Nay
dstefani
Forum Contributor
Posts: 140 Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA
Post
by dstefani » Fri Jan 09, 2004 8:38 pm
Thanks for replying, but what exactly are you saying to do?
Here is another snippet that works fine, I don't see a difference:
Code: Select all
<?php
$output .= <<<HTML2
<tr><td class="right">POP incoming email:</td><td class="field"><input type="text" name="acc_pop" size="40" /></td></tr>
<tr><td class="right">SMTP outgoing email:</td><td class="field"><input type="text" name="acc_smtp" size="40" /></td></tr>
<tr><td class="right">Frontpage:</td><td class="field"><input type="checkbox" name="acc_frontpage" value="1" /></td></tr>
<tr><td class="right">Autoresponder:</td><td class="field"><input type="checkbox" name="acc_autoresp" value="1" /></td></tr>
<tr><td class="right">Database:</td><td class="field"><input type="checkbox" name="acc_database" value="1" /></td></tr>
<tr><td class="right">SSL:</td><td class="field"><input type="checkbox" name="acc_ssl" value="1" /></td></tr>
<tr><td class="right">Email-filter:</td><td class="field"><input type="checkbox" name="acc_email_filter" value="1" /></td></tr>
<tr><td class="rightT">Notes:</td><td class="field"><textarea cols="45" rows="15" name="acc_notes"></textarea></td></tr>
<tr><td class="center" colspan=2><input type="submit" class="submit" value="Insert Record"></td></tr>
</table>
HTML2;
?>
And the code that's broken from a different function:
Code: Select all
<?php
$htmlout .= <<<HTML
<h2>Accounts: Insert Record</h2>
<h3>$db_cust_company: $db_cust_fname $db_cust_lname</h3>
<form name="frm_accounts" action="$page" method="POST">
<input type="hidden" name="view" value="acc_update" />
<input type="hidden" name="cust_id" value="$cust_id" />
<table id="ns_input">
<tr><td class="right" nowrap="1">Webmaster email:</td><td class="field">
<input type="text" size="40" name="acc_webmaster_email" value="$db_acc_webmaster_email" /></td></tr>
<tr><td class="right">Domain name:</td><td class="field">
<input type="text" size="40" name="dom_name" value="$db_dom_name" /></td></tr>
<tr><td class="right">Hostname:</td><td class="field">
<input type="text" size="40" name="acc_hostname" value="$db_acc_hostname" /></td></tr>
<tr><td class="right">Username:</td><td class="field">
<input type="text" size="40" name="acc_username" value="$db_acc_username" /></td></tr>
<tr><td class="right">Password:</td><td class="field">
<input type="text" size="40" name="acc_password" value="$db_acc_password" /></td></tr>
<tr><td class="right">IP address:</td><td class="field">
<input type="text" size="40" name="dom_ip" value="$db_dom_ip" /></td></tr>
<tr><td class="right" nowrap="nowrap">Primary Nameserver:</td>
<td class="field">
HTML;
?>
For the time being I used print to get it working, but I would really like to fix this. Am I looking right at the problem and just not seeing it?
Thanks,
- D
Fataqui
Forum Newbie
Posts: 10 Joined: Fri Jan 09, 2004 7:47 pm
Post
by Fataqui » Fri Jan 09, 2004 8:51 pm
Hi
On this line.....
$htmlout .= <<<HTML
Be sure you have no ('white spaces') after the '<<<HTML(here) < no white spaces (here)'
If you have error reporting on you would see you have a T_SL error
A good idea is to be sure 'NO' lines have trailing white spaces!
F!
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Fri Jan 09, 2004 8:54 pm
I meant:
$htmlout = <<< HTML2
HTML2;
as in:
$this[space]=[space]<<<[space]HTML2[NO-SPACE]
[NO-SPACE]HTML2;[NO-SPACE]
-Nay
dstefani
Forum Contributor
Posts: 140 Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA
Post
by dstefani » Fri Jan 09, 2004 9:37 pm
Putting a space <<<[space]HTML is not correct syntax. If it's correct, then I can't find your way in any documentation. Please provide a link.
And there is no whitespace after the <<<HTML. But thank you for your reply's.
- D
dstefani
Forum Contributor
Posts: 140 Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA
Post
by dstefani » Fri Jan 09, 2004 9:45 pm
Just to be clear, ...
It works with print <<<HTML
but not with $htmlout = <<<HTML
If you wouldn't mind, please look at the code once more and tell me if I'm missing anything. There are no white spaces and if I use print it works, Arg!
Thanks
Code: Select all
<?php
$htmlout = <<<HTML
<h2>Accounts: Insert Record</h2>
<h3>$db_cust_company: $db_cust_fname $db_cust_lname</h3>
<form name="frm_accounts" action="$page" method="POST">
<input type="hidden" name="view" value="acc_update" />
<input type="hidden" name="cust_id" value="$cust_id" />
<table id="ns_input">
<tr><td class="right" nowrap="1">Webmaster email:</td><td class="field">
<input type="text" size="40" name="acc_webmaster_email" value="$db_acc_webmaster_email" /></td></tr>
<tr><td class="right">Domain name:</td><td class="field">
<input type="text" size="40" name="dom_name" value="$db_dom_name" /></td></tr>
<tr><td class="right">Hostname:</td><td class="field">
<input type="text" size="40" name="acc_hostname" value="$db_acc_hostname" /></td></tr>
<tr><td class="right">Username:</td><td class="field">
<input type="text" size="40" name="acc_username" value="$db_acc_username" /></td></tr>
<tr><td class="right">Password:</td><td class="field">
<input type="text" size="40" name="acc_password" value="$db_acc_password" /></td></tr>
<tr><td class="right">IP address:</td><td class="field">
<input type="text" size="40" name="dom_ip" value="$db_dom_ip" /></td></tr>
<tr><td class="right" nowrap="nowrap">Primary Nameserver:</td>
<td class="field">
HTML;
?>
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Fri Jan 09, 2004 10:27 pm
I'm wondering why myself, I've always used plentiful of heredoc in all my scripts, this has never happened. Here's a snippet one of my files:
Code: Select all
COMMENT;
} // end while
} // end else
// if the cookie for the poster's URL is not set
if(!isset($_COOKIE['site']) || empty($_COOKIE['site'])) {
$comment_site = "http://";
} else {
$comment_site = $_COOKIE['site'];
}
// add the comments from to the output
$output .= <<< FORM
<h1 class="content_title">Post Comment</h1>
<form id="comment" action="../comments/" method="post" onsubmit="return checkForm('comment')">
<div>
<input type="hidden" name="submitted" value="submitted" class="required" />
<input type="hidden" name="news_id" value="{$_GET['news_id']}" class="required" />
Name *: <input type="text" value="{$_COOKIE['name']}" name="name" class="required" size="30" /><br />
E-mail: <input type="text" value="{$_COOKIE['email']}" name="email" class="email" size="30" /><br />
Website: <input type="text" value="$comment_site" name="site" class="url" size="30" /><br />
Comment *:<br />
<textarea name="comment" class="required" rows="30" cols="20" class="required" style="width:300px;height:100px;"></textarea><br />
<input type="submit" value="Submit" /><br />
* are required
</div>
</form>
<div class="spacer"></div>
FORM;
-Nay
Sarok
Forum Newbie
Posts: 9 Joined: Fri Jan 02, 2004 12:20 pm
Location: Oslo, Norway
Post
by Sarok » Fri Jan 09, 2004 10:34 pm
what error messages are you getting? maybe a little easier to help then.. turn error reporting to E_ALL. maybe it helps..
dstefani
Forum Contributor
Posts: 140 Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA
Post
by dstefani » Fri Jan 09, 2004 11:00 pm
Errors are set to E_ALL by default, I haven't changed them.
The space doesn't break the code, but if I replace print with the variable the ouput dissapears. I'm going write this function again, testing my output a few lines at a time. I'll post again when I fix it.
Thanks for your help.
- D