erikla
-
Posts
41 -
Joined
-
Last visited
Posts posted by erikla
-
-
Thanks Jacques! I will take notice of both points: utf8mba and to include utf-8 in the header. Regarding the first, I guess you mean that utf8mb4_Danish_ci is a better choice than utf8_Danish_ci as charset when defining the tables manually within phpMyAdmin, right? Also thanks for the details about the PDO code.
Erik -
Superb explanations from both of you (David and Jacques)! David: Your line mysql_query("Set names 'utf8'"); did the trick! Now the Danish letters display correctly. I am perfectly aware, that the code is not appropriate. Actually I got the advice to use MySQL PDO from this site about a month ago. The reason why I used the above implementation is because I found it in a tutorial elsewhere. The situation is that I need to take one step at a time in my learning process. Firstly I used quite some time to find Xampp to install phpMyAdmin making the appropriate settings. I need to make things work locally before I upload things. Now I realize my local version of php/MySQL is working properly, my next step will be to change the php code to MySQL PDO. I have already read the article about "prepared statements". Besides I have begun using Dreamweaver, so this is new too. I have a license for an Adobe bundle, including Dreamweaver, so I better learn to use it now. So far I have been using a not so wellknown Web Editor named Namo. Mostly I have created my webpages via the WYSIWYG part, with some knowledge about the HTML code itself - but not too much. I never considered the thing about HTML vs. XHTML that you write about, Jacques. I just used an almost empty page settings from Dreamweaver. At least it did include the meta tag with the charset utf-8 part. Now that I know how to handle things in phpMyAdmin and Dreamweaver, I will take the next step and change to MySQL PDO. Maybe the charset=utf-8 is handled differently in this environment? Anyway I will probably return with more questions later. Again big thanks for the advice. I appreciate it! Great site!!
Erik
-
I have a problem with the three special characters in the Danish language: æ, ø and å. I have created a database with a simple table manually within phpMyAdmin, and I have added contents, which is text with the letters mentioned. Everythings looks correct in here. But when I get the content of the database written out via a php document, these three letters are replaced with a box sign. In phpMyAdmin I chose "utf8_danish_ci" as collation. And here is the code of the php document writing out the content of the database table, named "lille_tabel", with the password written with stars.
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $server = "localhost"; $brugernavn = "root"; $kodeord = "************"; $db = "lille"; mysql_connect($server,$brugernavn,$kodeord) or die(mysql_error()); echo "Forbundet til MySQL server<br/>"; mysql_select_db($db) or die(mysql_error()); echo "Forbundet til Databasen<br/>"; $data = mysql_query("SELECT * FROM lilletabel") or die(mysql_error()); while ($info = mysql_fetch_array($data)) { echo "ID: ".$info['id']."<br/>"; echo "Navn: ".$info['navn']."<br/>"; echo "Tekst: ".$info['tekst']."<br/>"."<br/>"; } ?> </body> </html>
By the way: I use Dreamweaver. I hope someone have suggestions to pinpoint the problem ...
Regards,
Erik
-
Great! Now I think I understand the different views on the choice of datatype for IP addresses. Thanks a lot!
Erik
-
Hi requinix
Good question. A number of years ago I created a guestbook for my website, with a lot of help from a tutorial. This tutorial did have the IP address for the computer as a field in the database table. I think they added the IP address field in order to be able to lock out certain computers if they applied spam or so, but I am not sure. Now I just need to "repair" the code to make it work on my new Webhotel - since then some of the code has been deprecated and outdated. I still want the table to contain the IP address from contributors. From what you say, I guess a string type will be appropriate. I think I will still be able to compare string against string, right? So VARCHAR for email addresses as well as IP addresses?
Erik
-
I am quite new to PHP and MySQL. I am trying to figure out what datatypes to use for different fields in a Database. For ID (Identification) I use INT, for name I use VARCHAR and for people to write text messages, I use LONGTEXT. For date and time I use DATETIME.
What I am unsure about, however, is what type to use for an email adress and for an IP address? I have been watching videos at Youtube about the Datatype for IP addresses, but they don't seem always to agree. I hope someone can put me in the right direction on those two.
Regards,
Erik
-
Thanks, then I won't bother setting it up further!
Sorry for placing the question in the wrong section.
Regards,
Erik
-
I have used the XAMPP installer to install php and MySQL locall on my computer. I also succeeded in setting the security for XAMPP pages, the MySQL admin user root and phpMyAdmin login. When I enter phpMyAdmin via the link in the XAMPP initial page I do however receive a red notification:
phpMyAdmin configuration storage is not fully configured; some extensions are not activated. To find out click here.I have attached a screenshot showing three items which are not OK, shown in red. I looked up in the documentation, but could not find out. I hope someone can help. I don't even know if it is important to fix this problem.
Regards,
Erik
-
Jacques1, I will follow your advice and read the tutorial in order to understand the logic behind PDO, and get back if I get stuck in specific tasks. I really can't answer your question, why I use a "persistent connection". Have never heard about it, to be honest! Maybe 12-15 years back I took the code from a webcafé and modified it for my own purposes. I was able to do so without having read books about MySQL. Therefore I am not aware of all the tiny (but important) details. I think I need to look at it a bit closer without, hopefully, to need to read entire books about it.
Erik
-
Interesting with PDO, indeed! Sounds as it is easier and more fluent to use, but that it does not cover as much as the alternative in a few situations ... I will try it. Below is my code, before I make any changes. I have omitted some error-handling code and also the details on how to display the content of the Guestbook. Basicly there are three files:
save.php: Saving guestbook data entered into in a HTML Form (the latter file not shown).
mysql_functions.php: Additional functions to handle the interaction with the database.
gbook.php: The page to display the entire guestbook entrances, including the new one.
save.php
<?php require("mysql_functions.php"); function write_in_guestbook($name, $epost, $contribution) { global $REMOTE_ADDR; $ip = $_SERVER['REMOTE_ADDR']; $sql = "insert into guestbook(name,epost,contribution,ip,time) values('$name','$epost','$contribution','$ip',now())"; open_connection_and_choose_db(): sql_ask($sql); close_connection(); } write_in_guestbook(addslashes($name),addslashes($epost),addslashes($contribution)); header("Location: gbook.php"); ?>
mysql_functions.php
<?php function open_connection_and_choose_db() { $server = "*********"; $user = "*********"; $password = "*********"; $database = "*********"; if (!@mysql_pconnect("$server","$user","password")) { udskriv_fejl("Kunne ikke oprette en forbindelse til MySQL."); } if(!mysql_select_db("$database")) { print_error("Was not able to choose the database: $database"); } } function close_connection() { if(!mysql_close()) { print_error("Was not able to close the connection to MySQL!"); } } function sql_ask_and_receive_answer($query) { $result = mysql_query($query); if(!$result) { print_error("Was not able to execute: <em>$query</em>"); } while($row = mysql_fetch_array($result)) { $result_array[] = $row; } return $result_array; } function sql_ask($query) { $result = mysql_query($query); if(!$result) { print_error("Was not able to execute: <em>$query</em>"); } } function print_error($fejl) { echo "<p>$fejl"; if ($mysql_fejl = mysql_error()) { echo "<br>The error is: <em>$mysql_fejl</em>"; } exit; } ?>
gbook.php
gbook.php <?php require("mysql_functions.php"); if(!$start_nr || $start_nr < 0) { $start_nr = 0; } $sql = "select id, name, epost, date_format(time, '%e/%c %Y, %H:%i') as time, contribution from guestbook order by time desc limit $start_nr, $number_at_a_time"; $counter_sql = "select count(*) as number from guestbook"; open_connection_and_choose_db(); $result = sql_ask_and_receive_answer($sql); $counting = sql_ask_and_receive_answer($counter_sql); close_connection(); extract($counting[0]); + MORE TO WRITE THE CONTENTS OF guestbook IN AN APPROPRIATE WAY ... ?>
I would de delighted if someone could push me in the right direction on how to make the changes in the PDO way ...
Regards,
Erik
-
Jacques and mac_gyver: I see there are two options really: mysql with an 'i' added (simplified) or PDO. From the list in the link below they seem quite similar in "Feature comparison":
http://www.php.net/manual/en/mysqlinfo.api.choosing.php
Is mysql with an 'i' added an easy "quick-fix" compared to PDO, or are they equal good? I might be willling to go for the best solution if it is not too difficult ...
Erik
-
Thanks a lot mac_gyver. Good explanations! I will try to replace the old mysql functions with the new mysqli_ functions, remembering the extra database parameter. Also I will try to take into account your other recommendations. If I don't succeed, I will return with more questions ... great website!
Erik
-
Dear php freaks
I am working on updating the php code of my old Guestbook. I haven't been working on php for years, so I am very rusty. From searhing on php.net, I realize that quite a few of the commands in my old php code are deprecated. Here is a list.
@mysql_pconnect
mysql_select_db
mysql_query
mysql_fetch_array
mysql_close()
mysql_error()
global $HTTP_USER_AGENT
eregiRegarding for example the mysql_query php.net says the following:
http://www.php.net/manual/en/function.mysql-query.php
But thare are several options, I see. Can someone guide me how to make the proper changes. Should I just replace the above commands with some newer ones?
Regards,
Erik
-
Thanks a lot! I understand that I have been using deprecated code and the new Webhotel did not support the old way ...
I just changed it the way you describe and now it Works as expected! Great!
Erik
-
Dear phpfreak users
It is several years ago I looked at php code, so I am very rusty here. Many years ago I managed (with some help) to produce a guestbook for my website. It is the only part containing php code. A week ago I changed webhotel and after transferring my website to the new Webhotel, something is not working properly. I have been trying to pinpoint what it is. I think I have found one issue: When a user fill out a form and press the submit button, the variables are not transferred to the php page, which is written in the action part of the form. To make it less confusing I have deleted parts of my php page and just kept the part, where I guess there is a problem.
The form page named guest_form.html:
<HTML>
<HEAD>
<TITLE>Add items to the Guest book</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="generel/hoved.css">
</HEAD>
<BODY>
<h1><font color="#903C39">Guestbook</font></h1>
<FORM method="POST" action="guest_save.php">
<hr><br>
<table cellspacing=5 cellpadding=5>
<tr>
<td valign=top><strong><p><b><font color="#903C39">Name</font></b></p></strong></td>
<td valign=top>
<INPUT type="text" name="navn" size=40 maxlength=60>
</td>
</tr>
<tr>
<td valign=top><strong><p><b><font color="#903C39">E-mail</font></b></p></strong></td>
<td valign=top>
<INPUT type="text" name="epost" size=40 maxlength=60>
</td>
</tr>
<tr>
<td valign=top><strong><p><b><font color="#903C39">Contribution</font></b></p></strong></td>
<td valign=top>
<TEXTAREA name="indlaeg" cols=50 rows=6></TEXTAREA>
</td>
</tr>
<tr>
<td align=center colspan=2>
<INPUT type="submit" value="Submit Contribution">
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
The guest_save.php page:
<?php
if ($navn == "") {echo "Name is empty";}
if ($navn != "") {echo "Name is not empty";}
?>Comments:
I uploaded both pages and they are located at the same level. Then I filled out the form and pressed the submit button. The php page was displayed with the text: "Name is empty". So it look like the content of 'navn' is not tranferred to the php page. Is my code wrong could it be a problem at the Webhotel? I really hope somebody can push me in the right direction ...
Regards,
Erik
Is it possible to "redirect" htdocs to another folder?
in PHP Installation and Configuration
Posted
I installed Xampp on my Windows computer. It actually works well, but one thing that is a bit annoying is the fact that when you want to show the output of a PHP document, then it is necessary for the site to be located in the htdocs folder of C:\xampp. Or is it necessary? Is there a way to sort of "redirect" to another folder on the computer? I have my system (Windows 7) on my C drive and my data on my D drive. Sometimes I clone my C drive to keep it up to date and fast. Is there a way to have my website files on the D drive and Xampp installed in the default location on C:\xampp and still be able to test my site locally?
Erik