I don't know why my html form is not sending data. I have 3 file called default.php, prosesbacasoal.php and bacasoal.php. Because the default.php is too long I just write the html form I get from inspect element
<form method="post" action="prosesbacasoal.php"><div class="head-main- recenttest-result">
<input type="hidden" name="nomor" value="2">
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button> </div></form>
prosesbacasoal.php
<?php
session_start();
if(isset($_POST['submit'])) {
if(isset($_POST['nomor'])) {
$_SESSION['submitsoal'] = true;
$_SESSION['nomorsoal'] = $_POST['nomor'];
header("Location:bacasoal.php");
exit;
} else {
header("Location:bacasoal.php");
exit;
}
} else {
header("Location:bacasoal.php");
exit;
}
?>
Also the bacasoal.php is too long so I just write the part of it:
<?php
session_start();
if(isset($_SESSION['submitsoal'])) {
if(isset($_SESSION['nomorsoal'])) {
$nomorsoal = $_SESSION['nomorsoal'];
$queryjudulnya = "SELECT nomorsoal,judul,soal FROM soal WHERE nomorsoal='".$nomorsoal."'";
$runqueryjudulnya = mysqli_query($konek,$queryjudulnya);
$countqueryjudulnya = mysqli_num_rows($runqueryjudulnya);
if($countqueryjudulnya != 0) {
$assocqueryjudulnya = mysqli_fetch_assoc($runqueryjudulnya);
$juduldatabase = mysqli_real_escape_string($assocqueryjudulnya['judul']);
$soaldatabase = mysqli_real_escape_string($assocqueryjudulnya['soal']);
$nomorsoaldatabase = mysqli_real_escape_string($assocqueryjudulnya['nomorsoal']);
} else {}
} else {}
} else {}
?>
<?php
if(isset($juduldatabase) && isset($nomorsoaldatabase)) {
echo "<div class=\"head-main-recent\"> ".$nomorsoaldatabase.$juduldatabase." </div>";
} else {
echo "<div class=\"head-main-recent\">Judul soal tidak ditemukan!</div>";
}
?>
bacasoal.php keep echo the fail statement "Judul soal tidak ditemukan!"
Does anyone know why? (live demo : http://english-lesson.16mb.com/)
You can do it like below so that if error is there then it will display or any how at-least some useful information will display:-
default.php:-
<form method="post" action="prosesbacasoal.php">
<div class="head-main-recenttest-result">
<input type="hidden" name="nomor" value="2">
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button>
</div>
</form>
prosesbacasoal.php:-
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
if(isset($_POST['nomor'])) {
$_SESSION['submitsoal'] = 'true';
$_SESSION['nomorsoal'] = $_POST['nomor'];
header("location:bacasoal.php");
exit;
} else {
header("location:default.php");
exit;
}
?>
bacasoal.php:-
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
$juduldatabase = '';
$soaldatabase = '';
$nomorsoaldatabase = '';
if(isset($_SESSION['submitsoal']) && isset($_SESSION['nomorsoal'])) {
$nomorsoal = $_SESSION['nomorsoal'];
$queryjudulnya = "SELECT nomorsoal,judul,soal FROM soal WHERE nomorsoal='".$nomorsoal."'";
echo $queryjudulnya;
$runqueryjudulnya = mysqli_query($konek,$queryjudulnya);
if($runqueryjudulnya){
$countqueryjudulnya = mysqli_num_rows($runqueryjudulnya);
if($countqueryjudulnya > 0) {
while($assocqueryjudulnya = mysqli_fetch_assoc($runqueryjudulnya)){
$juduldatabase = $assocqueryjudulnya['judul'];
$soaldatabase = $assocqueryjudulnya['soal'];
$nomorsoaldatabase = $assocqueryjudulnya['nomorsoal'];
}
} else {
echo "No matching record found";
}
}else{
echo "Query execution failed because of:-".mysqli_error($konek);
}
}else {
echo "Session variables are not set";
}
?>
<?php
if(isset($juduldatabase) && isset($nomorsoaldatabase)) {
echo "<div class="head-main-recent"> ".$nomorsoaldatabase.$juduldatabase."</div>";
} else {
echo "<div class="head-main-recent">Judul soal tidak ditemukan!</div>";
}
?>
Note:- if still no error and no records,then echo query and run that query manually in db and check any record are coming or not?
In 3rd line of your HTML code I can see </div> before form tag ending. I cant see dive start tag after form tag
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button> </div></form>
Replace by
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button></form>
it was php session problem , fixed it after i session_destroy(); it using logout.php
Related
i try to get a variable from header page to a game page.. but when i do it with include 'header.php" he excute the header code in game.php ( header("refresh"))
i wanna to excute the refresh one time in first page only
header.php code :
<?php
$memory = "ahmed";
echo "Remember This Word : " . $memory;
header("Refresh: 5; url= game.php");
// exit;
?>
game.php code :
<?php
// ob_start();
// include "header.php";
// ob_end_clean();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if($_POST['solution'] == "ahmed") {
$_SESSION['username'] = $_POST['solution'];
} else {
echo "Try again";
}
}
if(isset($_SESSION['username'])) {
echo "Well Done <br>";
echo ' Play again';
} else {
?>
<form action="" method="POST">
<input type="text" name="solution" id="">
<input type="submit" value="check">
</form>
<?php } ?>
I'm new to PHP and I'm trying to create an easy form that has multiple steps. For each step, a validation of the input is happening before the user is directed to the next page. If the validation fails, the user should stay on the same page and an error message should be displayed. In the end, all entries that the user has made should be displayed in an overview page.
What I have been doing to solve this, is to use a boolean for each page and only once this is true, the user can go to the next page. This is not working as expected unfortunately and I guess it has something to do with sessions in PHP... I also guess that there's a nicer way to do this. I would appreciate some help!
Here's my code:
<!DOCTYPE HTML>
<html>
<head>
<title>PHP Test</title>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
session_start();
$_SESSION['$entryOne'] = "";
$_SESSION['$entryOneErr'] = $_SESSION['$emptyFieldErr'] = "";
$_SESSION['entryOneIsValid'] = false;
$_SESSION['$entryTwo'] = "";
$_SESSION['$entryTwoErr'] = "";
$_SESSION['entryTwoIsValid'] = false;
// Validation for first page
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submitEntryOne'])) {
if (!empty($_POST["entryOne"])) {
// Check for special characters
$_SESSION['$entryOne'] = removeWhitespaces($_POST["entryOne"]);
$_SESSION['$entryOneErr'] = testForIllegalCharError($_SESSION['$entryOne'], $_SESSION['$entryOneErr']);
// If error text is empty set first page to valid
if(empty($_SESSION['$entryOneErr'])){
$_SESSION['$entryOneIsValid'] = true;
}
} else {
// Show error if field hasn't been filled
$_SESSION['$emptyFieldErr'] = "Please enter something!";
}
// Validation for second page
} else if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submitEntryTwo'])) {
if (!empty($_POST["entryTwo"])) {
// Check for special characters
$_SESSION['$entryTwo'] = removeWhitespaces($_POST["entryTwo"]);
$_SESSION['$entryTwoErr'] = testForIllegalCharError($_SESSION['$entryTwo'], $_SESSION['$entryTwoErr']);
// If error text is empty set second page to valid
if(empty($_SESSION['$entryTwoErr'])){
$_SESSION['$entryTwoIsValid'] = true;
}
} else {
// Show error if field hasn't been filled
$_SESSION['$emptyFieldErr'] = "Please enter something!";
}
}
//Remove whitespaces at beginning and end of an entry
function removeWhitespaces($data) {
$data = trim($data);
return $data;
}
//Check that no special characters were entered. If so, set error
function testForIllegalCharError($wish, $error){
$illegalChar = '/[\'\/~`\!##\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/';
if (preg_match($illegalChar,$wish)) {
$error = "Special characters are not allowed";
} else {
$error = "";
}
return $error;
}
?>
<?php if (isset($_POST['submitEntryOne']) && $_SESSION['$entryOneIsValid'] && !$_SESSION['$entryTwoIsValid']): ?>
<h2>Second page</h2>
<p>Entry from first Page: <?php echo $_SESSION['$entryOne'];?></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Entry Two: <input type="text" name="entryTwo" value="<?php echo $_SESSION['$entryTwo'];?>">
<span class="error"><?php echo $_SESSION['$entryTwoErr'];?></span>
<br><br>
<input type="submit" name="submitEntryTwo" value="Next">
</form>
<?php elseif (isset($_POST['submitEntryTwo']) && $_SESSION['$entryTwoIsValid']): ?>
<h2>Overview</h2>
<p>First entry: <?php echo $_SESSION['$entryOne'];?></p>
<p>Second Entry: <?php echo $_SESSION['$entryTwo'];?></p>
<?php else: ?>
<h2>First page</h2>
<span class="error"><?php echo $_SESSION['$emptyFieldErr'];?></span>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<br><br>
First entry: <input type="text" name="entryOne" value="<?php echo $_SESSION['$entryOne'];?>">
<span class="error"> <?php echo $_SESSION['$entryOneErr'];?></span>
<br><br>
<input type="submit" name="submitEntryOne" value="Next">
</form>
<?php endif; ?>
</body>
</html>
You are setting your session variables to "" at the top of your script.
Check if your variable is set before setting to blank.
Check if Session Variable is Set First
<?php
//If variable is set, use it. Otherwise, set to null.
// This will carry the variable session to session.
$entryOne = isset($_REQUEST['entryOne']) ? $_REQUEST['entryOne'] : null;
if($entryOne) {
doSomething();
}
?>
Tips
Then you can use <?= notation to also echo the variable.
Do this $_SESSION['variable'] instead of $_SESSION['$variable'] (you'll spare yourself some variable mistakes).
<h2>Second page</h2>
<p>Entry from first Page: <?= $entryOne ?></p>
Example Script
This could be dramatically improved, but for a quick pass:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
//Check that no special characters were entered. If so, set error
function hasIllegalChar($input){
$illegalChar = '/[\'\/~`\!##\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/';
if (preg_match($illegalChar, $input)) {
return true;
}
return false;
}
session_start();
// Destroy session and redirect if reset form link is pressed.
if(isset($_GET['resetForm']) && $_GET['resetForm'] == "yes")
{
echo "SESSION DESTROY";
session_destroy();
header("Location: ?");
}
// Session
$page = isset($_SESSION['page']) ? $_SESSION['page'] : 1;
$errors = [];
// Value history.
$valueOne = isset($_SESSION['valueOne']) ? $_SESSION['valueOne'] : null;
$valueTwo = isset($_SESSION['valueTwo']) ? $_SESSION['valueTwo'] : null;
// Clean inputs here
$fieldOne = isset($_REQUEST['fieldOne']) ? trim($_REQUEST['fieldOne']) : null;
$fieldTwo = isset($_REQUEST['fieldTwo']) ? trim($_REQUEST['fieldTwo']) : null;
// First form
if ($page == 1) {
// If field two is submitted:
if ($fieldOne) {
//Validate inputs
if(hasIllegalChar($fieldOne)) {
$errors[] = "You entered an invalid character.";
}
if (count($errors) == 0 ){
$valueOne = $_SESSION['valueOne'] = $fieldOne;
$page = $_SESSION['page'] = 2;
}
}
}
// Second form
else if ($page == 2) {
// If field two is submitted:
if ($fieldTwo) {
//Validate inputs
if(hasIllegalChar($fieldTwo)) {
$errors[] = "You entered an invalid character.";
}
if (count($errors) == 0 ){
$valueTwo = $_SESSION['valueTwo'] = $fieldTwo;
$page = $_SESSION['page'] = 3;
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>PHP Test</title>
<style>
.error {
color: #FF0000;
}
</style>
</head>
<body>
<?php
// troubleshoot
if (true) {
echo "<pre>";
var_dump($_REQUEST);
var_dump($_SESSION);
echo "</pre>";
}
echo "<h1>Page " . $page . '</h1>';
if (count($errors) > 0) {
$errorMsg = implode('<br/>',$errors);
echo '<div class="error">Some errors occurred:<br/>' . $errorMsg . '</div>';
}
?>
<?php if ($page == 3): ?>
<h2>Overview</h2>
<p>First entry: <?= $valueOne;?></p>
<p>Second Entry: <?= $valueTwo;?></p>
Reset
<?php elseif ($page == 2): ?>
<p>Entry from first Page: <?= $valueOne; ?></p>
<form method="post" action="<?= $_SERVER["PHP_SELF"] ?>">
Entry Two: <input type="text" name="fieldTwo" value="<?= $fieldTwo ?>" autofocus>
<br><br>
<input type="submit">
</form>
<?php else: ?>
<form method="post" action="<?= $_SERVER["PHP_SELF"] ?>">
<br><br>
Entry One: <input type="text" name="fieldOne" value="<?= $fieldOne; ?>" autofocus>
<br><br>
<input type="submit">
</form>
<?php endif; ?>
</body>
<html>
You can run the following command to test out the page without using a fancy tool like WAMP or LAMP.
php -S localhost:8000 index.php
You can now access in the browser at http://localhost:8000.
When the user submits a form, the PHP will check to see if the $post was empty, if so, it will set an $error_message variable; thus database INSERT query will not execute. I then attempt to show the error message further on in the code, however it will not display. I have been trying to figure this out for hours and I still cannot find the solution. The funny thing is, this used to work, however I must have implemented something in this file which is preventing the code to execute correctly.
Why is my error message not echoing to the screen (last few lines of code show attempt to echo the error_message)?
<?php require("inc/db.php"); ?>
<?php include("inc/functions.php"); ?>
<?php include ("inc/ChromePhp.php"); ?>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("html_errors", 1);
session_start();
if(!isset($_GET['id'])) {
header("Location: ?id=".getUserId($_SESSION['U_Email']));
}
if(isset($_SESSION["U_Email"])) {
$usersData = getUserInfo($_GET['id']);
$postCount = getPostCount($_GET['id']);
} else {
header('Location: login.php');
}
if($_SERVER["REQUEST_METHOD"] == "POST") {
$post = trim(filter_input(INPUT_POST,"user_post",FILTER_SANITIZE_SPECIAL_CHARS));
if($post == "") {
$error_message = "Please enter something before submitting";
}
if(!isset($error_message)) {
$post = $db->real_escape_string($post);
$postStore = $db->query("INSERT INTO `Post`(P_Body, P_Dateadded, User_U_ID) VALUES ('{$post}', NOW(), '{$_SESSION['U_ID']}' )");
}
}
$dashNav = true;
$cap = true;
$pageTitle = 'Profile';
$name = $usersData['U_Forename'] . " " . $usersData['U_Surname'];
$gender = $usersData['U_Gender'];
$bio = $usersData['U_Biography'];
$team = $usersData['U_Team'];
$city = $usersData['U_City'];
include("inc/header.php");
?>
<?php if(userExists($_GET['id'])) { ?>
<section>
<div class="wrapper">
<?php
if($_SESSION['U_ID'] != $_GET['id']) {
$testFollow = "SELECT `Following`.F_ID, `Following`.U_ID FROM `Following`
WHERE U_ID = '{$_SESSION['U_ID']}' AND F_ID = '{$_GET['id']}'";
$testFollowResult = $db->query($testFollow);
if ($testFollowResult->num_rows > 0) {
echo "<button class='lift' href='#'>Unfollow Driver</button>";
} else {
echo "<button class='lift' href='#'>Follow Driver</button>";
}
}
?>
<?php if (isset($error_message)) {
// This code will not echo!
echo "<h2>".$error_message."</h2>";
}
?>
</div>
<div class="section-b">
<div class="grid">
<div class="row">
<div class="col-wd-12">
<div class="col">
<form id="share" name="share" action="profile.php" method="post">
<textarea id="post" name="user_post" placeholder="What's happening?"> </textarea>
<span id="errorpost" class="error">You must input something something before sending</span>
<?php
echo "<div class='g-recaptcha' data- sitekey='6LfNTB0TAAAAAKEw9zfnFzvGCXF9MuYTkdB144x1
'></div>"; ?>
<button onclick="return postCheckValidate();" type="submit">Share</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
I have this form that I'm working with off a tutorial. I'm trying keep the fields populated when there is a validation error.
Here is my form:
<div class="add">
<?php $errors4 = errors_seesion_funtion(); ?>
<?php echo form_errors($errors4); ?>
<div class="error-message"><?php echo message(); ?></div>
<div class="done"><input name="Done" type="button" value="Done" /></div>
<h2>ADD New Department:</h2>
<form action="create-department-process.php" method="post">
<p class="department-name">Department name:
<input type="text" name="department_name" id="department-name" value="<?php if (isset($_POST['department_name'])) { echo htmlentities($_POST['department_name']); } ?>" />
<span class="error">* <?php if (!empty($errors4)) { echo "<div class=\"error\">";
echo "Hi";
echo "</div>";
}
?></span>
</p>
<p class="department-name">Test name:
<input type="text" name="test_name" id="test-name" value="" />
<span class="error">* <?php /*echo form_errors($errors4); */
if (!empty($errors4)) {
echo "<div class=\"error\">";
echo "test name";
echo "</div>";
}
?></span>
</p>
<input type="submit" name="dept_added" id="add-btn" value="ADD Department" />
</form>
<br />
<div class="cancel">Cancel</div>
Here is my Session:
session_start();
function message() {
if (isset($_SESSION["message"])) {
$output = "<div class='message'>";
$output .= htmlentities($_SESSION["message"]);
$output .= "</div>";
// clear message after use
$_SESSION["message"] = null;
return $output;
}
}
function errors_seesion_funtion() {
if (isset($_SESSION["errors3"])) {
$errors2 = $_SESSION["errors3"];
$_SESSION['post_data'] = $_POST;
// clear message after use
$_SESSION["errors3"] = null;
return $errors2;
}
}
Here is my Validation Functions:
$errors_array = array();
function fieldname_as_text($fieldname) {
$fieldname = str_replace("_", " ", $fieldname);
$fieldname = ucfirst($fieldname);
return $fieldname;
}
function has_presence($value) {
return isset($value) && $value !== "";
}
function validate_presences($required_fields) {
global $errors6;
foreach($required_fields as $field) {
$value = trim($_POST[$field]);
if (!has_presence($value)) {
$errors6[$field] = fieldname_as_text($field) . " can't be blank";
}
}
}
Here is my create-department-process.php
if (isset($_POST['dept_added'])) {
$department_name = mysql_prep($_POST["department_name"]);
//Validations for form
$required_fields = array("department_name", "test_name");
validate_presences($required_fields);
if (!empty($errors6)) {
$_SESSION["errors3"] = $errors6;
redirect_to("add-department.php"); //this is the page the form is on
}
// Process the form
$query1 = "INSERT INTO departments (";
$query1 .= " department_name ";
$query1 .= ") VALUES ( ";
$query1 .= " '{$department_name}' ";
$query1 .= ") ";
$result1 = mysqli_query($db_connection, $query1);
if ($result1) {
// Success
$_SESSION["message"] = "Department created.";
redirect_to("add-department.php");
} else {
// Failure
$_SESSION["message"] = "Department creation failed.";
redirect_to("creation-error.php");
}
} else {
redirect_to("fail.php");
}
I've tried to put this in the value of my form
<?php if (isset($_POST['department_name'])) { echo htmlentities($_POST['department_name']); } ?>
But the value I type in doesn't stay when PHP runs the form validation and redirects. Does anyone have any idea on how I can keep the data I type into the form fields when I have a validation error?
Thank you for your time and Help! I really appreciate it!
I think your POST data is getting lost when you do this:
if (!empty($errors6)) {
$_SESSION["errors3"] = $errors6;
redirect_to("add-department.php"); //this is the page the form is on
}
I'm guessing redirect_to actually redirects your browser to the specified page, therefore resetting the REQUEST values and losing the pervious POST data. You either need to save the POST values in the session (a la errors_seesion_funtion) and access them from there in your form, or include the form above to preserve the original POST values.
I have a problem with php & mysql, insert to database using utf-8.
first file:
addsite:
<?php
include 'header.php';
if(isset($data)) {
foreach($_POST as $key => $value) {
$posts[$key] = filter($value);
}
if(isset($posts['type'])){
if($posts['url'] == "http://" || $posts['url'] == ""){
$error = "Add your page link!";
}else if($posts['title'] == ""){
$error = "Add your page title!";
}else if(!preg_match("/\bhttp\b/i", $posts['url'])){
$error = "URL must contain http://";
}else if(!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $posts['url'])){
$error = "Please do not use special characters in the url.<";
}else{
include "plugins/" . $posts['type'] . "/addsite.php";
}
}
?>
<div class="contentbox">
<font size="2">
<li>Pick the type of exchange you are promoting from the dropdown menu.</li>
<li>Set the amount of coins you wish to give per user complete(CPC).</li>
<li>The higher the amount of coins the higher the Links position.</li>
</div>
<div class="contentbox">
<div class="head">Add Site</div>
<div class="contentinside">
<?php if(isset($error)) { ?>
<div class="error">ERROR: <?php echo $error; ?></div>
<?php }
if(isset($success)) { ?>
<div class="success">SUCCESS: <?php echo $success; ?></div>
<?php }
if(isset($warning)) { ?>
<div class="warning">WARNING: <?php echo $warning; ?></div>
<?php } ?>
<form class="contentform" method="post">
Type<br/>
<select name="type"><?php $select = hook_filter('add_site_select', ""); echo $select; ?></select><br/><br/>
Link<br/>
<input name="url" type="text" value="<?php if(isset($posts["url"])) { echo $posts["url"]; } ?>"/><br/><br/>
Title<br/>
<input name="title" type="text" value="<?php if(isset($posts["title"])) { echo $posts["title"]; } ?>"/><br/><br/>
Cost Per Click<br/>
<?php if($data->premium > 0) { ?>
<select name="cpc"><?php for($x = 2; $x <= $site->premcpc; $x++) { if(isset($posts["cpc"]) && $posts["cpc"] == $x) { echo "<option selected>$x</option>"; } else { echo "<option>$x</option>"; } } ?></select><br/><br/>
<?php }else{ ?>
<select name="cpc"><?php for($x = 2; $x <= $site->cpc; $x++) { if(isset($posts["cpc"]) && $posts["cpc"] == $x) { echo "<option selected>$x</option>"; } else { echo "<option>$x</option>"; } } ?></select><br/><br/>
<?php } ?>
<input style="width:40%;" type="Submit"/>
</form>
</div>
</div>
<?php
}
else
{
echo "Please login to view this page!";
}
include 'footer.php';
?>
second file , plugin addsite.php
<?php
$num1 = mysql_query("SELECT * FROM `facebook` WHERE `url`='{$posts['url']}'");
$num = mysql_num_rows($num1);
if($num > 0){
$error = "Page already added!";
}else if(!strstr($posts['url'], 'facebook.com')) {
$error = "Incorrect URL! You must include 'facebook.com'";
}else{
mysql_query($qry);
mysql_query("INSERT INTO `facebook` (user, url, title, cpc) VALUES('{$data->id}', '{$posts['url']}', '{$posts['title']}', '{$posts['cpc']}') ");
$success = "Page added successfully!";
}
?>
when i write arabic language in the form and submit ,
it went to database with unkown language like :
أسÙ
database collaction : utf8_general_ci
<?php
error_reporting(E_ALL);
ini_set('display_errors', '0');
$host = "localhost"; // your mysql server address
$user = "z*******"; // your mysql username
$pass = "m********"; // your mysql password
$tablename = "z*******"; // your mysql table
session_start();
$data = null;
if(!(#mysql_connect("$host","$user","$pass") && #mysql_select_db("$tablename"))) {
?>
<html>
MSQL ERROR
<?
exit;
}
include_once 'functions.php';
require_once "includes/pluggable.php";
foreach( glob("plugins/*/index.php") as $plugin) {
require_once($plugin);
}
hook_action('initialize');
$site = mysql_fetch_object(mysql_query("SELECT * FROM settings"));
?>
add this line:
mysql_query("SET NAMES 'utf8'");
Like this
if(!(#mysql_connect("$host","$user","$pass") && #mysql_select_db("$tablename"))) {
?>
<html>
MSQL ERROR
<?
exit;
}
else{
mysql_query("SET NAMES 'utf8'");
}
Also:
- Add meta charset to the form page
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
or HTML5
<meta charset='utf-8'>