I attempted PHP and MySQL for the first time today following a tutorial, I was told using $MySQL was outdated and told to use $mysqli which I've attempted. I've uploaded my page to my server on ipage but am only getting a white screen. Its likely there's an error in my code, the server runs sql 5.5.32. The thing is I'm not even getting the echo back messages in Internet Explorer.
Edited with a bind / edited with 'db_table to 'db_table' /added form
<?php
//Database Setup
$mysqli_db = new mysqli($db_host,$db_name,$db_username,$db_password);
function webmailSignUp()
{
$webmailFullName = $_POST['webmailFullName'];
$webmailName = $_POST['webmailUserName'];
$webmailExEmail = $_POST['webmailExEmail'];
$webmailPhone = $_POST['webmailPhone'];
$webmailDOB = $_POST['webmailDOB'];
//Check that the fields are not empty
if ((!empty($webmailFullName)) or (!empty($webmailName)) or (!empty($webmailExEmail)) or (!empty($webmailPhone)) or (!empty($webmailDOB)))
{
//Check that there is no existing name in the table
if (checkUser($userName) == false)
{
//Adding the person to the Database Query
$query = "INSERT INTO '$db_table'(userFullName,userName,userExEmail,userPhone,userDOB) VALUES(?,?,?,?,?)";
//Binding to Prevent SQL injection
$requery = $mysqli_db->prepare($query);
$requiry->bind_param($webmailFullName,$webmailName,$webmailExEmail,$webmailPhone,$webmailDOB);
if ($requery->execute())
{
echo "Person has been added";
}
else
{
echo "bind failed";
}
}
else
{
echo "There is already a user registered with this username. Please try a different one.";
}
}
else
{
echo "One of your fields are blank! Please try again";
}
}
function checkUser($userNameCheck)
{
//Check the field userName is the same as the Posted Username
$Field = "userName"; //The Field to check
$query = "SELECT '$Field' WHERE '$Field'='$webmailName' FROM '$db_table' LIMIT 1";
$result = mysqli_query($query, $mysqli_db) or die(mysql_error());
if (!$row = mysqli_fetch_array($result) or die(mysql_error()))
{
return false; //username was not found in the field in the table
}
else
{
return true; //username was found in the field in the table
}
}
function close()
{
$mysqli_db->close();
}
//Main Code Sequence
error_reporting(-1);
ini_set('display_errors',1);
if(isset($_POST['webmailRegisterButton']))
{
echo("firstbit");
webmailSignUp();
close();
echo "End of Registration";
}
if(isset($_POST['webamilForgottenPWSubmit']))
{
webmailForgottenPassword();
close();
echo "End of Password Reset Request";
}
?>
Form:
<form method="POST" action="../_webmail/mailDB.php">
<div class="popupTitleCell"><h3>Name:</h3></div>
<div class="popupInputCell"><input type="text" name="webmailFullName" class="popupInputField"></div>
<div class="popupSpacer2"><p>Your Full Name (ex. John Coles)</p></div>
<div class="popupTitleCell"><h3>UserName:</h3></div>
<div class="popupInputCell"><input type="text" name="webmailUserName" value="#allcoles.com" class="popupInputField"></div>
<div class="popupSpacer2"><p>Preference email (ex john#allcoles.com)</p></div>
<div class="popupSpacer"><hr></div>
<div class="popupTitleCell"><h3>Existing Email:</h3></div>
<div class="popupInputCell"><input type="text" name="webmailExEmail" class="popupInputField"></div>
<div class="popupSpacer2"><p>REQUIRED to recieve SignIn details</p></div>
<div class="popupTitleCell"><h3>Phone Number:</h3></div>
<div class="popupInputCell"><input type="text" name="webmailPhone" class="popupInputField"></div>
<div class="popupSpacer2"><p>(allows for SMS confirmation)</p></div>
<div class="popupTitleCell"><h3>Date of Birth:</h3></div>
<div class="popupInputCell"><input type="text" id="datepickerRegister" name="webmailDOB"></div>
<div class="popupSpacer2"><p>Select your DOB from the calender</p></div>
<div class="popupSpacer"><hr></div>
<div class="popupButtonCell">
<button type="submit" name="webmailRegisterSubmit" value="register" id="submitButton" class="popupButton">
<span>Register</span></button></div>
</form>
Any help would be appreciated.
Can you also put the code of the form you are using to submit data on this file. Because if you directly open this file no code will be execute. Also please try this
<?php
//Main Code Sequence
error_reporting(-1);
ini_set('display_errors',1);
//Database Setup
$db_host = "localhost";
$db_name = "test";
$db_table = "emailUser";
$db_username = "root";
$db_password = "";
$mysqli_db = new mysqli($db_host,$db_username,$db_password, $db_name);
function webmailSignUp()
{
$webmailFullName = $_POST['webmailFullName'];
$webmailName = $_POST['webmailUserName'];
$webmailExEmail = $_POST['webmailExEmail'];
$webmailPhone = $_POST['webmailPhone'];
$webmailDOB = $_POST['webmailDOB'];
//Check that the fields are not empty
if ((!empty($webmailFullName)) or (!empty($webmailName)) or (!empty($webmailExEmail)) or (!empty($webmailPhone)) or (!empty($webmailDOB)))
{
//Check that there is no existing name in the table
if (checkUser($userName) == false)
{
//Adding the person to the Database Query
$query = "INSERT INTO '$db_table(userFullName,userName,userExEmail,userPhone,userDOB) VALUES($webmailFullName,$webmailName,$webmailExEmail,$webmailPhone,$webmailDOB)";
echo "Person has been added";
}
else
{
echo "There is already a user registered with this username. Please try a different one.";
}
}
else
{
echo "One of your fields are blank! Please try again";
}
}
function checkUser($userNameCheck)
{
//Check the field userName is the same as the Posted Username
$Field = "userName"; //The Field to check
$query = "SELECT '$Field' WHERE '$Field'='$webmailName' FROM '$db_table' LIMIT 1";
$result = mysqli_query($query, $mysqli_db) or die(mysql_error());
if (!$row = mysqli_fetch_array($result) or die(mysql_error()))
{
return false; //username was not found in the field in the table
}
else
{
return true; //username was found in the field in the table
}
}
function close()
{
$mysqli_db->close();
}
if(isset($_POST['webmailRegisterButton']))
{
echo("firstbit");
webmailSignUp();
close();
echo "End of Registration";
}
if(isset($_POST['webamilForgottenPWSubmit']))
{
webmailForgottenPassword();
close();
echo "End of Password Reset Request";
}
?>
Related
I have two tables in one database. The first one is the g1 where the buttons' data is located. The second is the gradeone, where the enrollees' data is located. I want to display the data from the table "gradeone" by clicking the
specific buttons.
Assuming that I added 2 sections. Section 1 and section 2. I click the button section1. By clicking it, I want to display the data of the enrollee from table "gradeone" where the section is 1.
<?php
$dsn = 'mysql:host=localhost;dbname=admin';
$username = 'root';
$password = '';
try{
// Connect To MySQL Database
$con = new PDO($dsn,$username,$password);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $ex) {
echo 'Not Connected '.$ex->getMessage();
}
$sectionnumber ="";
$datasuccess ="";
$error ="";
function getPosts(){
$posts = array();
$posts[1] = $_POST['sectionnumber'];
return $posts;
}
if(isset($_POST['add'])){
$data = getPosts();
if(empty($data[1])){
$error = 'Enter The User Data To Insert';
}else {
$insertStmt = $con->prepare('INSERT INTO g1(sectionnumber) VALUES(:sectionnumber)');
$insertStmt->execute(array(
':sectionnumber'=> $data[1]
));
if($insertStmt){
$datasuccess = "<font color='#f8234a'>New added</font>";
}
}
}
?> //Code for adding a button
<?php
require 'connection.php';
$sql = "SELECT sectionnumber FROM g1";
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<button type='button' class='btn'>Section " . $row["sectionnumber"] . "</button></a><hr>";
}
} else { echo "<B>No Sections</B>"; }
$con->close();
?> //Code for displaying the button
<html>
<body>
<form action=">
<input type="number" name="sectionnumber">
<input type="submit" name="add">
</form>
</body>
</html>
//This has been driving me nuts lol.. code to execute below. i am trying to exit the script if one if statement is true, and continue if it is false
<?php
require('includes/config.php');
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$selectQuery = "SELECT username, email, tokens, tokenstatus, tokensinc, tokenstatus1, tokenswith, tokenstatus2 FROM members WHERE username = '".($_SESSION['username']) ."'";
$updateQuery = "UPDATE members SET tokens=tokens - 10, tokenstatus='(Pending Tokens)' ,tokenswith=tokenswith + 10, tokenstatus1='(Pending Tokens)' WHERE username = '".($_SESSION['username']) ."'";
// Create connection
$db = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
//if not logged in redirect to login page
if(!$user->is_logged_in()) { header('Location: login.php'); exit(); }
//define page title
$title = 'Withdraw ~ Pixel Jag';
//include header template
require('layout/header.php');
?>
<div class="container">
<div class="panel panel-default">
<?php
$result = mysqli_query($db, $selectQuery);
if (mysqli_num_rows($result) > 0) {
// output data of each row
echo "<ul class='list-group'>";
while($row = mysqli_fetch_assoc($result)) {
//the if statement below is the code to execute, if this returns true i want it to exit script, if its false i want it to continue to update//
if ($row['tokens'] < 10) {
echo "<li class='list-group-item list-group-item-danger'>You do not have enough tokens!</li>";
}
}
echo "</ul>";
}
//see below for code i wish to execute instead if the above is returned false//
if (mysqli_query($db, $updateQuery)) {
echo "<ul class='list-group'><li class='list-group-item list-group-item-success'><h4>Record updated successfully!</h4></li></ul>";
} else {
echo "Error updating record: " . mysqli_error($db);
}
mysqli_close($db);
?>
<div class="panel-footer">
<h4>Back To Dashboard..</h4>
</div>
</div>
</div>
<?php
//include header template
require('layout/footer.php');
?>
please just put a flag $isValid with the default value is true
$isValid = true;
while(mysqli_num_rows($result) > 0 || $isValid) {
if ($row['tokens'] < 10) {
echo "<li class='list-group-item list-group-item-danger'>You do not have enough tokens!</li>";
$isValid = false;
}
}
alright if the flag is true do the update
The best way would be, in my opinion, if you are within a function or method, using a return; statement.
function some(){
if(true){
return;
}
else{
//do other stuff
if(true){
return;
}
}
}
But there are also a lot of ways in php to interrupt execution. You are indeed using some of those.
die;
exit;
throw new Exception('some error');//we need an exception handler in this case
then:
if ($row['tokens'] < 10) {
echo "<li class='list-group-item list-group-item-danger'>You do not have enough tokens!</li>";
die;// or exit or return if you are within a function o method
}
PROBLEM: I got a problem updating my input into sql using PHP, the PHP updates all empty values into sql which I don't want to.
ACHIEVEMENT: So I hope to achieve when user submit their data either empty or filled then PHP might be able to pickup and update only filled data into my sql. I tried using input with value=">php echo here<" but it won't work with textarea, so I couldn't find any solution since I'm new to PHP and SQL. Tried to find similar posts but I couldn't make them work like I wanted to :(
<?php include 'config/sqlconnect.php'; ?>
<form method="post" action"config/sqlconnect.php">
</p>MainPage info</p>
<input type="text" name="mainPageInfo"/>
<br>
</p>MiddlePage info</p>
<textarea name="middlePageInfo"></textarea>
<br>
</p>Container info</p>
<input type="text" name="containerInfo"/>
<br>
</p>Content</p>
<input type="text" name="content"/>
<br>
</p>Second content</p>
<input type="text" name="secondContent"/>
<input type="submit" name="submit" class="btn-block"/>
<br>
</form>
in PHP script
<?php
$servername = "localhost";
$username = "root";
$password = "pass";
$dbname = "pagesDb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysqli_set_charset($conn,"utf8");
$sql = "SELECT * FROM myPages";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$mainPageInfo = $row['mainPageInfo'];
$middlePageInfo = $row['middlePageInfo'];
$containerInfo = $row['containerInfo'];
$content = $row['content'];
$secondContent = $row['secondContent'];
}
} else {
echo "0 results";
}
if (isset($_POST['submit'])) {
$mainPageInfo = $_POST['mainPageInfo'];
$middlePageInfo = $_POST['middlePageInfo'];
$containerInfo = $_POST['containerInfo'];
$content = $_POST['content'];
$secondContent = $_POST['secondContent'];
$sql = "UPDATE myPages SET mainPageInfo='$mainPageInfo',
middlePageInfo='$middlePageInfo',
containerInfo='$containerInfo',
content='$content',
secondContent='$secondContent'
WHERE id=0";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
}
$conn->close();
?>
Second Attempts: It doesn't update my data somehow... please help I tried more than 8 hours with no results :(
if (isset($_POST['submit'])) {
foreach($_POST as $name => $value) {
$sql = "UPDATE myPages SET $name = '$value' WHERE id=1";
}
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
}
Help would be appreciated, thanks everyone!
Using your Second Attempt as a starting point.
The problem with just using the POST array without being specific is that, in this example you are going to try an update a column on the database called submit i.e. your submit button. Later there may be data on the page that belongs in 2 or more tables.
So create an controlling array containing all the field names from the form that you want to process onto your table.
$db_fields = array('mainPageInfo', 'middlePageInfo', 'containerInfo',
'content', 'secondContent');
$sql = ''; // will hold the query we build dynamically
// was this a user sending data
if ( $_SERVER['REQUEST_METHOD' == 'POST' ) {
foreach($db_fields as $fieldname) {
if ( ! empty($_POST[$fieldname] ) {
$sql .= "$fieldname = '{$_POST[$fieldname]}', ";
}
}
}
$sql = rtrim($sql, ','); // remove the trailing comma
$sql = "UPDATE myPages SET $sql WHERE id=1";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
I would like to write a logic for data validation before insert into database. If the data not valid, then it will prompt user errors, but then I facing problem which not the logic that I wish:
(1) Message "Data successfully inserted!" shown even the error checking message was prompt.
(2) Message "Data successfully inserted!" shown even no data was entered in the form then click submit.
How should I change the logic to the one that I wish to have?
<?php
// Initialize variables to null.
$comp_nameError ="";
$compLicenseeNameError ="";
if(isset($_POST['comp_name'])) {$comp_name= $_POST['comp_name'];}
if(isset($_POST['comp_licensee_name'])) {$comp_licensee_name= $_POST['comp_licensee_name'];}
//On submitting form below function will execute
if (isset($_POST['submit'])) {
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//-------------------------Form Validation Start---------------------//
if (empty($_POST["comp_name"])) {
$comp_nameError = "Name is required";
} else {
$comp_name = test_input($_POST["comp_name"]);
// check name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$comp_name)) {
$comp_nameError = "Only letters and white space allowed";
}
}
if (empty($_POST["comp_licensee_name"])) {
$compLicenseeNameError = "Company Licensee Name is required";
} else {
$comp_licensee_name = test_input($_POST["comp_licensee_name"]);
}
//-------------------------Form Validation End---------------------//
// attempt a connection
$host="host=xx.xx.xx.xx";
$port="port=xxxx";
$dbname="dbname=xxxx";
$credentials="user=xxxxxx password=xxxxxxx";
$dbh = pg_connect("$host $port $dbname $credentials");
if (!$dbh) {
die("Error in connection: " . pg_last_error());
}
// execute query
$sql = "INSERT INTO t_comp(comp_name, comp_licensee_name)VALUES('$comp_name', '$comp_licensee_name')";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
echo "Data successfully inserted!";
// free memory
pg_free_result($result);
// close connection
pg_close($dbh);
}
//php code ends here
?>
<html>
<head>
<link rel="stylesheet" href="style/style.css" />
</head>
<body>
<div class="maindiv">
<div class="form_div">
<form method="post" action="compReg.php">
<span class="error">* required field.</span>
<br>
<hr/>
<br>
Company Name:<br><input class="input" type="text" name="comp_name" value="">
<span class="error">* <?php echo $comp_nameError;?></span>
<br>
Company Licensee:<br><input class="input" type="text" name="comp_licensee_name" value="">
<span class="error">* <?php echo $compLicenseeNameError;?></span>
<br>
<input class="submit" type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
I'd accumulate the errors into an array, and proceed to the insert part only if it's empty:
$errors = array();
if (empty($_POST["comp_name"])) {
$errors[] = "Name is required";
} else {
$comp_name = test_input($_POST["comp_name"]);
// check name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$comp_name)) {
$errors[] = "Only letters and white space allowed in the computer name";
}
}
if (empty($_POST["comp_licensee_name"])) {
$errors[] = "Company Licensee Name is required";
} else {
$comp_licensee_name = test_input($_POST["comp_licensee_name"]);
}
if (!empty($errors)) {
echo "The following errors occurred:<br/>" . implode('<br/>', $errors);
exit();
}
// If we didn't exit, continue to the insertion code
<?php
// Initialize variables to null.
$comp_nameError ="";
$compLicenseeNameError ="";
if(isset($_POST['comp_name'])) {$comp_name= $_POST['comp_name'];}
if(isset($_POST['comp_licensee_name'])) {
$comp_licensee_name= $_POST['comp_licensee_name'];}
//On submitting form below function will execute
if (isset($_POST['submit'])) {
// check boolean variable value
$is_valid = 1;
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//-------------------------Form Validation Start---------------------//
if (empty($_POST["comp_name"])) {
$comp_nameError = "Name is required";
} else {
$comp_name = test_input($_POST["comp_name"]);
// check name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$comp_name)) {
$validation_error = "Only letters and white space allowed";
$is_valid = 0;
}
}
if (empty($_POST["comp_licensee_name"])) {
$validation_error = "Company Licensee Name is required";
$is_valid =0;
} else {
$comp_licensee_name = test_input($_POST["comp_licensee_name"]);
}
//-------------------------Form Validation End---------------------//
// attempt a connection
if($is_valid == 1 ){
$host="host=xx.xx.xx.xx";
$port="port=xxxx";
$dbname="dbname=xxxx";
$credentials="user=xxxxxx password=xxxxxxx";
$dbh = pg_connect("$host $port $dbname $credentials");
if (!$dbh) {
die("Error in connection: " . pg_last_error());
}
// execute query
$sql = "INSERT INTO t_comp(comp_name, comp_licensee_name)VALUES('$comp_name', '$comp_licensee_name')";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
echo "Data successfully inserted!";
// free memory
pg_free_result($result);
// close connection
pg_close($dbh);
} else {
echo $validation_error;
die;
}
}
//php code ends here
?>
This question already has answers here:
Issue with PHP MySQL and insert into UTF-8 [closed]
(3 answers)
Closed 10 years ago.
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"));
?>
after removing
$posts[$key] = filter($value); "
from header.php
The output shift from:
To:
& Oslash; & pound; & Oslash; ³& Ugrave
to : Ù Ù Ù
header file : http://zwdha.com/header.txt
You might need to add some ini_set statements if your db is full utf8: http://www.polak.ro/php-mysql-utf-8.html
This a very basic insert query to see if you can insert data in you database with PHP.
<?php
function inserting_data() {
$host = "host";
$user = "username";
$password = "password";
$database = "database";
$charset = "utf8";
$link = mysqli_connect($host, $user, $password, $database);
mysql_set_charset($charset, $link);
IF (!$link) {
echo('Unable to connect to the database!');
} ELSE {
/*
* this just to test if something gets inserted into your table.
* If some of your columns are set to not null you should add them tot this insert query.
*/
$query = "INSERT INTO facebook (`title`) VALUES('test_title'), ('test_title1')";
mysqli_query($link, $query);
}
mysqli_close($link);
}
?>
This is a very basic select query to retrieve data form your database.
<?php
function selecting_data(){
$host = "host";
$user = "username";
$password = "password";
$database = "database";
$charset = "utf8";
$link = mysqli_connect($host, $user, $password, $database);
mysql_set_charset($charset, $link);
IF (!$link) {
echo('Unable to connect to the database!');
} ELSE {
/*
* this just to test if something gets returned from your table.
*/
$query = "SELECT * FROM facebook";
$result = mysqli_query($link, $query);
while ($rows = mysqli_fetch_array($result, MYSQLI_BOTH)){
echo $rows['title'];
}
}
mysqli_close($link);
}
?>
My advise is to first test if you can get data in your database and retrieve it. By trial and error you will need to solve your question. B.T.W. I have used MYSQLI_ function instead of MYSQL. The mysql_ functions will depreciate soon. Hope this helps.
a - you should not use mysql_ functions. use PDO. this error is one of the reasons.
b - mysql_set_charset('utf8');
c - are the columns you are trying insert data using utf8_general_ci ?
d - on my.cf set default-character-set and character-set-server
if this doesn't work read this:
http://www.oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html
and this:
http://www.phpwact.org/php/i18n/utf-8
if after that you still dont get it right, make sure to listen to people and use PDO.