Jump to content

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


yshua

Recommended Posts

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 "<br />". mysql_errno(). " : ". mysql_error();
}

?>

Thanks, ahead of time,

Yshua :-\

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.