Why doesn't my PHP code work?

Status
Not open for further replies.

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
I thought we get free PHP here, but all day codes that begin <? or <?PHP have either been warped on the website builder admin panel or the page itself, even when I tried to use the html editor and code paster. It won't even link as a script. Am I doing something wrong?

I'm just trying to use one PHP code only, rest of my site will probably just be basic HTML.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
1. Write the code locally and upload via cPanel File Manager or FTP

or

2. Use cPanel --> File Manager --> Edit or Code Editor
 

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
Ok, I've tried ALL of those and still no good. A well-written script in the WBAP will either be warped, vanished, have <-- --> inserted ruining it or will read only the HTML compenents and ignore everything else.

And the WBAP won't read linked PHP script (or at least not from this website since you don't seem to allow linking which I found out testing images, though I'm not sure where I can host a PHP script). I tested the code and it works fine on phpDesigner7.
 
Last edited:

Anna

I am just me
Staff member
Messages
11,750
Reaction score
581
Points
113
can you give an example of an url that does not work properly?
 

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
Just linking an image with <img src=""> works fine, but if it's in a php file it won't work. When I tried that in phpDesigner with an image I uploaded here I got a red X and alt text, so maybe that's why x10 won't link a code I uploaded here?

Here's a sample of the code, it's meant to retrieve the date and display an image that way:

<?PHP
date_default_timezone_set('UTC');
switch(date('m-d')) {
case '01-01':
case '01-02':
case '01-03':
case '01-04':
print '<img src="https://starka.x10hosting.com:2083/viewer/home%2fploinky/Lossless-circle-canny.png" alt="You should be seeing a white circle on a black background" />';
break;
// fallback image
default:
print '<img src="http://humanflowerproject.com/images/uploads/poi-gold-flower.jpg" alt="Image from a different site in case the other link is broken or messed up" />';
break;
}
?>

(https://starka.x10hosting.com:2083/viewer/home/ploinky/thasampel.php Also, the syntax parts don't highlight..)

LONG code if I want an image everyday, I know, but it's the only one I've found that does what I want and I'm new to PHP. BTW thanks for reading, guys.
 
Last edited:

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
I figured that, but I can't seem to find the raw URLs through file manager or right or left click..
 
Last edited:

masshuu

Head of the Geese
Community Support
Enemy of the State
Messages
2,293
Reaction score
50
Points
48
looking at it, thasampel.php and Lossless-circle-canny.png look like their in your root directory.
If you move them to public_html, you can use

year-of-the-sun.elementfx.com/thasampel.php
year-of-the-sun.elementfx.com/Lossless-circle-canny.png
 

Anna

I am just me
Staff member
Messages
11,750
Reaction score
581
Points
113
Image urls should always start with your main domain, or use a path relative to the document they are included in.

Also you should note that if you want to be able to view the file in the browser, you need to place it inside the directory public_html, same goes for the images.

Given the structure you currently have at /home/ploinky, the correct image url would be like
Code:
<img src="http://year-of-the-sun.elementfx.com/Lossless-circle-canny.png" />
if you move all files into the folder public_html
 

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
Ok, thasampel works now that I've moved it like you said, but it still won't link in the html editor or code paster when I use
<script type="text/javascript" src="myscript.php"></script> or <script type="php" src="myscript.php"></script> (though it doesn't seem to work in phpDesigner either..)

BTW yes I'm testing with thasampel.
 
Last edited:

masshuu

Head of the Geese
Community Support
Enemy of the State
Messages
2,293
Reaction score
50
Points
48
You may need to read up on php some more.
PHP is a language that is run serverside. Its output is then sent to the client, its output usually being html code. You can't directly have the html browser run php code as most do not support php.
 

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
I'm using Firefox 3.6.13 on Windows 7 (can anyone see php working on their computer?). Serverside, maybe I was thinking userside earlier. Is there a different coding system I could use? I tried HTML but date retrieval and scheduling doesn't seem to exist in it.

On the source page for Year-of-the-sun I see the php code, but on the page itself it's just 2 lines of broken text. On IExplorer I don't see any of the text on year-of-the-sun page or that the code has registered at all. Should I give up?
 
Last edited:

Anna

I am just me
Staff member
Messages
11,750
Reaction score
581
Points
113
You can not include a php script the same way you include a javascript, they work completely different.

Javascript is executed on the client side, ie in the browser window of the viewer.
PHP is executed server side and transformed to a html page for the client to view, on the fly.

To get php to work, it has to be interpreted server side, which would be what happens when you open the php page directly in the browser. Also all pages with php code to be executed must be saved as .php files.

This might be of use along the way of learning more: http://tuxradar.com/practicalphp
 
Last edited:

koonoe49

New Member
Messages
8
Reaction score
0
Points
0
Oh, and that would explain then why the thasampel.php link itself works, but not on the page.. So maybe I should have my homepage redirect to something like /welcome.php ? And I'm guessing this site doesn't allow javascript?

Thanks for the text. I've got a bunch of them, I'm still considering myself lucky for getting something out of this one about time: http://php.net/manual/en/function.date.php
 

masshuu

Head of the Geese
Community Support
Enemy of the State
Messages
2,293
Reaction score
50
Points
48
If you want clientside, you will need to use javascript. Its the only serverside scripting language that most browsers support.
 
Status
Not open for further replies.
Top