Jump to content


Photo

Inserting line of data from PHP thru MYSQLI, w emsg.


  • Please log in to reply
4 replies to this topic

#1 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 123 posts

Posted 12 August 2012 - 07:56 PM

Dear encouraging, appreciated people:

        All comments (even when my ears tingle) are taken positively.  Am babystepping, taking my time, running PHP5.3.8, MYSQL5.5, Win7, Apache2.2 and receive following emsgs from a customer entry menu:


Timestamp: 8/12/2012 6:32:24 PM
Warning: A form was submitted in the windows-1252 encoding which cannot encode all Unicode characters, so user input may get corrupted. To avoid this problem, the page should be changed so that the form is submitted in the UTF-8 encoding either by changing the encoding of the page itself to UTF-8 or by specifying accept-charset=utf-8 on the form element.
Source File: http://127.0.0.1/form.php
Line: 0

Timestamp: 8/12/2012 6:32:24 PM
Error: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.
Source File: http://127.0.0.1/insert.php
Line: 0

        Here is condensed code of php.insert:

<?php
include("admin/includes/db.php");

mysqli::__construct() ([ string $host = ini_get("mysqli.default_host") [, string $username = ini_get("mysqli.default_user") [, string $passwd = ini_get("mysqli.default_pw") [, string $dbname = "reccus2" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
 
  $mysqli = new mysqli('host', 'headache2', 'Mag114nes43ium44', 'reccus2');

 /*
 * This is the "official" OO way to do it,
 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
 */
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}

/*
 * Use this instead of $connect_error if you need to ensure
 * compatibility with PHP versions prior to 5.2.9 and 5.3.0.
 */
if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . $mysqli->host_info . "\n";

mysql_query("INSERT INTO users (fname,lname,address,city,state,zip,phone,emailid,howhear) VALUES 
('".$_REQUEST['fname']."','".$_REQUEST['lname']."','".$_REQUEST['address']."','".$_REQUEST['city']."','".$_REQUEST['state']."','".$_REQUEST['zip']."','".$_REQUEST['ph_no']."'
,'".$_REQUEST['email']."','".$_REQUEST['howhear']."')");
session_start();
$_SESSION['user']=$_REQUEST['fname'];

$mysqli->close();

if (mysql_error()) {
echo "&lt;br /&gt;". mysql_errno(). " : ". mysql_error();
}

?>
Thanks, ahead of time,
Yshua :-\

#2 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 12 August 2012 - 08:03 PM

When posting code, enclose it within the forum's [code] . . . [/code] BBCode tags.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

#3 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 13 August 2012 - 11:04 AM

The problem is not related to that code at all, but rather the communication between your web server and browser.

In short: Your browser is sending the content using the windows-1252 charset, while your web server (and code) expects UTF-8. The possible fixes for this has been listed in the first error message, with the most recommended one being to add the correct header to the HTTP header your browser sends.
header ("content-type: text/html; charset=utf-8");

If that doesn't help, make sure your browser auto-selects the charset to use, and lastly the accept-charset attribute on the form element.
Keeping it simple.

#4 yshua

yshua

    Advanced Member

  • Members
  • PipPipPip
  • 123 posts

Posted 21 August 2012 - 01:41 AM

Dear ChristianF:

      You nailed the problem!  Am gaining momentum on solving it, but the handling of charset has gotten to a lot of other mysteries as well.  Thanks for taking the time out.

Have a great day,
Yshua

#5 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 21 August 2012 - 05:48 AM

You're welcome, and I'm glad I could help. :)
Keeping it simple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com