The code below searches employees on basis of employee number entered in textbox or first name but I have the first name in Arabic and it is not matching. Image is attached which shows priperly arabic on broser but not it is searched by textbox I dont know why
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Search Contacts</title>
<link rel="stylesheet" href="css/insert.css" />
<link rel="stylesheet" href="css/navcss.css" />
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<div class="maindiv">
<?php include("includes/head.php");?>
<?php include("menu.php");?>
<!--HTML form -->
<div class="form_div">
<h3>Search Records:</h3>
<p>You may search by Employee Number</p>
<form method="post" action="search.php?go" id="searchform">
<input type="text" class="input" name="emp_number">
<input type="submit" class="input" name="submit" value="Search">
</form>
<?php
include 'connect-db.php';
//do something here in code
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[a-zA-Z0-9,]+$/", $_POST['emp_number'])){
//if(preg_match("/\p{Arabic}/u", $_POST['first_name'])){
$emp_number=$_POST['emp_number'];
//$first_name=$_POST['first_name'];
//connect to the database
//$db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
//$mydb=mysql_select_db("mydb");
//-query the database table
//mysqli_query($connection,"SET CHARACTER SET utf8");
$sql="SELECT * FROM employees WHERE emp_number LIKE '%" . $emp_number . "%' OR first_name LIKE '%" . $emp_number."%'";
//-run the query against the mysql query function . $name .
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName =$row['first_name'];
echo "<table border='1' cellpadding='10'>";
echo "<tr><th>First Name</th> <th>Last Name</th><th>Employee Number</th><th>Department</th><th>Email</th><th>Total Printers</th><th>Total Scanners</th><th>Total PCs</th><th>Total Telephones</th></tr>";
//-display the result of the array
echo "<tr>";
echo '<td>' . $row['first_name'] . '</td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['emp_number'] . '</td>';
echo '<td>' . $row['department'] . '</td>';
echo '<td>' . $row['email'] . '</td>';
echo '<td>' . $row['total_printers'] . '</td>';
echo '<td>' . $row['total_scanners'] . '</td>';
echo '<td>' . $row['total_pc'] . '</td>';
echo '<td>' . $row['total_phones'] . '</td>';
echo '<td class="forscreen">View</td>';
echo '<td class="forscreen">Edit</td>';
echo '<td class="forscreen">Delete</td>';
echo '<td class="forscreen">View Accessories</td>';
echo '<td class="forscreen">Add Accessories</td>';
//echo '<button class="btnPrint" type="submit" value="Submit" onclick="window.print()">Print</button>';
//echo '<button class="btnPrevious" type="submit" value="Submit" onclick="history.back(); return false;">Return to previous page</button>';
/*echo "<ul>\n";
echo "<li>" . "" .$FirstName . "</li>\n";
echo "</ul>"; */
echo "</tr>";
}
// close table>
echo "</table>";
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
<div class="forscreen">
<br />
<button class="btnPrint" type="submit" value="Submit" onclick="window.print()">Print</button>
<button class="btnPrevious" type="submit" value="Submit" onclick="history.back(); return false;">Return to previous page</button>
</div>
</div>
</div>
</body>
</html>
You should check your database tables default collation. I often work with korean charachters and I always make sure everything is set tu utf8. (HTML / PHP headers and DB tables collation).
This may not be required in modern versions of PHP, but on the very first line of your file, add the following:
<?php
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
?>
Related
In command line, sqlite correctly displays the accented characters contained in my database.
In PHP, echo shows me correctly as well.
But when I do a query from my PHP page, it does not display correctly. I can not find where the encoding problem is.
Thank you in advance for your help.
<?php
$db = new SQLite3('database.sqlite');
if(isset($_GET['search'])) {
$rec = htmlentities($_GET['search']);
} else {
$rec = '';
}
$result3 = $db->query('SELECT lastname,firstname,phone,location FROM rh WHERE name != "" AND lastname || " " || firstname || " " || location LIKE "%'.$rec.'%" ORDER BY name asc LIMIT 25');
?>
The HTML form :
<form action="" method="get">
<input type="search" name="search" value="<?php echo $rec; ?>" /> <input type="submit" value="Search" />
</form>
And the results on another php page :
<?php
echo '<h3>Results</h3>';
echo '<tr><th>Name</th><th>Phone</th><th>Location</th></tr>';
while ($row = $result3->fetchArray(SQLITE3_ASSOC)) {
echo '<tr><td>' . $row['lastname'] . ' ' . $row['firstname'] . '</td><td>' . $row['phone'] . '</td><td>' . $row['location'] . '</td></tr>';
}
$db->close();
?>
Maybe you need to specify the propper encoding in your HTML-Head e.g.:
<html>
<head>
<meta charset="utf-8">
...
</head>
And/or you need to de/encode your data before output utf8_encode();.
I've been trying to display the image I uploaded into the db using a simple insertform. I've only been able to retrieve the image-name into the "data-file", what I'm wondering is how can I easily display the image in the same form location instead of the image-name?
This is my result at this moment, as you can see I've only added an image to one of the inserts, and I would like to change the "footer.jpg-name" with the image displayed here.
<html>
<head>
</head>
<body>
<form action="insertform.php" method="post">
Topic: <input type="text" name="topic"><br />
Name: <input type="text" name="name"><br />
Attendance: <input type="text" name="attendance"><br />
Image: <input type="file" name="image"><br />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$con = mysql_connect("localhost","username","password");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("testingisfun",$con);
$sql = "INSERT INTO Lectures (Topic,Name,Attendance,Image) VALUES ('$_POST[topic]', '$_POST[name]', '$_POST[attendance]', '$_POST[image]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>
</body>
</html>
Heres the "data-file".
<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("testingisfun",$con);
$sql = "SELECT * FROM lectures";
$myData = mysql_query($sql,$con);
echo "<table border = 1>
<tr>
<th>Topic</th>
<th>Name</th>
<th>Attendance</th>
<th>Image</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<tr>";
echo "<td>" . $record['Topic'] . "</td>";
echo "<td>" . $record['Name'] . "</td>";
echo "<td>" . $record['Attendance'] . "</td>";
echo "<td>" . $record['Image'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
Thanks for any sort of feedback!
Try this
echo "<td><img src='/{$record['Image']}'>" . $record['Image'] . "</td>";
I took this answer from linked answer that I had put in comments. There are other alternatives also provided for this problem.
echo "<td>" . $record['Image'] . "</td>";
replace with
echo "<td><img src=\"data:image/jpeg;base64,"" . base64_encode( $record['Image'] ) . "/></td>";
You are storing images in DB and while fetching it is giving you image data that is raw so to display images from data you can use this method.
This wont help in caching but it will solve the problem.
I have been trying to make an online gateway for my college, where staff can nominate students for particular post or prizes. I used php with css for front end and phpmyadmin for back end. But once i give the input(regno) to nominate a student, it doesn't update in the table. Can anyone help? This is my code:
<!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>NOMINATE ENTRIES</title>
<meta author="" content="">
<link rel="stylesheet" type="text/css" href="view.css" media="all">
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>Nominate Entries</a></h1>
<form name="form5" class="appnitro" method="post" action="test.php">
<div class="form_description">
<center><h2>Students Database</h2></center>
<p><center><font size='3'>
<?php
$con=mysqli_connect("localhost","staff","12345","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM `student` WHERE `Nominated` = 0");
echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Department   </th>
<th>Name       </th>
<th>Class   </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['RegNo'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
if(isset($_POST['submit']))
{
$regno = $_POST['regno'];
$reason = $_POST['reason'];
$sql = "UPDATE `mop`.`student` SET `Nominated` = \'1\' WHERE `student`.`RegNo` = 1106103;";}
mysqli_close($con);
?>
</center></font>
</p>
</div>
<b>Enter Register Number <font color='red'>*</font> </b> <input type="text" id="regno" name="regno"><br>
<b>Enter Reason <font color='red'>*</font> </b> <input type="text" id="reason" name="reason"><br>
<ul >
<center><li class="buttons">
<input type="hidden" name="form_id" value="768845" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center>
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
You didn't actually send your query.
$result = $connection -> query($sql);
// Or, since it is only an update
$connection -> query($sql);
Where $connection is the connection to your DB
i have changed the whole file like this sir. thanks all for ur input wanted to share it for others:
here is my form.php file:
<!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>NOMINATE ENTRIES</title>
<meta author="" content="">
<link rel="stylesheet" type="text/css" href="view.css" media="all">
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>Nominate Entries</a></h1>
<form name="form" class="appnitro" method="post" action="test.php">
<div class="form_description">
<center><h2>Students Database</h2></center>
<p><center><font size='3'>
<?php
$con=mysqli_connect("localhost","staff","123456","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM student");
echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Name       </th>
<th>Department   </th>
<th>Class   </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['RegNo'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</center></font>
</p>
</div>
<b>Enter Register Number <font color='red'>*</font> </b> <input type="text" name="regno"><p>
<b>Enter Reason <font color='red'>*</font> </b> <input type="text" name="reason"><p>
<ul >
<center><li class="buttons">
<input type="hidden" name="form_id" value="768845" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center>
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
it refers to the test.php file and here is that file too:
<?php
$con=mysqli_connect("localhost","staff","123456","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql1="UPDATE student SET Reason = '$_POST[reason]' WHERE RegNo ='$_POST[regno]'";
if (!mysqli_query($con,$sql1))
{
die('Error: ' . mysqli_error($con));
}
else
{
$sql2="INSERT INTO nominated select * from student where regno = '$_POST[regno]'";
if (!mysqli_query($con,$sql2))
{
die('Error: ' . mysqli_error($con));
}
else
{
$sql3="DELETE from student where regno = ".intval($_POST["regno"]);
if (!mysqli_query($con,$sql3))
{
die('Error: ' . mysqli_error($con));
}
}
}
header("location:form5_1.php");
mysqli_close($con);
?>
THIS IS MY CODE HERE I AM GETTING PROBLEM THIS IS A INPUT TYPE TAG AND NOT SELECTED DATA FROM DATABASE USING PHP.
here is first part of this code is html formatted ad second part is php
i want select data from database to data slect to same page as we see on the sopping cart sites
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>phpSelect</title>
</head>
<body>
Insert Age for search
<form action="#" method="post" >
<input type="text" id="val" name="resValue" />
<input type="submit" value="submit" /></form>
<?php
if(isset($_POST['submit']))
{
$res=$_POST['resValue'];
echo $res;
}
//echo $res;
$con=mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons where Age=25");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Try changing the SQL to this
SELECT * FROM Persons where Age='".mysql_escape_string($formValue['val'])."'
First issue I found on your code is here:
<input type="submit" value="submit" />
it should be:
<input type="submit" value="submit" name="submit" />
To be able to get the results. Below are the codes:
<?php
$query = "";
if(isset($_POST['submit']))
{
$res=$_POST['resValue'];
$query = " where Age='$res'"
}
//echo $res;
$con=mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons $query");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Change your select query to this one.
SELECT * FROM Persons where Age='".mysql_escape_string($_POST['val'])."'
In your problem the all value of form get by the name of all fields of form.\
so here should be
<input type="submit" name="submit" value="submit"/>
Because in $_POST['submit'] submit is same as button's name.
$result = mysqli_query($con,"SELECT * FROM Persons where Age="25");
In the below code the list box is getting populated with the values but when I select the corresponding list value and click search the table is not getting displayed. I have used the SELF_PHP for the form action here also the idea of this form is that the list will be having and id's populated while the loading of the page. When I select a list value and click on the search button it should display the table with the values of only that ambulance ID or id which has been selected in the list box. Please help me.
<!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 charset="utf-8">
<title>TPS Login Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<center>
<h2>Ambulance Activity Log</h2>
<hr>
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
View activity of ambulance:
<Select NAME="field">
<?php
include 'con.php';
$query = "SELECT amb_id FROM ambulance;";
$result = mysql_query($query) or die("Unable to retreive amb_id :".mysql_error());
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo"<option id=\"ambid\" value=$row[amb_id]>$row[amb_id]</option>";
}
}
?>
</Select>
<input class="btn btn-info" type="submit" name="search" value="Search" />
<input type="hidden" name="searching" value="yes" />
</form>
<?php
if(isset($_POST['submit']))
{
$id=getElementById('ambid') ;
$query = "SELECT * FROM log WHERE amb_id='$id' ORDER BY l_time DESC;";
$result = mysql_query($query) or die(mysql_error());
print "
<table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"800\" text-align=\"center\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\">
<tr>
<td width=\"30\">Amb ID</td>
<td width=\"120\">Event Time</td>
<td width=\"50\">Description</td>
<td width=\"30\">Signal ID</td>
<td width=\"30\">Road No</td>
<td width=\"30\">Priority</td>
</tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "<tr>";
print "<td>" . $row['amb_id'] . "</td>";
print "<td>" . $row['l_time'] . "</td>";
print "<td>" . $row['l_event'] . "</td>";
print "<td>" . $row['t_sigid'] . "</td>";
print "<td>" . $row['l_roadno'] . "</td>";
print "<td>" . $row['e_priority'] . "</td>";
print "</tr>";
}
print "</table>";
print "</center>";
}
?>
</body>
</html>
Please help me.
Thanks in advance :)
Give the <select> Tag a better name . And quote your "$row[amb_id]". value=$row[amb_id] ! is wrong.
<select name="ambid" size="10">
....
{
echo"<option value=\"$row[amb_id]\">$row[amb_id]</option>";
}
</select>
After post you can get it with :
if(isset($_POST['submit']))
{
$id=$_POST['ambid'];
$query = "...