I am trying to access data on a mySQL server, but due to my age and alzheimer's I seem to be overlooking the obvious mistake here. Anyone care to spare a couple of minutes to help. -
<?
-
$host = "localhost";
-
$user = "root";
-
$pass = "";
-
$dbname = "wxoww";
-
$datatbl= "tbl_owwdata";
-
-
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error());
-
-
mysql_select_db ($dbname);
-
-
$sql = ("SELECT * FROM $datatbl ORDER BY qtm LIMIT 1") ;
-
-
$query = mysql_query($sql);
-
echo'<table border="0" width="100%">';
-
while ($row = mysql_fetch_array($query)) {
-
echo'<tr>
-
<td width="8%">'.$row["qtm"].'</td>
-
<td width="8%">'.$row["t1"].'</td>
-
<td width="8%">'.$row["t2"].'</td>
-
<td width="8%">'.$row["dp"].'</td>
-
<td width="8%">'.$row["rh"].'</td>
-
<td width="8%">'.$row["bp"].'</td>
-
<td width="8%">'.$row["wdspd"].'</td>
-
<td width="8%">'.$row["wdgst"].'</td>
-
<td width="8%">'.$row["wddir"].'</td>
-
<td width="8%">'.$row["rn"].'</td>
-
<td width="8%">'.$row["rnd"].'</td>
-
<td width="8%">'.$row["rnrt"].'</td>
-
</tr>'
-
}
-
-
echo'</table>';
-
-
?>
-
The resulting page if I bring it up in a browser has this on it -
'; while ($row = mysql_fetch_array($query)) { echo' '.$row["qtm"].' '.$row["t1"].' '.$row["t2"].' '.$row["dp"].' '.$row["rh"].' '.$row["bp"].' '.$row["wdspd"].' '.$row["wdgst"].' '.$row["wddir"].' '.$row["rn"].' '.$row["rnd"].' '.$row["rnrt"].' ' } echo''; ?>
-
It suggests to me that the $query is at fault, but the sql query is correct I think ... duh isn't it ...??
Many thanks
7 2141
If you get this type of output to the browser, try to put <?php instead of <?
I get an empty screen with this, what have I missed -
<?php
-
$host = "localhost";
-
$user = "wxoww";
-
$pass = "password";
-
$dbname = "wxoww";
-
$datatbl= "tbl_owwdata";
-
-
$connection = mysql_connect($host,$user,$pass);
-
-
if(!$connection) "" {
-
die('Could not connect: ' . mysql_error());
-
}
-
-
mysql_select_db($dbname);
-
-
$sql =("SELECT * FROM $datatbl ORDER BY qtm DESC LIMIT 1");
-
-
$query = mysql_query($sql);
-
-
while($row = mysql_fetch_array($query)) {
-
echo $row['qtm']" "$row['t1']" "$row['t2'];
-
}
-
?>
-
Essentially what this returns is the last record in the database, the sql query works fine in other query browser type applications but not in the php file on the server.
I have a file wxdataload.php which inserts the data into the mysql database just fine, using an output parser from an application called OWW. -
<?php
-
$host = "localhost" ;
-
$user = "wxoww" ;
-
$pass = "zaq11qaz" ;
-
$db = "wxoww";
-
$dbf = "tbl_owwdata" ;
-
-
// Parse query string from URL and put into an array
-
// This part fetches the part after the "?" from the URL.
-
$data = "$_SERVER[QUERY_STRING]";
-
-
// echo "$data <br />"; //test returns query string
-
-
//Break query string into parts delimited by the "&" (key=val)
-
-
$query_string = explode( '&', $data );
-
// echo "$query_string <br />"; //test returns "Array"
-
-
$args = array( ); // return array
-
// echo "$args <br />" //test returns "Array"
-
-
//Loop through the array, break at "=",
-
-
foreach( $query_string as $chunk )
-
{
-
$chunk = explode( '=', $chunk );
-
-
list( $key, $val ) = $chunk;
-
-
// echo "$key $val <br />"; //test returns keys and their assosiated values
-
-
/*
-
****************************************************
-
For each iteration of the loop test for key, create
-
a variable and set its value to the one associated with it.
-
These values are used to update the database.
-
***************************************************
-
*/
-
-
switch ($key):
-
-
case ($key == "qtm"):
-
global $qtm;
-
$qtm = $val;
-
break;
-
-
case ($key == "t1"):
-
global $t1;
-
$t1 = $val;
-
break;
-
-
case ($key == "t2"):
-
global $t2;
-
$t2 = $val;
-
break;
-
-
case ($key == "t3"):
-
global $t3;
-
$t3 = $val;
-
break;
-
-
case ($key == "dp"):
-
global $dp;
-
$dp = $val;
-
break;
-
-
case ($key == "rh"):
-
global $rh;
-
$rh = $val;
-
break;
-
-
case ($key == "bp"):
-
global $bp;
-
$bp = $val;
-
break;
-
-
case ($key == "wdspd"):
-
global $wdspd;
-
$wdspd = $val;
-
break;
-
-
case ($key == "wdgst"):
-
global $wdgst;
-
$wdgst = $val;
-
break;
-
-
case ($key == "wddir"):
-
global $wddir;
-
$wddir = $val;
-
break;
-
-
case ($key == "wddeg"):
-
global $wddeg;
-
$wddeg = $val;
-
break;
-
-
case ($key == "wdchill"):
-
global $wdchill;
-
$wdchill = $val;
-
break;
-
-
case ($key == "wdpnt"):
-
global $wdpnt;
-
$wdpnt = $val;
-
break;
-
-
case ($key == "rn"):
-
global $rn;
-
$rn = $val;
-
break;
-
-
case ($key == "rnd"):
-
global $rnd;
-
$rnd = $val;
-
break;
-
-
case ($key == "rnrt"):
-
global $rnrt;
-
$rnrt = $val;
-
break;
-
-
case ($key == "rnint"):
-
global $rnint;
-
$rnint = $val;
-
break;
-
-
case ($key == "c1"):
-
global $c1;
-
$c1 = $val;
-
break;
-
-
case ($key == "cd1"):
-
global $cd1;
-
$cd1 = $val;
-
break;
-
-
case ($key == "iadc1"):
-
global $iadc1;
-
$iadc1 = $val;
-
break;
-
-
case ($key == "vadc1"):
-
global $vadc1;
-
$vadc1 = $val;
-
break;
-
-
case ($key == "sol1"):
-
global $sol1;
-
$sol1 = $val;
-
break;
-
-
endswitch;
-
$args[ $key ] = urldecode( $val );
-
}
-
// connect to the database
-
$con = mysql_connect("$host","$user","$pass");
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
// select the database
-
mysql_select_db("$db", $con) or die ("error selecting db");
-
// Insert values into the fields in the database
-
mysql_query("INSERT INTO $dbf (qtm, t1, t2, t3, dp, rh, bp, wdspd, wdgst, wddir, wddeg, wdchill, wdpnt, rn, rnd, rnrt, rnint, c1, cd1, iadc1, vadc1, sol1 ) VALUES ('$qtm','$t1','$t2','$t3','$dp','$rh','$bp','$wdspd','$wdgst','$wddir','$wddeg','$wdchill','$wdpnt','$rn','$rnd','$rnrt','$rnint','$c1','$cd1','$iadc1','$vadc1','$sol1')");
-
-
mysql_close($con);
-
-
?>
-
The output parser was adapted from code supplied by others in the weather data community.
What I wish to do is create a web page that can read the data from the Database server. Not having a lot of luck. Any one know of a good data based web development tutorial for me to get stuck into.
Atli 5,058
Recognized Expert Expert
Hi.
Just to explain dumm's suggestion.
The short-tags you using in your original example, <? ... ?>, are not enabled by default in PHP5. Therefore, unless you specifically configure your PHP installation to work with the short-tags, PHP will not interpret the code as PHP code and simply send it as plain text, rather than executing it.
That is why you should always use the <?php ... ?> tags. They never fail.
As to your code, there two things I see wrong with the code itself.
The extra quote-marks you have after the if statement in line #10, and the incorrectly formatted string you try to echo in line #21.
They should be producing an error. (Try turning on the debug messages)
Once that is fixed, if the page continues to return no results, it would indicate that your database is in fact not returning any results.
If that is the case, try printing the actual query your code executes before it is executed and see if it looks like it should look.
Many thanks ...
I got a basic line of data as per the plan however I would now like to present it in table form. This code produces the line, you will see that the commented out line however do not. -
<?php
-
error_reporting(E_ALL);
-
ini_set('display_errors', true);
-
-
$host = "localhost";
-
$user = "wxoww";
-
$pass = "password";
-
$dbname = "wxoww";
-
$datatbl= "tbl_owwdata";
-
-
$connection = mysql_connect($host,$user,$pass);
-
-
if(!$connection) {
-
die('Could not connect: ' . mysql_error());
-
}
-
-
mysql_select_db($dbname);
-
-
$sql =("SELECT * FROM $datatbl ORDER BY qtm DESC LIMIT 1");
-
-
$query = mysql_query($sql);
-
while($dd = mysql_fetch_array($query))
-
{
-
//echo <table border=1 align=center>
-
// echo <tr>;
-
// echo <td>$dd['qtm']</td>;
-
// echo <td>$dd['t1']</td>;
-
// </tr>;
-
// echo </table>;
-
-
echo $dd['qtm'], $dd['t1'], $dd['t2'], $dd['t3'], $dd['dp'], $dd['rh'], $dd['bp'], $dd['wdspd'], $dd['wdgst'], $dd['wddir'], $dd['rn'], $dd['rnd'], $dd['rnrt'], $dd['iadc1'];
-
echo "<br />";
-
}
-
-
-
?>
-
@Atli Atli 5,058
Recognized Expert Expert
That would probably be because your strings are not quoted. -
// This is incorrect:
-
echo <div class="whatever">$row['something']</h1>;
-
-
// It should be:
-
echo '<div class="whatever">'. $row['something'] .'</h1>';
-
-
// Or: (Note how the quotes that are meant to be printed are escaped)
-
echo "<div class=\"whatever\">{$row['something']}</h1>";
-
-
// Or if you have a lot of output, you can also do:
-
echo <<<HTML
-
<div class="whatever">{$row['something']}</div>
-
<span>Some more HTML</span>
-
<span>etc...</span>
-
HTML;
-
You could probably avoid all these basic syntax errors if you read through a good PHP tutorial real quick. Like say, this one.
Many thanks for the advice. Below is the resulting code -
<?php
-
error_reporting(E_ALL);
-
ini_set('display_errors', true);
-
$host = "localhost";
-
$user = "wxoww";
-
$pass = "password";
-
$dbname = "wxoww";
-
$datatbl= "tbl_owwdata";
-
$connection = mysql_connect($host,$user,$pass);
-
if(!$connection) {
-
die('Could not connect: ' . mysql_error());
-
}
-
mysql_select_db($dbname);
-
$sql =("SELECT * FROM $datatbl ORDER BY qtm DESC LIMIT 20");
-
$query = mysql_query($sql);
-
echo "<table class=\"sample\">";
-
echo "<th width =\"12%\">Date/Time</th>";
-
echo "<th width =\"5%\">Temp</th>";
-
echo "<th width =\"5%\">Indoor</th>";
-
echo "<th width =\"5%\">Dew</th>";
-
echo "<th width =\"5%\">Humid</th>";
-
echo "<th width =\"5%\">Baro</th>";
-
echo "<th width =\"5%\">Wind</th>";
-
echo "<th width =\"5%\">Gust</ch>";
-
echo "<th width =\"5%\">Direction</th>";
-
echo "<th width =\"5%\">Rain</ch>";
-
echo "<th width =\"5%\">Daily mm</th>";
-
echo "<th width =\"5%\">Intensity/Hr</th>";
-
while($dd = mysql_fetch_array($query))
-
{
-
echo "<p class=\"sample\">";
-
echo "<tr>";
-
echo "<td width =\"12%\">$dd[qdat]</td>";
-
echo "<td width =\"5%\">$dd[t1]</td>";
-
echo "<td width =\"5%\">$dd[t3]</td>";
-
echo "<td width =\"5%\">$dd[dp]</td>";
-
echo "<td width =\"5%\">$dd[rh]</td>";
-
echo "<td width =\"5%\">$dd[bp]</td>";
-
echo "<td width =\"5%\">$dd[wdspd]</td>";
-
echo "<td width =\"5%\">$dd[wdgst]</td>";
-
echo "<td width =\"5%\">$dd[wddir]</td>";
-
echo "<td width =\"5%\">$dd[rn]</td>";
-
echo "<td width =\"5%\">$dd[rnd]</td>";
-
echo "<td width =\"5%\">$dd[rnrt]</td>";
-
echo "</tr>";
-
echo "</p>";
-
}
-
echo "</table>";
-
-
?>
-
An online page using this code in it can be found at Clyde Weather which will redirect to the page with the data on it.
I have provided the above code that it might help anyone starting out as I am.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: F. Biguet |
last post by:
Hello,
I want to create a generic script that connects to Oracle databases
(from 7.3.4 to 9.2 version) with a guest user. This script should
return 1 if connection is successful and 0 if not.
My problem is due to the 3 requests for password when the connection
fails. I can't find any option that allows to ask for password only
one time.
Has anyone already written a such script?
|
by: Randell D. |
last post by:
HELP!
I am determined to stick with this... I'm getting there... for those who
haven't read my earlier posts, I'm createing what should be a simple
function that I can call to check that required fields in a form have
values. I'm writing the values to the client using document.write only so
that I can confirm that the values are there to be played with - this is not
the final result so please (unless it's leading to the script failure)...
|
by: Kenneth |
last post by:
Hello,
I'm having some serious problems debugging a script that I'm trying to make
work. I'm working on a form where a user can type in a time (in the format
of HH:MM), and another script automatically calculate how much time is
inbetween.
That part of it is working fine, but what ISN'T working fine is the script
that validates whether or not the user has entered the time in proper
syntax, and to make sure that the Time In does not...
|
by: nielsonj1976 |
last post by:
I am getting a failure on the db backup job of one of my maintenance
plans. It is coming back with the generic error message of,
"sqlmaint.exe failed. (Error 22029). The step
failed."
I then checked the Database Maintenance Plan History page, but this
shows all the steps having run successfully. If I check the drives for
the actual backup files, they exist and look healthy too!
|
by: cy |
last post by:
Hi all,
I would appreciate it if anyone could point me on this.
My JSP page has 3 select boxes for states, counties and, cities and the
counties and cities should be populated once the user chooses a state and so
forth for the cities too.
I will need to get the data from an Oracle database.
Thanks so much in advance.
| |
by: calaha |
last post by:
Hi all,
I have been working with this since last night, and can't quite figure out
why it's not working. I have a simple login box form that is set to be my
startup form in my Access app (upon successful authentication, it opens the
Switchboard). All it does is get the username and password, pull up a
recordeset of the usernames and sets the UserId to be used throughout the
session. The table Userlist is a SQL 2000 linked table. I can...
|
by: MLH |
last post by:
I cut a mail function off the m'soft site. Has always worked. However,
I would like to include error codes returned by the sendmail Fn and
be able to understand what they mean. I had my first occasion to
experience a failure and got a code of 2??? Would like to know
just what that means.
Here's how I call the fn...
Result = SendMail((F!Subject), (F!To), (F!CC), (F!Attach),
(F!Message))
|
by: Guy Debord |
last post by:
Hello all,
I know that this is a long shot, but I have a problem which someone
reading this group *may* just be able to shed some light on.
We have a new internal personnel planner/attendance system in place. It
uses a web interface to allow members of staff to select their site
location for any week, request leave and record absences.
The server-side scripting is composed of VB/ASP and Javascript which
|
by: andrewcw |
last post by:
I have tried :
http://msdn2.microsoft.com/en-us/library/system.management.connectionoptions.aspx
using my own credentials - no options supplied and as known alternate user
But it simply gives an error - MSDN suggests
http://support.microsoft.com/default.aspx/kb/224370
However I can PING the share just fine !
Other clues - is this code example DOA ? or is there something else ?
--
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |