I've been working on some code and tested it on localhost, everything works fine, but when i upload it to my server it doesn't work beyond my php tags. No errors are showing either. I have checked both php versions and on localhost i run version 5.4.7 and on server it's version 5.3.21. Maybe this is causing the problem? Is there something I should look for in the phpinfo()? Am I missing something in my code?
Here is the code:
<!DOCTYPE html>
<?php phpinfo(); ?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<meta charset="utf-8">
<style>
body { background:black;}
.toggle { display:none; }
p {
width:570px;
text-align:justify;
color:#686868;
font-family:Georgia, serif;
}
h2 { color:black; }
button { background:#686868;
border:none;
font-family:Georgia, serif;
width:570px;
}
</style>
</head>
<body>
<?php
include('sql.php');
$i = 0;
while($i < count($rows)) {
echo "
<div>
<button class='trigger'>
<table width='100%'>
<tr>
<td width='20%'><img src='http://localhost/app-side/Icons/bar_icon.png' />
</td>
<td width='80%'><h2>{$rows[$i]['titel']} </h2></td>
</tr>
</table>
</button>
<div class='toggle'>
<p>
{$rows[$i]['info']}
</p>
</div>
</div>";
$i++;
}?>
</body>
<script>
$('.trigger').click(function() {
$(this).siblings('.toggle').slideToggle('fast');
});
</script>
</html>
When i run it, it shows a black background (as it's suppose to) but everything beyond my php starting tag gets cut off.
I have also tried to force my while loop to loop 10 times and also removed the parts where it's getting data from my database to see if it was a mysql related problem. Which I can conclude it's not.
The following line is the problem:
<img src='http://localhost/app-side/Icons/bar_icon.png
The image cannot being loaded as localhost refers to the local computer of the client (where the browser runs) not to your server. Usually such urls in websites are considered malicious ;)
A workaround to make it work on both localhost and server would be to use an relative path. This can be relative to your document or relative to the DOCUMENT_ROOT of your server. I've used the second approach as I don't know the location of your php file on server.
Solution with link relative to DOCUMENT_ROOT:
Replace:
<img src='http://localhost/app-side/Icons/bar_icon.png
by
<img src='/app-side/Icons/bar_icon.png
The only thing that I can assume is that $rows is empty and hence the following code does not get run:
// count($rows) could be equal to 0
while($i < count($rows)) { // this condition becomes false in that case
echo "
<div>
<button class='trigger'>
<table width='100%'>
<tr>
<td width='20%'><img src='http://localhost/app-side/Icons/bar_icon.png' />
</td>
<td width='80%'><h2>{$rows[$i]['titel']} </h2></td>
</tr>
</table>
</button>
<div class='toggle'>
<p>
{$rows[$i]['info']}
</p>
</div>
</div>";
$i++;
}
UPDATE
Based on your comment, it could then due to something inside sql.php, most probably database connection problem. Try putting error_reporting(E_ALL) at the very top of the page and see if that prints out any error.
Have you checked your sql.php to make sure you've changed it to match your live server (changed from localhost variables) also check your database field names versus your script for typos.
[code]
{$rows[$i]['titel']} </h2></td>
[\code]
Is it supposed to read :
[code]
{$rows[$i]['title']} </h2></td>
[\code]
If your database field name is "title" and
You are trying to get data from a field called
"titel" than that could cause your error.
I hope that helps
Related
This is head file of my program:
<?php
$obrazki = array('opona1.jpg', 'olej1.jpg', 'swieca_zaplonowa1.jpg',
'drzwi1.jpg', 'kierownica1.jpg',
'termostat1.jpg', 'wycieraczka1.jpg',
'uszczelka1.jpg', 'hamulec1.jpg');
shuffle($obrazki);
?>
<html>
<head>
<title>Czesci samochodowe Janka </title>
</head>
<body>
</br>
<h1 style="color:blue;font-size: 4em; text-align:center"> Czesci samochodowe Janka</h1>
</br>
<h3 style="color:red;font-size: 2em; text-align:center"> Witamy na stronie Czesci samochodowe Janka!</h3>
<form action="glowna.php" method=post>
<div align="center">
<table width = 100%>
<tr>
<?php
for ($i = 0; $i < 4; $i++) {
echo "<td align=\"center\"><img src=\"";
echo $obrazki[$i];
echo "\"/></td>";
}
?>
</tr>
<table>
</br>
<p style="color:red;font-weight:bold; text-align:center"> Prosimy o poswiecenie czasu i poznanie nas!</p>
</br>
<tr>
<td align="center"><input type="submit" value=" Wejscie "></td>
</tr>
</div>
</form>
</body>
</html>
File got extention *.php. It has to load some pics(opona1.jpg...) from $obrazki and if button "Wejscie" is pressed, programm in file glowna.php is called. Two problems:
1. If i try to change top of the program in such way
<html>
<?php
$obrazki = array('opona1.jpg', 'olej1.jpg', 'swieca_zaplonowa1.jpg',
'drzwi1.jpg', 'kierownica1.jpg',
'termostat1.jpg', 'wycieraczka1.jpg',
'uszczelka1.jpg', 'hamulec1.jpg');
shuffle($obrazki);
?>
and to change extetion of head file from *.php to *.html - program doesn't work properly and doesn't show images at all?
2.All image files from $obrazki were of different images and had different names without 1s( like opona.jpg, olej.jpg, swieca_zaplonowa.jpg etc.)from the very begining. But if I tried to insert different images in my program and give them the same names (opona.jpg, olej.jpg, swieca_zaplonowa.jpg...) program started to show old(previous) pix even if i erased them totally. But when i changed names of all images from $obrazki adding 1s to names(like u see now) program started to show these new images.Why have I to do like that? Is this means html save information about image files somewhere? Thnx
First, always try to use English words (like variables or files) in your code. It's easier to understand for readers which don't know your language.
You can't change file extension from PHP to HTML. Only PHP files can execute PHP scripts. (Of course, you can configure your server to execute HTML file as PHP or add rule to htacess to swap extension from .php to .html)
I think it's cache. You should always refresh page few times or use any method to clean cache after making changes (In chrome you can disable cache on the selected page)
Anyone know of a PHP method, code snippet or project that I can use or start with to take a HTML input and remove the <style> tag but apply all the styles to each element they were intended for?
Example Input:
<html>
<head>
<style>
body {
font-size: 10px;
}
td {
font-size: 8px;
}
</style>
</head>
<body>
<!--This is my table with smaller text: -->
<table>
<tr><td>this text is:</td><td>8px</td></tr>
</table>
</body>
</html>
Desired output:
<html>
<head>
</head>
<body style="font-size: 10px;">
<!-- This is my table with smaller text: -->
<table>
<tr><td style="font-size: 8px;">this text is:</td><td style="font-size: 8px;">8px</td></tr>
</table>
</body>
</html>
Why? I want my app to include original emails with replies without the original message styles messing with the format of the reply. I'm guessing this is the way forward for me because when you view the source of a reply in Outlook, it seems to use this method.
https://github.com/tijsverkoyen/CssToInlineStyles should do the trick. The code would look like this:
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
$cssToInlineStyles = new CssToInlineStyles();
$css = "body {
font-size: 10px;
}
td {
font-size: 8px;
}";
$html = "
<body>
<!--This is my table with smaller text: -->
<table>
<tr><td>this text is:</td><td>8px</td></tr>
</table>
</body>
";
echo $cssToInlineStyles->convert(
$html,
$css
);
If you'd rather use an online tool there is also http://premailer.dialect.ca/
What you're looking is a style inliner, that's often used on HTML email development, here you have some tools:
https://templates.mailchimp.com/resources/inline-css/
http://foundation.zurb.com/emails/inliner.html
https://inliner.cm/
https://putsmail.com/inliner
https://github.com/tijsverkoyen/CssToInlineStyles
https://github.com/jjriv/emogrifier
https://www.npmjs.com/package/css-inliner (for npm)
http://www.mailermailer.com/labs/tools/magic-css-inliner-tool.rwp
Depending on your apps code, you could find some library to do so... if you want to build your own.... maybe the npm package can serve you as guide.
Hope this helps
I am using Emogrifier for creating HTML mail messages - and it works really good for me.
Here's a link:
Emogrifier
You can use id and class to save your CSS code and call whenever you want in a tag.
I have a PHP script that has an infinite loop in it. The browser does not print the first echo statements in the loop, it does not even provide proper links to the hyperlinks. What could have gone wrong?
Demo
Code:
<html>
<head>
<style>
img{
height:200px;
width:200px;
}
</style>
</head>
<body>
<?php
error_reporting (0);
set_time_limit(0);// Setting an infinite timeout limit.
for($i=1; ;$i++)
{
$to_send = "http://graph.facebook.com/";
$to_send_new = $to_send.$i;
$content = file_get_contents($to_send_new);
$parsed = json_decode($content);
$link = $parsed->link;
$link = str_replace("http://www.facebook.com","https://graph.facebook.com",$link);
$link .="/picture?width=200&height=200";
if(!$parsed->first_name)
goto a;
?>
<br>
First Name: <?php echo $parsed->first_name;?>
<br>
Last Name:<?php echo $parsed->last_name;?>
<br>
Full Name :<?php echo $parsed->name;?>
<br>
Facebook Username:<?php echo $parsed->username;?>
<br>
Gender:<?php echo $parsed->gender;?>
<br>
Profile Picture
<!--
<img src="<?php/* echo $link; */?>" >
-->
<br>
<hr>
<?php
sleep(5);
a:
}
?>
</body>
</html>
Be careful with infinite loops. Depending on your web server (eg. apache) and php settings any request to your server adds up a thread on the server, which eats their set of ressources. This may or may not hang up your server over time.
Sometimes I use long lasting loops myself. In such cases I found apachestatus useful, to check which threads are still running:
http://httpd.apache.org/docs/2.2/mod/mod_status.html
It also provides the PID which helps to kill old threads.
I have a search form that when you click on the more info link for a record will open a new window for that record to display additional information and I use <a href=more_info.php?id=$rows[id]>to pass the id to the next page and that works great.
On that next page I have a button that pops up a small browser window using this <a href="#" onclick="window.open('signature_pad.html', 'newwindow', 'width=500, height=200'); return false;"> this windows pops up with a signature pad.
What I need to do is pass that record ID from the second window to the popup window so when the customer signs the signature pad their signature is posted into the correct record.
so here is the code for the 2nd and popup pages: (I only posted the code for the button section of the 2nd page to save space as the code for that page is fairly long and only the button portion pertains to this question)
<table class="auto-style16" style="width: 615px; height: 28px;">
<td style="width: 435px; height: 22px;" class="auto-style7">
**<input type="button" value="Get Signature" />**
And the popup window
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Signature Pad</title>
<!-- The Signature Pad -->
<script type ="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="signature-pad.js"></script>
</head>
<body>
<center>
<fieldset style="width: 435px">
<br/>
<br/>
<div id="signaturePad" style="border: 1px solid #ccc; height: 55px; width: 400px;"></div>
<br/><br/><br/>
<button id="clearSig" type="button">Clear Signature</button>
<button id="saveSig" type="button">Save Signature</button>
<div id="imgData"></div>
<br/>
</fieldset>
</center>
<div id="debug"></div>
</body>
</html>
This is the doesn't work page you have:
more_info.php
<p>I have some text here and am just a HTML page saved as .php</p>
<table class="auto-style16" style="width: 615px; height: 28px;">
<td style="width: 435px; height: 22px;" class="auto-style7">
**<input type="button" value="Get Signature" />**
This is how it should be:
more_info.php
<?php
$myId = $_GET['id'];
?>
<p>I have some text here and am a HTML with PHP page saved as .php</p>
<table class="auto-style16" style="width: 615px; height: 28px;">
<td style="width: 435px; height: 22px;" class="auto-style7">
**<input type="button" value="Get Signature" />**
On my above example, I am making use of php for 2 things, first I received the query string id and save it into my variable $myId then I print the variable to the HTML location it should for the window.open. You can also print the $_GET directly but I prefer not to in case I need to further do things to the variable like sanitization, etc.
More information on $_GET
To carry a variable across your PHP application you can use either GET / POST (hidden option) or PHP Session, or use your database
Since you need to save variables across your web app, you have to incorporte sessions (with or w/o database).
On top of each page add this:
session_start(); and this will allow your web app server track each user.
Then assign any vars to session $_SESSION['user']='Bob';
Then, when you get familiar with sessions, you can just keep track of user id and keep the rest in the database
Check this article and go from there
<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?php print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>° C,
<?php echo $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<?php foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?php echo $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?php echo round(conver_f_c($forecast->low['data'])); ?>° C - <?php echo round(conver_f_c($forecast->high['data'])); ?>° C,
<?php echo $forecast->condition['data'] ?>
</span>
</div>
<?php endforeach ?>
</body>
</html>
<?php
function conver_f_c($F){
return $C = ($F − 32) * 5/9;
}
I want Out somthing like this manner of the horizontal ,
Even i tried UL LI WITH display inline but it goes failed,
Tell me some good suggestion for my probme,
I want exactly like horizontal, expecting exactly like screen shot ,
Tell me How to render using php
Thanks
alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg
Above snippet present display out verticly , i want o change that verticle to horizonatal ,
somthing like this screen shot
<table>...</table>
Update
From your latest comment so far:
i know how to fetch array and display
it, but i dont know to fetch and
display in the verticl manner that is
the stuck up
I feel this is going to be a stupid answer but it appears to be what you don't understand...
The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.
You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.
To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.
And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:
<table>
<tr>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
<td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
<td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
</tr>
<tr>
<td>26ºC</td>
<td>26ºC</td>
<td>22ºC</td>
<td>25ºC</td>
</tr>
<table>
I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.
This is what's done by Google :
http://jsfiddle.net/bW8NA/1