473,408 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

mysql_query($query) returns mysql_errno 0.

Hey all;

I'm one of those newbies to the PHP realm of programming and I've run
into a stumper. What I'm trying to do is pull data (any data at this
point) from a mysql database. I've checked and doublechecked by my
code and cross referenced examples on the Web, but I cannot seem to
find anything that might give me some incite.

Below is a code snippet showing what I'm trying to accomplish.

<?php
$connection = mysql_connect('localhost', 'user', 'pass');
if(!$connection)
{
die ("Could not connect to the database: \n".
mysql_error());
}
elseif($connection)
{
print "Successfully connected to the database \n";
}
$db_select = mysql_select_db('self_serv');
if(!$db_select)
{
die ("Could not select the database: \n".
mysql_error());
}
elseif($db_select)
{
print "Successfully selected the database \n";
}
$select = 'SELECT';
$column = '*';
$from = 'FROM';
$tables = 'app_n_port';
$where = 'WHERE app_no=1001';
$query = $select." ".$column." ".$from." ".$tables." ".$where. " LIMIT
0, 30";
$result = mysql_query($query);
if (!$result);
{
die ("Query failed. Your Query: " . $query . "
Returned Error Number: " ." ".mysql_errno() . " Error Detail-" . m
ysql_error()). "\n";
}
while ($result_row = mysql_fetch_array($result))
{
echo $result_row. "\n";
}
mysql_close($connection);
?>

After running the script I get the "die" statement after the <if(!
$result) clause with no mysql_error and a mysql_errno of 0.

Any help would be greatly appreciated.

Thanks in advance,

Thad

Sep 14 '07 #1
1 2904
On Fri, 14 Sep 2007 19:58:25 -0000, th********@gmail.com wrote:
>if (!$result);
You have a semicolon here, ending the statement.
{
This brace is not connected to the previous conditional. Despite PHP not doing
block scoping, it does let you put redundant braces around blocks.
die ("Query failed. Your Query: " . $query . "
Returned Error Number: " ." ".mysql_errno() . " Error Detail-" . m
ysql_error()). "\n";
So this always runs, $result probably was valid, and mysql_errno tells you "no
there wasn't an error".

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: davidv | last post by:
I am building a very simple form that takes text and inserts data in a MySQL db. I would like my "logic" to simply insert the value in to the field in the database that matches the name from the...
13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
10
by: johnnyboy10017 | last post by:
I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that...
5
by: lkrubner | last post by:
www.php.net says: >>>>>>>>>>>> Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of...
1
by: Ryan Govostes | last post by:
Eh, I was wondering if anyone could help me with a SQL query problem I'm having. I'm a complete newbie to SQL and MySQL, so any help would be greatly appreciated. I am using PHP to allow users...
7
by: John Moore | last post by:
Hi I posted three days ago about a function I wrote which kept refusing to run a mysql_query. Well I did away with the function, and hard coded the variables into the query itself. Here's...
5
by: cover | last post by:
So why is it that the following code returns data from a single table just fine? When 'all' is selected, all records are returned or if another selection is selected, only the ones specific to...
10
by: Jerim79 | last post by:
I need to take the output from a query and convert it to lower case. Here is the relevant code: $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND LNAME=('$LName')"; $result =...
20
by: Guillaume Dargaud | last post by:
I must be tired tonight: $query="SELECT * FROM ImageList WHERE Name='$value'"; $result=mysql_query($query, $DB) or die(mysql_error()); if ($result) { $InContext=mysql_fetch_assoc($result);...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.