I have a problem, obviosly with php script.
I am trying to get some data from mssql but I am getting an error:
Warning: mssql_query() [function.mssql-query]: message: Unicode data
in a Unicode-only collation or ntext data cannot be sent to clients
using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.
(severity 16) in /var/www/mssql_test_saop.php on line 63
Warning: mssql_query() [function.mssql-query]: Query failed in
/var/www/mssql_test_saop.php on line 63 Rezultati za:
SELECT * FROM VseClaniceISPAPDokument
This is structure of table VseClaniceISPAPDokument
([NazivPU] [nvarchar](20) NULL,
[MesObr] [nvarchar](20) NULL,
[LetoObr] [nvarchar](20) NULL,
[IspapXML] [xml] NULL)
This is php script:
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="windows-1250">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
table * {
font-family: "Arial Narrow";
font-size: 10px;
}
</style>
</head>
<body>
<pre><?
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = '10.10.10.110:51541';
// Connect to MSSQL
$link = mssql_connect($server, 'tinem', '****');
$db = "saopsf"; //skupna
//$db = "saopopn013";
if (!$link || !mssql_select_db($db, $link)) {
die('Unable to connect or select database!' . mssql_get_last_message());
}
// Do a simple query, select the version of
// MSSQL and print it.
$version = mssql_query('SELECT ##VERSION');
$row = mssql_fetch_array($version);
print_r($row);
// Clean up
mssql_free_result($version);
?>
</pre>
<?
function run_sql($sql) {
$query = mssql_query($sql);
echo "Rezultati za: <pre>$sql</pre>";
echo mssql_num_rows($query). " vrstic<br>";
if (mssql_num_rows($query) > 0) {
//$data = mssql_fetch_assoc($data);
?>
<table border="1" style="font-size: 10;font-family: arial;">
<tr>
<?
for ($i = 0; $i < mssql_num_fields($query); ++$i) {
$field = mssql_fetch_field($query, $i);
echo "<th>".$field->name."</th>";
}
?>
</tr>
<?
while ($row = mssql_fetch_assoc($query)) {
echo "<tr>";
foreach($row as $field) {
echo "<td>" . $field . "</td>";
}
echo "</tr>";
}
?>
</table>
<?
}
mssql_free_result($query);
}
run_sql("SELECT * FROM VseClaniceISPAPDokument");
?>
Any help? Thanks in advance
Related
I get data from a mssql database that I want to display in a table.
The table has three categories:
ORDER NUMBER
PAYMENT STATUS
ORDER STATUS
The problem is as follows:
I would like to align my order numbers with the payment status and the order status in order to have a nice table that is well aligned.
Here is my code in php and the result it gives me :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/clientsS.css">
<title></title>
</head>
<body>
<div class="BLOC1">
<div class="NUMBER">
<center><table>
<tr>
<th>NUMERO COMMANDE</th>
<th>STATUT PAIEMENT</th>
<th>STATUT COMMANDE</th>
</tr>
<tr>
<td><?php
//CONNEXION ODBC SERVER//
$dsn="";
$user="";
$password="";
$conn=odbc_connect($dsn
,$user, $password);
//REQUETES
$sql = <<<EOF
SELECT top 10 [enc_cmd_num]
FROM [encaissement]
WHERE enc_date= '20221220'
EOF;
$results = odbc_exec($conn,$sql);
while($resultrow = odbc_fetch_array($results)){
echo $resultrow["enc_cmd_num"]."<br/>" ; }
?>
</td>
</div>
<div class="TITRE">
<td><?php
//CONNEXION ODBC SERVER//
$dsn="";
$user="";
$password="";
$conn=odbc_connect($dsn,$user, $password);
//REQUETES
$sql = <<<EOF
SELECT top 10 [enc_paye]
FROM [encaissement]
WHERE enc_date= '20221220'
EOF;
$results = odbc_exec($conn,$sql);
//CONDITION
while($resultrow = odbc_fetch_array($results)) {
switch($resultrow['enc_paye']){
case 0:
echo "<p>En attente paiement</p> \r\n";
break;
case 1:
echo "<p class='green'>Commande payée<p/>\r\n";
break;
}
}
?>
</td>
<td><?php
//CONNEXION ODBC SERVER//
$dsn="";
$user="";
$password="";
$conn=odbc_connect($dsn,$user, $password);
//REQUETES
$sql = <<<EOF
SELECT top 10 [enc_prepared]
FROM [encaissement]
WHERE enc_date= '20221220'
EOF;
$results = odbc_exec($conn,$sql);
//CONDITION
while($resultrow = odbc_fetch_array($results)) {
switch($resultrow['enc_prepared']){
case 0:
echo "<p>Commande en attente</p> \r\n";
break;
case 1:
echo "<p class='yellow'>Commande en cours de préparation<p/>\r\n";
break;
}
}
?>
</td>
</tr>
</table>
</div>
It is preferable that you use the same tag <p> even for the first <td>:
Test it like this and tell me if it works for you:
echo "<p>".$resultrow["enc_cmd_num"]."<p/>" ;
Instead of:
echo $resultrow["enc_cmd_num"]."<br/>" ;
Unfortunately my code isn't working quite well.
The source code:
<!DOCTYPE html>
<html>
<head>
<title>Query data from News database and display in table</title>
<meta charset="UTF-8">
<meta name="description" content="" />
<meta name="author" content="WRBikAir" />
<meta name="keywords" content="" />
<style>
table, th, td{
border: 1px solid black;
}
</style>
</head>
<body>
<?php
error_reporting(E_ALL);
echo "Test 1";
$con = mysqli_connect("mysql.hostinger.com","u441817146_admin","CBGApp","u441817146_cbg");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM News";
if ($result = mysqli_query($con, $sql)) {
echo "<table>";
while($row = $result->fetch_assoc()) {
$r = json_encode($row);
echo "<tr><td>" . $r['NID'] . "</td><td>" . $r['headline'] . "</td><td>" . $row['text'] . "</td><td>" . $r['timestamp'] . "</td></tr>";
}
echo "</table>";
} else {
echo "no result.";
}
mysqli_close($con);
echo "2";
?>
</body>
</html>
Everything works fine, except of the output of the NID, headline and timestamp. There are all '{'. Does it mean, that there is now value? because if I simply print them out (encoded of course) there are values e.g.:
{"NID":"1","headline":"Testartikel 2","text":"test test test","timestamp":"15.11.2017, 18:13"}
Does somebody knows a solution?
You are using $result 2 times on $result = mysqli_query($con, $sql) and in your foreach loop. I changed the one in the foreach loop to $results instead of $result.
Also try turning on error reporting using:
error_reporting(E_ALL);
Try using:
<!DOCTYPE html>
<html>
<head>
<title>Query data from News database and display in table</title>
<meta charset="UTF-8">
<meta name="description" content="" />
<meta name="author" content="WRBikAir" />
<meta name="keywords" content="" />
<style>
table, th, td{
border: 1px solid black;
}
</style>
</head>
<body>
<?php
echo "Test 1";
$con = mysqli_connect(CENSORED (but working in other classes fine);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM News";
if ($result = mysqli_query($con, $sql)) {
$resultArray = array();
$tempArray = array();
while($row = $result->fetch_object()) {
$tempArray = $row;
array_push($resultArray, $tempArray);
}
echo "<table>";
foreach ($resultArray as $results) {
$r = json_encode($results);
echo "<tr><td>" . $results['headline'] . "</td><td>" . $results['text'] . "</td></tr>";
}
echo "</table>"
}
mysqli_close($con);
echo "2";
?>
</body>
</html>
For everybody who need the working answer.
Thank you to MasterOfCoding, GrumpyCrouton, Paul Spiegel and prodigitalson.
Special thanks to tadman for the insider information.
Now the code:
<!DOCTYPE html>
<html>
<head>
<title>Query data from News database and display in table</title>
<meta charset="UTF-8">
<meta name="description" content="" />
<meta name="author" content="WRBikAir" />
<meta name="keywords" content="" />
<style>
table, th, td{
border: 1px solid black;
}
</style>
</head>
<body>
<?php
error_reporting(E_ALL);
echo "Test 1";
$con = mysqli_connect("...","...","...","...");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM News";
if ($result = mysqli_query($con, $sql)) {
echo "<table>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['NID'] . "</td><td>" . $row['headline'] . "</td><td>" . $row['text'] . "</td><td>" . $row['timestamp'] . "</td></tr>";
}
echo "</table>";
} else {
echo "no result.";
}
mysqli_close($con);
echo "2";
?>
</body>
</html>
So I was importing some MySQL Rows into a form but there seems to be an issue, the database doesnot connects, it says no database selected, I have my Database connection parameters in constants.php and they are working fine in the other pages of the website, and there is no syntax error in the commands either, Help me please.Thanks!
<?php
require_once 'classes/Membership.php';
require_once 'includes/constants.php';
$membership = New Membership();
$membership->confirm_Member();
$con = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or
die('Error connecting Database');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>Post Scores | Admin Panel D2C</title>
<style type="text/css">
</style>
</head>
<body>
<div class="main_body">
<table width="1029" border="0" cellpadding="0" class="score_table" >
<td width="131">
<form align="center" action="update_team_database.php" method="post">
<tr>
<td> Team: </td>
<td width="831">
<?php
$result = mysql_query("select DISTINCT TeamName from team") or die(mysql_error());
echo '<select name="teamname1"><OPTION>';
echo "Select a team</OPTION>";
while ($row = mysql_fetch_array($result)){
$team1 = $row["TeamName"];
echo "<OPTION value=\"$team1\">$team1</OPTION>";
}
echo '</SELECT>';
?></td>
</tr>
</form>
</table>
</body>
</html>
I would recommend you make use of Object Oriented way of performing queries over MySQL using MySQLi
You may check the example in here
http://in2.php.net/manual/en/mysqli.query.php
Since MySQL is deprecated as of PHP 5.5
I just started a project with a new client and have run into an issue that I haven't had before.
I've moved a copy of their site to my local machine (running the latest version of mamp) and I got their database set up with no issue.
The main pages load fine, but after I log in and am taken to the admin dashboard (a custom cms), clicking on any link causes the page to hang and timeout.
I've narrowed the issue down to the initial call to session_start() on the subpages and removing it and any code that references the session data allows the pages to load.
The site did not have a php.ini file.
I've googled around and found several suggestions of using session_write_close() at the end of each file, and before redirection. I've tried this and still get the timeout.
I've noticed that when I log in the session is created without issue in the mamp/tmp/php folder on my mac, and the dashboard page that loads can be refreshed (calling session_start() again) without the page timing out.
Also, once I try to load any other page in the admin (causing the timeout) I can no longer access the dashboard page because it begins to timeout to. I then have to delete the session file to regain access to any pages that start a session.
Here is the dashboard page code, I don't see anything in there that should cause the next page to load to have a session issue (I'm not looking for best-practices suggestions, I literally just inherited this codebase).
<?php
session_start();
if(basename($_SERVER['PHP_SELF'])!="index.php") {
if(!isset($_SESSION['is_logged_in'])) {
header("Location:index.php");
die();
}
}
?>
<!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" xml:lang="en" lang="en">
<head>
<title>RVC Admin: Dashboard</title>
<?php
include "includes/connect.php";
include "includes/headers.php";
?>
</head>
<body>
<div id='main'>
<?php
include "includes/menu.php";
?>
<h1>RVC Admin System</h1>
<?php
$result = mysql_query("SELECT COUNT(ID) as HOWMANY FROM listings");
if(#mysql_num_rows($result)>0) {
$row = mysql_fetch_assoc($result);
$LISTINGS = number_format($row['HOWMANY']);
}
$result = mysql_query("SELECT COUNT(id) as HOWMANY FROM user");
if(#mysql_num_rows($result)>0) {
$row = mysql_fetch_assoc($result);
$ADMINS = number_format($row['HOWMANY']);
}
print "<p>There are ".$LISTINGS." listings in the system, and ".$ADMINS." admins.</p>";
$result = mysql_query("SELECT description FROM LGBTlevel ORDER BY description");
if(#mysql_num_rows($result)>0) {
print "<div style='float: left; padding-right: 30px;'><p>Levels:</p>";
print "<ul style='margin: 2px 0 5px 18px; padding: 0;'>";
while($row = mysql_fetch_row($result)) {
print "<li style='margin-bottom: 2px;'>".$row[0]."</li>";
}
print "</ul></div>";
}
$result = mysql_query("SELECT description FROM LGBTtype ORDER BY description");
if(#mysql_num_rows($result)>0) {
print "<div style='float: left; padding-right: 30px;'><p>Types of Listings:</p>";
print "<ul style='margin: 2px 0 5px 18px; padding: 0;'>";
while($row = mysql_fetch_row($result)) {
print "<li style='margin-bottom: 2px;'>".$row[0]."</li>";
}
print "</ul></div>";
}
print "<br style='clear: left;' />";
?>
<?php session_write_close(); ?>
<br style='clear: both;' /><br />
</div>
</body>
</html>
Here is the connect.php file (actual access info removed)
<?php
$testing_server = true;
if($testing_server != true){
$MYSQL_USER_NAME = "removed";
$MYSQL_PASSWORD = "removed";
$MYSQL_DATABASE_NAME = "removed";
$dbh=mysql_connect ("localhost", "$MYSQL_USER_NAME", "$MYSQL_PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$MYSQL_DATABASE_NAME");
$db = new mysqli('localhost', "$MYSQL_USER_NAME", "$MYSQL_PASSWORD", "$MYSQL_DATABASE_NAME");
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
} // if testing server != true
else{
$MYSQL_USER_NAME = "removed";
$MYSQL_PASSWORD = "removed";
$MYSQL_DATABASE_NAME = "removed";
$dbh=mysql_connect ("localhost", "$MYSQL_USER_NAME", "$MYSQL_PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$MYSQL_DATABASE_NAME");
$db = new mysqli('localhost', "$MYSQL_USER_NAME", "$MYSQL_PASSWORD", "$MYSQL_DATABASE_NAME");
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
}//else, testing server credentials
?>
Here is the headers file
<meta name='robots' content='noindex,nofollow' />
<meta name='author' content='removed' />
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta name='MSSmartTagsPreventParsing' content='TRUE' />
<meta http-equiv='imagetoolbar' content='no' />
<link rel='stylesheet' type='text/css' href='css/styles.css' />
<link type="text/css" href="css/custom-theme/jquery-ui-1.9.1.custom.css" rel="stylesheet" />
<script type='text/javascript' src='includes/javascript/jquery-1.8.1.min.js'></script>
<script type="text/javascript" src="includes/javascript/jquery-ui-1.9.1.custom.min.js"> </script>
<link href='https://fonts.googleapis.com/css?family=Cantora+One' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Cabin+Condensed' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Condensed' rel='stylesheet' type='text/css'>
Aaand here is the menu file
<?php
#MENU
?>
<form method='post' action='index.php' style='float: right; margin: 0 0 0 10px;'><input type='hidden' name='RVC_LOGOUT' value='TRUE' /><input type='image' title='Logout' src='images/icon-logout.png' /></form>
<a href='admin-users.php' title='Manage Users'><img src='images/icon-users.png' border='0' alt='Manage Users' style='float: right; margin: 0 0 0 10px;' /></a>
<a href='listings.php' title='Edit Listings'><img src='images/icon-listings.png' border='0' alt='Edit Listings' style='float: right; margin: 0 0 0 10px;' /></a>
<a href='dashboard.php' title='Home'><img src='images/icon-home.png' border='0' alt='Home' style='float: right; margin: 0 0 0 10px;' /></a>
If anyone can see any reason that this page should load fine the after logging in and then cause every page that uses a session to timeout after trying to leave it, your help would be appreciated.
clicking any link in the menu file causes the page to timeout at the first line, which as I said is the session_start();
EDIT:
I reduced one of the sub pages to just the session_start call and it still causes the browser to time out.
I am a newcomer and have just started building a website.. I wrote the following code but its not working.it is not connecting to the database..If not this is there any other way to connect dreamweaver to postgresql ...please help..thnx in advance
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="span6">
<table class="table table-striped">
<thead>
<tr>
<th>Scheme-ID</th>
<th>Scheme Name</th>
<th>Scheme Type</th>
</tr>
</thead>
<tbody>
<?PHP
$conn = pg_connect("host=localhost port=5432 dbname=egram user=postgres password=password") or die("unable to connect to database");
if ($conn)
{
echo ("Connection attempt succeeded.");
}
else {
echo ("Connection attempt failed.");
}
$sql = "SELECT scheme_id,scheme_name,scheme_type FROM schemes";
$result = pg_query($conn,$sql); //order executes
if($result)
{
echo("query ran successfully");
while($data = pg_fetch_row($result))
{
echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td></tr>");
}
}
else
{
echo("error in running query");
}
?>
</tbody>
</table>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
#
</body>
</html>