Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with PHP Variables and HTML Sytax... 3

Status
Not open for further replies.

hneal98

Programmer
Aug 13, 2002
1,637
US
Hi,

I am lost. I need to know if something like the following is possible:

Code:
<?php 	
	
if($flamt>0) {
"<img src='[URL unfurl="true"]http://www.mydomain.com/affiliate/scripts/sale.php?TotalCost="{$flamt}"&ProductID=001'[/URL] width=1 height=1>";
}
if($blamt>0){
echo "<img src='[URL unfurl="true"]http://www.mydomain.com/affiliate/scripts/sale.php?TotalCost="{$blamt}"&ProductID=002'[/URL] width=1 height=1>";
}
?>


1st, I am having problems with syntax errors and
2nd, The variables are created and initiated in a file that calls this file. The variables are used once, but it seems as soon as they are used, they are no longer defined, and so I get an error for that as well.

I would appreciate any help I can get.

Thanks in advance.
 
Hi

hneal98 said:
1st, I am having problems with syntax errors and
Then why not posted the error message ?
hneal98 said:
2nd, The variables are created and initiated in a file that calls this file. The variables are used once, but it seems as soon as they are used, they are no longer defined, and so I get an error for that as well.
Plain wrong.

Just correct your syntax error : remove those quotes around the variable inside the string. ( You could remove the braces ( {} ) too, as they are useless in this case. )


Feherke.
 
Are you having a bad day? I did not post the syntax error because as a programmer in other languages, I know that if someone is asking "if something is possible", does not require error messages.

I have removed the {}, and put other things in there, but nothing has worked. The variables are not reinitializing because of syntax errors.

If you don't know about something, then don't post.

Thanks
 
1. If you are having problems with syntax errors and are asking for help, its usually a good idea to post the errors.

Second: Your strings and variable concatenation are very very wrong.


3rd: With the code you posted there is absolutely no way to know what you are doing or why your variables loose their values.

Corrected Code:

Code:
[gray]if($flamt>0) {
[red]echo[/red]"<img src='[URL unfurl="true"]http://www.mydomain.com/affiliate/scripts/sale.php?TotalCost="[/URL][COLOR=white red].[/color]$flamt[COLOR=white red].[/color]"&ProductID=001' width=1 height=1>";
}
if($blamt>0){
echo "<img src='[URL unfurl="true"]http://www.mydomain.com/affiliate/scripts/sale.php?TotalCost="[/URL][COLOR=white red].[/color]$blamt[COLOR=white red].[/color]"&ProductID=002' width=1 height=1>";
}[/gray]

And finally if you are asking whether you can use variables in an included script that were defined in the including script, then the answer is yes.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
@hneal98

I know you are experienced in these forums. Thus I assume you know how to review a person's activity and the like. Had you checked, you would know as I do that Feherke is one of the most helpful contributors on this whole site. His experience is immensely valued in many many fora. This one included.

In the years that I have participated here I have never known feherke's advice to be off point or sub-par. His advice, in this case, was on point. If you want our help then it is very useful to post the precise error you get. I very much doubt whether you would have been happy with a glib 'yes' in response to your question
.... is possible?

It would have been a simple thing to point out that you were either not breaking out of php tags or not using echo. But different people have views as to whether doing that would help you in the long run. Feherke's advice to lose the quotes around the variable (and optionally the braces) would have cured those syntax errors and would then have given you a nice error about the lack of a function call before the string. This you could have easily cured on your own as we know that in the other posts you have made you have been able to use echo statements adequately.

as to feherke's statement
plain wrong
. Of course he's absolutely right. no interpreted language would allow its variables to be unset simply because they had once been used. That's just common sense.

I won't tell you what to do. But perhaps it might have been better to consider feherke's advice in the literal sense and just try it in the spirit in which it was intended.
 
I really do appreciate everyone's help. What I don't appreciate is attitude. The first statement made was this:

Then why not posted the error message ?

That tells me attitude. If I were responding, I would say, "Can you please post any error messages you are receiving?"

People have feelings and already having a lack of understanding of PHP and feeling stupid, we don't need attitude.

I apologize for getting everyone riled up, but when I have helped people on this forum in the past, I have ALWAYS tried to be polite and understand that they may be having frustrations.

With that said, again, I really do appreciate all the help I personally have received.
 
I apologize for offending anyone on this forum. I appreciate any and all help. Just don't make me look stupider than I already feel.

I am new to PHP, not programming in general.

Here is where I am running into problems now. As I mentioned earlier, It seems as though the variables are re-initialized after their first use. However, the problem seems to be more with the if statements.

Here are the errors:

Notice: Undefined variable: flamt in /home/users/f/footlog/public_html/store/email.php on line 115

Notice: Undefined variable: blamt in /home/users/f/footlog/public_html/store/email.php on line 118

Here are the lines they refer to:

Code:
<?php 
if($flamt>0) {
echo "<img src='[URL unfurl="true"]http://www.mydomain.com/affiliate/scripts/sale.php?TotalCost=".$flamt."&ProductID=001'[/URL] width=1 height=1>";
}
if($blamt>0){
echo "<img src='[URL unfurl="true"]http://www.mydomain.com/affiliate/scripts/sale.php?TotalCost=".$blamt."&ProductID=002'[/URL] width=1 height=1>";
}
?>

Lines 115 and 118 are the If($flamt>0) and If($blamt>0)

These variables are used in other areas in the code with no problems. Am I doing something wrong with the If Statements?

Thanks again,

Harvard
 
Thanks for your response. No, they are just within the <?php ?> in the file that calls this one. Then this file reads those variables from it.

I added a piece of code and it seemed to make everything ok; although I can't explain why. the code I added is
Code:
if (isset($variable)){}

I encapsulated the other 'if' statements code above within the {} and it seems to be working ok now.

If you have an idea why, I would love to hear it.

Thanks again for your reply.

 
@hneal98
bear in mind please that not everyone is a native English speaker. Feherke's english is excellent but he is not a native speaker. I am bilingual (and speak several others to a smaller degree) and I know from this that what appears curt in one language is fully normal in another.

with php error messages, you should view the line number as a guide, not an absolute. this is not because php simply estimates the line number, but because it's view of where the error occurs is not quite the same as where you or I would consider the error to have occurred.

php Notices are NOT errors. Nor are they warnings. treat them as simply advisories. Good to get rid of them before launching to production but not totally necessary. when you move to production code you set display_errors to OFF and change error reporting and logging to a value that suits you. that means that your code will fail to a blank or partially blank page if you have fatal (syntax and other) errors; but that notices and warnings will not interrupt the user experience. always keep them showing for debugging and dev platforms: the feedback is invaluable.

In your case the line number is accurate and the notice occurs because you have not declared/instantiated/filled the variable prior to making a reference to it. That is why encapsulating in an if(isset()) works for you.

so your real question might now be why these variables are not being instantiated.

If you are new to PHP then you might not be familiar yet with the manual. In my experience the manual is the best of any language I have ever coded in.
 
Your IF statement is checking to see if that they are indeed set before attempting to use them. The question still remains as to where they are actually instantiated before being used.

I'm thinking you have a conditional statement that decides whether to instantiate them or not. But you attempt to use them regardless of their state.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
That is a possibility. I have looked in the php file that calls this one and at the top, it looks like the variables are just used, but I don't see where they are instantiated.

Can php instantiate them by just assigning a value to them?

Thanks
 
Yes. Assigning a value to a variable instantiates it.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Ok. Then it is done in the file that calls this file and then passed to this file for use in the Thank You page.

Thanks again for your help.
 
but as you have seen, the variables aren't being filled. do you want to post the full code of the files or can you take it from here?
 
Actually, they are being filled. The problem I had was after their first use, it seemed they were reinitialized until I put the if(isset... statement mentioned above. Now they seem to work fine. Again, I can't explain why other than what vacunita has stated above.

Anyway, thanks for checking. I appreciate it.
 
Well, I just wanted to give everyone an update. My code is working great now. As it turns out my problem was due to an ID10T error. (Idiot) :-(

I did not realize that the variables were case sensitive. In the previous file, it used $flAmt and in my code I was using $flamt, so, it kept giving me the error that the variable was not defined.

I just wanted to thank everyone for your support on this. You gave me some great advice.

Thanks again,

Harvard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top