New on PHP/MYSQL
Character sets revisited
I have had a thread here recently titled: Special Language characters doesn't display correctly. Now however, I have encountered a new problem with character sets, that I hope you can help me resolve! I find the concept of character sets quite confusing. When you are dealing with a database and want the content to be displayed on a web page, you obviously want it to be displayed correctly, and if you are not from an English speaking country, this could cause you some problems here and there due to international characters. As I have understood, one need to tell how the data (text) is stores in the database, how it is being interpreted (collation) and how it is being displayed on the web page.
Here is my situation:
One php page is displaying the content of a guestbook: show_content. This php file is divided into three parts: An include of a header.html file, a middle section displaying the content of the database and finally an include of a footer.html file to take care of the lower part of the page. Now, the header.html file does contain the script for a dropdown menu written in javascript:
header.html
<html> <head> <title>Guestbook</title> <meta http-equiv="Content-Language" content="da"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <LINK REL=stylesheet TYPE="text/css" HREF="generel/pop_style.css"> <LINK REL=stylesheet TYPE="text/css" HREF="generel/hoved.css"> </HEAD> <BODY leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 background="generel/univback.gif"> <script type="text/javascript" language="JavaScript1.2" src="generel/pop_core.js"></script> <script type="text/javascript" language="JavaScript1.2" src="generel/pop_data.js"></script> <script type="text/javascript" language="JavaScript1.2" src="generel/pop_events.js"></script> <!--etc .......
The main page controlling this header:
show_content.php
<?php function handle_fatal_errors() { if (http_response_code() == 500) {echo 'A technical error ocurred.';} } register_shutdown_function('handle_fatal_errors'); ini_set('display_errors', 0); include("header.html"); include("settings.php"); header('Content-Type: text/html; charset=utf-8'); //etc ...
The footer.html file doesn't really matter here, so I avoid it.
Now the strange thing: When I execute the show_content.php file above, the content of the database (guestbook) display perfectly, but the International letters in the dropdown menu don't display properly. BUT if I out-comment the following line:
header('Content-Type: text/html; charset=utf-8');
in the show-content.php file it is the opposite way around!! Then the items in the dropdown menu display properly while the content of the guestbook don't!
By the way: When I connect to the database to store items, I do it with the following code:
$db = new PDO('mysql:host='.$server.';dbname='.$database.';charset=utf8mb4', $username, $password);
If somebody have an idea for an explanation of this behavior, I will be happy to hear about it! To me all these character set issues seem rather overwhelming. Maybe one setting override the other or what?
NB! I also read that the people around the developement of PHP temporarily gave up on Unicode support for a PHP 6.0 version ...
Erik
Very slow retrieval of data from a database - what can you do?

<center> <br /> <table border=0 cellspacing=1 cellpadding=0 width="1000px"> <tr> <td align='right' valign='middle' style='width: 40%;text-align: right;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>שם המוסד</td> <td align='right' valign='middle' style='width: 15%;text-align: right;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>רישום לקייטנה</td> <td align='right' valign='middle' style='width: 15%;text-align: right;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>משלמים לקייטנה</td> <td align='center' valign='middle' style='width: 10%;text-align: center;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>רישום לצהרון</td> <td align='center' valign='middle' style='width: 10%;text-align: center;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>משלמים לצהרון</td> <td align='center' valign='middle' style='width: 5%;text-align: center;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>רשומים לבית ספר</td> <td align='center' valign='middle' style='width: 5%;text-align: center;padding: 5px;background: #061B2A;color: #FFF;font-weight: bold;'>רשומים לגן</td> </tr> </table> <? ?> <?php $res1 = mysql_query("SELECT * FROM `places` ORDER BY `name` desc"); while($row1 = mysql_fetch_array($res1)) { $res_ci = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `city`='".$row1["id"]."' AND `rishum_to`='1' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_ci = mysql_num_rows($res_ci); $res_ci_PAY = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`='payed' AND `city`='".$row1["id"]."' AND `rishum_to`='1' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_ci_PAY = mysql_num_rows($res_ci_PAY); $res2_ci = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `city`='".$row1["id"]."' AND `rishum_to`='2' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row2_ci = mysql_num_rows($res2_ci); $res2_ci_PAY = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`='payed' AND `city`='".$row1["id"]."' AND `rishum_to`='2' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row2_ci_PAY = mysql_num_rows($res2_ci_PAY); $res_countPerCity_school = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `city`='".$row1["id"]."' AND `soog_mosad`='school' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_countPerCity_school = mysql_num_rows($res_countPerCity_school); $res_countPerCity_gan = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `city`='".$row1["id"]."' AND `soog_mosad`='gan' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_countPerCity_gan = mysql_num_rows($res_countPerCity_gan); if(($row_ci+$row2_ci) > 0) { ?> <div class="module" style="width: 1000px"><div class="module_name" align='center' style='cursor: hand;cursor: pointer;'> <table border=0 cellspacing=1 cellpadding=0 width="1000px"> <tr class="try"> <td align="right" style="text-align: right;width: 40%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row1["name"];?></td> <td align="center" style="text-align: center;width: 15%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row_ci;?></td> <td align="center" style="text-align: center;width: 15%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row_ci_PAY;?></td> <td align="center" style="text-align: center;width: 10%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row2_ci;?></td> <td align="center" style="text-align: center;width: 10%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row2_ci_PAY;?></td> <td align="center" style="text-align: center;width: 5%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row_countPerCity_school;?></td> <td align="center" style="text-align: center;width: 5%;padding: 5px;color: #FFF;font-weight: bold;"><?=$row_countPerCity_gan;?></td> </tr> </table> </div><div class="module_links2" align='center'> <table border=0 cellspacing=1 cellpadding=0 width="1000px"> <? $resCITY = mysql_query("SELECT * FROM `schools` WHERE `city`='".$row1["id"]."' ORDER BY `type` desc,`name`"); while($rowCITY = mysql_fetch_array($resCITY)) { $res = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `the_mosad`='".$rowCITY["id"]."' AND `rishum_to`='1' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row = mysql_num_rows($res); $res_PAY = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`='payed' AND `the_mosad`='".$rowCITY["id"]."' AND `rishum_to`='1' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_PAY = mysql_num_rows($res_PAY); $res2 = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `the_mosad`='".$rowCITY["id"]."' AND `rishum_to`='2' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row2 = mysql_num_rows($res2); $res2_PAY = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`='payed' AND `the_mosad`='".$rowCITY["id"]."' AND `rishum_to`='2' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row2_PAY = mysql_num_rows($res2_PAY); if(($row+$row2) > 0) { ?> <tr> <td align="rigth" style="width: 40%;text-align: right;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"><?=$rowCITY["name"];?></td> <td align="center" style="width: 15%;text-align: center;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"><a href="index.php?action=rishum&sa=statistics&year=<?=$filterByYear;?>&city=<?=$row1["id"];?>&school=<?=$rowCITY["id"];?>&tofesType=1&typeee=<?=$rowCITY["type"];?><? if($_GET["aougust_form"]) { echo "&aougust_form=1"; } ?>"><?=$row;?></a></td> <td align="center" style="width: 15%;text-align: center;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"><?=$row_PAY;?></td> <td align="center" style="width:10%;text-align: center;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"><a href="index.php?action=rishum&sa=statistics&year=<?=$filterByYear;?>&city=<?=$row1["id"];?>&school=<?=$rowCITY["id"];?>&tofesType=2&typeee=<?=$rowCITY["type"];?><? if($_GET["aougust_form"]) { echo "&aougust_form=1"; } ?>"><?=$row2;?></a></td> <td align="center" style="width:10%;text-align: center;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"><?=$row2_PAY;?></td> <td align="center" style="width:5%;text-align: center;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"> --- </td> <td align="center" style="width:5%;text-align: center;padding: 5px;background: #ddd;color: #444444;font-weight: bold;"> --- </td> </tr> <? } } ?> </table> </div></div> <? } } $res_all = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `rishum_to`='1' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_all = mysql_num_rows($res_all); $res_all_PAY = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`='payed' AND `rishum_to`='1' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_all_PAY = mysql_num_rows($res_all_PAY); $res_all2 = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`!='not_relevant' AND `rishum_to`='2' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_all2 = mysql_num_rows($res_all2); $res_all2_PAY = mysql_query("SELECT * FROM (SELECT * FROM `rishum` WHERE `status`='payed' AND `rishum_to`='2' AND `aougust_form`='".$_GET["aougust_form"]."' AND `date`>='".$filterByYear."/04/22' AND `date`<='".($filterByYear+1)."/04/21') as c GROUP BY `talmid_id`"); $row_all2_PAY = mysql_num_rows($res_all2_PAY); ?> <table border=0 cellspacing=1 cellpadding=0 width="1000px"> <tr> <td align='right' valign='middle' style='width: 40%;text-align: right;padding: 10px;background: #000;color: #FFF;font-weight: bold;'>סה"כ טפסי רישום</td> <td align='center' valign='middle' style='width: 15%;text-align: center;padding: 10px;background: #000;color: #FFF;font-weight: bold;'><?=$row_all;?></td> <td align='center' valign='middle' style='width: 15%;text-align: center;padding: 10px;background: #000;color: #FFF;font-weight: bold;'><?=$row_all_PAY;?></td> <td align='center' valign='middle' style='width: 10%;text-align: center;padding: 10px;background: #000;color: #FFF;font-weight: bold;'><?=$row_all2;?></td> <td align='center' valign='middle' style='width: 10%;text-align: center;padding: 10px;background: #000;color: #FFF;font-weight: bold;'><?=$row_all2_PAY;?></td> <td align='center' valign='middle' style='width: 5%;text-align: center;padding: 10px;background: #000;color: #FFF;font-weight: bold;'> --- </td> <td align='center' valign='middle' style='width: 5%;text-align: center;padding: 10px;background: #000;color: #FFF;font-weight: bold;'> --- </td> </tr> </table> </center>
MySQL Fetch Array Loop If Statement
Hi,
Does anyone have a clue how I might solve this little issue:
I have a MySQL query, for example:
<?php // Make a MySQL Connection $query = "SELECT * FROM staff"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if($row['clock'] < time()) { echo "<b>"$row['name']. " - ". $row['age']"</b>"; echo "<br />"; } else { echo $row['name']. " - ". $row['age']; echo "<br />"; } } ?>
Taking data from the following table setup:
name - age - clock
Timmy Mellowman - 23 - 09:00:00
Sandy Smith - 21 - 12:00:00
Bobby Wallace - 15 - 14:00:00
What im trying to achieve is compare the current time to the time in the clock column and depending if it's earlier or later, change the styling of the results.
The above code does appear to work somewhat however it seems to change the styling of all results in one go, rather than individually when it passes the time in the cell, which is what im looking for.
Thanks
User authantication per browser.
I'd like to know if there is any alternatives for cookies,session and ip for user identification ?
As cookies aren't secure enough as they're easily compromised and untrustable.
As for session, I haven't seen a website that uses session for user identification while still being told to use in several "Login/Registration" tutorials, but aren't secure/trustworthy in my opinion as they're editable.
IP isn't the best idea because people use proxys and can change ip per page or interval. ( and VPN's )
User agents are editable by plugins and aren't unique as far as I know.
Are there any trustworthy information that can be retrived from the user ?
or combine a few into one ?
(except evercookie)
P.S. I am aware of OpenID, OAuth and social media authentication, but I am not interested in other websites identifying users for me.
Appericiate any input.
Help needed for checkbox issue
I'm currently developing a website which allows users to register and log into the system to read news articles in RSS form.
A subscription page with a list of checkboxes (like CNN, BBC etc) is provided for the users to choose which news site they want to include in their customized RSS feed page.
I successfully stored the checkbox values in array form into the database. For example, if the user ticks "CNN", "BBC", "ABC News", the values that will be stored in database will be: cnn, bbc, abc
Since I'm a beginner in web coding, especially in PHP and MYSQL, I have two questions here.
Q1. How can I retrieve the stored values and display it on the subscription page with the specific checkboxes checked based on user's subscription? For instance, if the user already subscribed to CNN, when he logs into the system next time, he should be able to see the already-ticked CNN checkbox.
Q2. How can I retrieve the stored values and put it onto the customised RSS page? It's something like: if cnn is selected, then add http://rss.cnn.com/rss/edition_world.rss. Is there any tutorial on that?
Last but not least, forgive me for asking so many questions in one go in this lengthy piece and thanks for all the replies in advance! =)
Table structure:
HTML for checkboxes:
<input type="checkbox" name="subs[]" value="mal-malins"> The Malaysian Insider</option> <input type="checkbox" name="subs[]" value="mal-malaymo"> The Malay Mail Online</option> <input type="checkbox" name="subs[]" value="mal-star"> The Star</option> <input type="checkbox" name="subs[]" value="mal-nst"> New Straits Times</option>
Code for storing the checkbox values:
//START: Subscription if(isset($_POST['subscribe'])){ if(isset($_POST['subs'])){ try { $data= $_POST['subs']; $subs = implode(",", (array)$data); $stmt = $db->prepare("UPDATE members SET subs = :subs WHERE username = '$username' "); $stmt->execute(array( ':subs' => $subs )); //show success message echo '<div class="alert alert-success"><a class="close" data-dismiss="alert">×</a>Subscription updated!</div>'; //else catch the exception and show the error. } catch(PDOException $e) { $error[] = $e->getMessage(); } } else { echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a>You have not selected any subscription!</div>'; } } //END: Subscription
A crash and no errors
Hi, I'm Chris, first time here, I usually post on stackoverflow but I think that this is a little bit more complex than usual.
I believe I really need a PHP expert to solve this issue. We have an application which is crawling the web. There's 2 main PHP scripts that are doing the work, using using proc_open, and exec() and running over a circular reference. Both scripts that compose the main structure are saving all and every single error on a custom error log, defined this way:
//error_log
@ini_set('error_reporting', -1);
@ini_set('log_errors','On');
@ini_set('display_errors','On');
@ini_set('error_log','/var/www/vhosts/xxx/xxx/resonance/such_a_mess');
The problem is simple, after running for some hours or days, the application stops crawling. And there's no error information at all on the error_logs that could explain the problem or the reason why it stopped. I've been trying to get more details using Newrelic and XHProf, no luck.-
There's no HTTP server involved on the execution of the scripts as they are being executed like I mentioned, using exec() and proc_open:
exec("sh -c \"$cmd | logger\" > /dev/null &");
It has been around 3 months on the same situation... and to be honest the only thing I want at this point is to see a fatal error on the logs, to understand what's going on...
PHP/MySQL - WHERE Clause - Won't Update
Hi,
Im having a problem and I can't seem to figure it out or find anything on the net.
If I use the following code the script successfully updates every row in the table:
mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud'");
However if I try updating the table using the WHERE clause in any of the combinations below nothing happens.
mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud' WHERE Ads_ID=$DBROWID");
----------------------------------------------------------------------
My Script:
mysqli_query($con,"INSERT INTO Ads (Ads_ID, Ads_AID, Ads_Title) VALUES ('', '$Polished_AdRef', '$Polished_AdTitle')"); $DBROWID = mysqli_insert_id($con); mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID=$DBROWID"); // TRIED THESE TOO // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='$DBROWID'"); // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='5'");
Does any one know where I am going wrong?
Cannot store selected form row items in variables
Trouble displaying two images per row
I am trying to display two images per row. Will add in table tags later so it will look nicer. Anyway, it is leaving off the second image. So, I have 6 images and image number two is blank.
$dirname = "Files/$listingid/images/"; $images = glob($dirname."*"); /* $html .= '<table width="100%">'; foreach($images as $image){ $html .= "<tr><td><center>"; $html .="<img src=\"$image\" width=\"300\">"; $html .= "</a></center></td>"; $html .= "</td></tr>"; } $html .= "</table>"; */ $countImages = count($images) ; $imagesPerRow = 2; for ($i = 0 ; $i < $countImages; $i++) { //display image here $image = $images[$i] ; $html .= "<img width = \"200\" src='$image'>" ; if ($i % $imagesPerRow == 0) { //have displayed an entire row $html .= '<br>' ; } }
Dynamic title tags header.php
Hello group,
Apologies if this has been asked. I have a site that is generating pages like this:
storing some values from a php-array into mysaql-db fails
i want to store some data that i have gained from a request at the planetfile of openstreetmap: so i have set up a database on my opensuse 13.1
i have created a db called test on the mysql-server on my opensuse:
CREATE TABLE `pois` ( `id` bigint(20) unsigned NOT NULL, `lat` float(10,7) NOT NULL, `lon` float(10,7) NOT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `pois_tag` ( `poisid` int(11) NOT NULL DEFAULT '0', `tagname` varchar(45) NOT NULL DEFAULT '', `tagvalue` varchar(255) DEFAULT NULL, PRIMARY KEY (`poisid`,`tagname`) )
Where each tagname/value pair is stored as a row in a separate table with the pois id
Processing would be like this
<?php $db = new mysqli(localhost,root,rimbaud,'test'); // use your credentials $xmlstr = <<<XML <data> <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> </data> XML; $fields = array('id','name','lat','lon'); $xml = simplexml_load_string($xmlstr); // // PROCESS XML RECORDS // $poisdata = array(); $tagdata = array(); foreach ($xml->node as $node) { $nodedata = array_fill_keys($fields,''); $nodedata['id'] = intval($node['id']); $nodedata['lat'] = isset($node['lat']) ? floatval($node['lat']) : 0; $nodedata['lon'] = isset($node['lon']) ? floatval($node['lon']) : 0; $poisdata[] = vsprintf("(%d, %10.7f, %10.7f)", $nodedata); foreach ($node->tag as $tag) { $k = (string)$tag['k']; $v = (string)$tag['v']; $tagdata[] = sprintf("(%d, '%s', '%s')" , $nodedata['id'] , $db->real_escape_string($k) , $db->real_escape_string($v)); } } // // STORE THE DATA // $sql = "REPLACE INTO pois ('id','lat','lon') VALUES\n" . join(",\n", $poisdata); $db->query($sql); $sql = "REPLACE INTO pois_tag (poisid, tagname, tagvalue) VALUES\n" . join(",\n", $tagdata); $db->query($sql); // // DISPLAY THE DATA // $currentTags = array(); $sql = "SELECT DISTINCT tagname FROM pois_tag ORDER BY tagname = 'name' DESC, tagname"; $res = $db->query($sql); while (list($tn) = $res->fetch_row()) { $currentTags[] = $tn; } $thead = "<tr><th>id</th><th>lat</th><th>lon</th><th>" . join('</th><th>', $currentTags) . "</th></tr>\n"; $currid = $currlat = $currlon = 0; $sql = "SELECT p.id, lat, lon, tagname, tagvalue FROM pois p LEFT JOIN pois_tag t ON t.poisid = p.id ORDER BY p.id"; $res = $db->query($sql); $tdata = ''; while (list($id, $lat, $lon, $t, $v) = $res->fetch_row()) { if ($currid != $id) { if ($currid) { $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; } $currid = $id; $currlat = $lat; $currlon = $lon; $poisrow = array_fill_keys($currentTags,''); } $poisrow[$t] = $v; } $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tags</title> <meta name="author" content="Barand"> <meta name="creation-date" content="06/04/2014"> <style type="text/css"> body, td, th { font-family: arial, sans-serif; font-size: 10pt; } table { border-collapse: collapse; } th { background-color: #369; color: white; padding: 5px 2px; } td { background-color: #EEE; padding: 2px; } </style> </head> <body> <table border='1'> <?php echo $thead, $tdata; ?> </table> </body> </html>
leeeds to the following errors....
PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> php osm_200.php PHP Notice: Use of undefined constant localhost - assumed 'localhost' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant root - assumed 'root' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant rimbaud - assumed 'rimbaud' in /home/martin/php/osm_200.php on line 3 PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php>
so what goes wrong here...?
Data filter
Hi,
I'm trying to make a program that filters data out of a website. Now I've got a problem.
For example, I've this line:
<td class="maintxt" width="200"><a href="profile.php?x=Stranger">Stranger</a></td><td class="maintxt" width="200">Godfather (96.76%)</td><td class="maintxt" width="200"><i><a href="clanprofile.php?x=Ettertjes">Ettertjes</a></i></td>
Form this line I want to set the word "Stranger" in a variable, and do the same for the word "Godfather". What is the best method to do this?
Thanks in advance,
iRoot121
Using a template in different directories.
So I have a simple template that I want to be the index page of the website that I'm working on, however, I don't want to have to create several almost identical files for each of the directories.
Is there perhaps anyway that I can change the content of the main div yet the address be a different directory.
So for example, this is the main index page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <title>Matthew Noskiw's website - Home</title> <link rel='stylesheet' type='text/css' href='./inc/CSS/styles/default.css' /> <link rel='stylesheet' type='text/css' href='./inc/CSS/static/navigation.css' /> </head> <body> <div id='Container'> <div id='Header'> <div class='right'> <ul id='Navigation'> <li id='NavButton' class='active'><a href='./'>Home</a></li> <li id='NavButton'><a href='./about'>About</a></li> <li id='NavButton'><a href='./blog'>Blog</a></li> <li id='NavButton'><a href='./contact'>Contact</a></li> </ul> </div> <span>noskiw.co.uk</span> </div> <hr /> <div id='MainContent'> <h2>Home</h2> <br /> <span> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </span> <br /><br /> <span> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? </span> </div> <hr /> <div id='Footer'> <span>Matthew Noskiw</span> </div> </div> </body> </html>
But if you look in the <h2> tag in the 'MainContent' div, then you'll see it reads "Home". What I want to happen is that when I change the page, for example, go to /about I want it to read <h2>About</h2>. I have 4 different pages for this so far, is there any way to get it down to just one yet they be in different directories?
P.S The reason this is in the PHP Help section is because I assumed that it would more than likely be something to do with PHP.
Permission denied on unlink
Hi. I'm trying to make my folder management tool able to remove stuff. Problem is, I get permission denied.
I've checked the NFTS perms for the share and for the folder. It's also not read only. I logged into my other workstation as the service account the web server is using and opened a DOS window and did "rd \\server\share\folder" and it removed it no problem. It just fails in PHP. Any idea what I should be looking at? Thanks!
Video handling class in PHP
Hey everyone!
I have a question about handling video files. Are there classes available for handling videos? I've found classes to handle images and I was wondering if there is something similar for videos.
I'm asking because I want to allow users to upload videos, but I want to reduce their resolution (take up less space). The video is intended to play in a small section on the page, so it doesn't require high resolution.
I'll appreciate any help. Thanks!
Unable to display output properly using php "echo" and html tags
hi there, the code below is suppose to display something like the attachement "code2" but instead it displays something like attachement "code1" please assist in find what is wrong with my echo lines.
<?php $counter = 2; $sqlq="select * from state WHERE status = 0 "; $categorysqlq = mysql_query($sqlq); $varq = mysql_num_rows($categorysqlq); while($catfetchq = mysql_fetch_array($categorysqlq)) { $cnty = $catfetchq[0]; $sqllq="select * from vehicle WHERE country = '$cnty' "; $categorysqllq = mysql_query($sqllq); $numsql = "select * from branchaddr WHERE state = '$cnty' "; $numquery = mysql_query($numsql); $varqa = mysql_num_rows($numquery); $cntyfetchq= mysql_fetch_array($numquery); if($varq != 0){ if($counter == 2){ echo "<tr><td><a href=\"transport2.php?id=".$cntyfetchq['state'].">".$catfetchq[1]."(<span style=\"color:red\">".$varqa."</span>)</a></td>"; $counter--; } else{ echo "<td><a href=\"transport2.php?id=".$cntyfetchq['state'].">".$catfetchq[1]."(<span style=\"color:red\">".$varqa."</span>)</a></td></tr>"; $counter = 2; } } } ?>
Pass randomized array to other users
I want the quiz questions a teacher loads to be randomized so that each time the teacher gives it (different class, different day, whatever …) the order of questions will be randomized. I'm loading the data into an array and then shuffling it. Problem solved. BUT … students on their smart devices need to load the same quiz with the same question order.
I can solve this by:
- teacher stores question and answer data and order temporarily in a dB table
- students load that information
- problem solved
But I was hoping to do this without using a table. Is there a way to pass a randomized array from the teacher to the students without going through a dB table? Thanks.
String gets cut off
I have a basic contact us form that gets data from another page if there is and leaves the textarea empty if there is none.
HTML:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" autocomplete="on"> <div class="ui-contact-form "> <span class="icon-user ui-contact-icons"></span><label>Name: </label><input class="input-name" type="text" name="name" autofocus/> </div> <div class="ui-contact-form"> <span class="icon-list ui-contact-icons"></span><span>Service of Enquiry: </span> <div id="radio" class="btngrp-service" name="btngrp-service1" > <input type="radio" id="radio1" name="btngrp-service" value=1><label for="radio1" class="btngrp-service">Moving</label> <input type="radio" id="radio2" name="btngrp-service" value=2 checked="checked"><label for="radio2" class="btngrp-service">Delivery</label> <input type="radio" id="radio3" name="btngrp-service" value=3><label for="radio3" class="btngrp-service">Accounting</label> <input type="radio" id="radio4" name="btngrp-service" value=4><label for="radio4" class="btngrp-service">IT</label> <input type="radio" id="radio5" name="btngrp-service" value=5><label for="radio5" class="btngrp-service">Others</label> </div> </div> <div class="ui-contact-form"> <span class="icon-envelop ui-contact-icons"></span><label>E-Mail: </label><input type="email" name="email" /> </div> <div class="ui-contact-form"> <span class="icon-phone ui-contact-icons"></span><label>Contact No.: </label><input type="tel" name="contactno" /> </div> <div class="ui-contact-form"> <span class="icon-info ui-contact-icons"></span><label>Feedback / Enquiries </label><textarea rows="5" cols="10" name="enquiry" placeholder="Enter your questions here!" ><?php echo htmlspecialchars($enqContent); ?></textarea> </div> <input type="submit"/> </form>
if (isset($_GET['delSpeed']) && isset($_GET['delWeight'])) { $delSpeed = $_GET['delSpeed']; $delWeight = $_GET['delWeight']; $enqContent = 'I would like to enquire about a delivery order weighing '; $enqContent.= $delWeight .'KG and would require '.$serviceText. ' shipping.'; } else { $enqContent = ''; }
And I validate the other fields making sure the user has entered something and not left it empty
$nameErr = $emailErr = $contactErr = $enquiryErr = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $valid = true; var_dump($enqContent); <-- already cut off here if (empty($_POST["name"])) { $nameErr = "<span>Please enter a valid name</span>"; $valid = false; } else { $name = $_POST["name"]; $_SESSION['name']=$name; } if (empty($_POST["email"])) { $nameErr = "<span>Please enter a valid email</span>"; $valid = false; $emailErr = "Missing"; } else { $email = $_POST["email"]; $_SESSION['email'] = $email; } if (empty($_POST["contactno"])) { $nameErr = "<span>Please enter a valid contact number.</span>"; $valid = false; $error = "error"; } else { $contactNum = $_POST['contactno']; $_SESSION['contactno'] = $contactNum; } if(empty($_POST['enquiry'])) { $nameErr = "<span>Please enter valid content to help us serve you better.</span>"; } else { $enquiry = $_POST['enquiry']; //$_SESSION['enquiry'] = $enquiry; var_dump($enquiry); } if($valid) { //trim input print_r($_POST); $serviceType = $_POST['btngrp-service']; $_SESSION['btngrp-service'] = $serviceType; //header('Location: http://localhost/ppsv2/submit.php'); }
As you can see after the IF, I check for the input that came from the other page, the string gets cut off and I have no idea why. When I press submit to check what string I get from $enqContent, this is what I get. I have tried bumping up max_input_vars and post_max_size and nothing seems to work.
I would like to enquire about a delivery order weighing 12KG and would%.
I would like to know what is causing this and what is the solution to it. Thanks!
PHP error help needed
hello I keep getting these errors:
Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\PHP & JQUERY\WEBSITE\index.php on line 17
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\xampp\htdocs\PHP & JQUERY\WEBSITE\index.php on line 19
This is the code I am using:
$conn = mysql_connect("localhost", "root");