I set up phpmyadmin, and it works fine, but my code isn't working. id is
the correct column (it is the primary key), stock is the correct database.
CODE:
$qresult = mysql_query("SELECT id FROM 'stock'");
echo ("START<P><HR>");
while ($row = mysql_fetch_array($qresult)) {
echo ($row ["name"]);
echo ("<br>");
}
echo ("<P><HR><P>END");
OUTPUT:
START
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14
END
does anybody have any idea's why? 15 4741
just thought i would add that i am using uk2.net as my hosting, and mysql
and php are setup fine.
TIA
Matthew Robinson wrote: OUTPUT: START Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14 END
does anybody have any idea's why?
Use error checking!
Instead of
<?php
$qresult = mysql_query("select ...");
?>
do
<?php
$qresult = mysql_query("select ...") or die(mysql_error());
?>
or, easier to interpret the (eventual) error
<?php
$command = 'select ...';
$qresult = mysql_query($command) or die('Error ' . mysql_error() .
' in ' . $command);
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Matthew Robinson wrote: I set up phpmyadmin, and it works fine, but my code isn't working. id is the correct column (it is the primary key), stock is the correct database.
CODE: $qresult = mysql_query("SELECT id FROM 'stock'"); echo ("START<P><HR>"); while ($row = mysql_fetch_array($qresult)) { echo ($row ["name"]); echo ("<br>"); } echo ("<P><HR><P>END");
OUTPUT: START Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14 END
does anybody have any idea's why?
Omit the single quotes from your query, like so:
$qresult = mysql_query("SELECT id FROM stock");
Putting single quotes around the table name causes a SQL error.
Regards,
- Dan
dantripp.com
$command = "SELECT id FROM stock";
$qresult = mysql_query($command) or die('Error ' mysql_error() ' in '
$command); //$qresult = mysql_query("SELECT id FROM stock"); echo
("START<P><HR>");
while ($row = mysql_fetch_array($qresult)) {
echo ($row ["name"]);
echo ("<br>");
}
echo ("<P><HR><P>END");
gives this error: Parse error: parse error in
/home/houseproudlancs_co_uk/index_to_be.php on line 12
line 12 in the page is the second line on this post ( $qresult =
mysql_query($command) or die('Error ' mysql_error() ' in ' $command);)
removing the quotes from "SELECT id FROM stock"; didn't work either.
Matthew Robinson wrote: $qresult = mysql_query($command) or die('Error ' mysql_error() ' in ' $command); //$qresult = mysql_query("SELECT id FROM stock"); echo ("START<P><HR>");
gives this error: Parse error: parse error in /home/houseproudlancs_co_uk/index_to_be.php on line 12
You lack the dots to concatenate the strings.
$qresult = mysql_query($command) or die('Error ' . mysql_error() . ' in ' . $command);
// ______________________________________________^___ ____________^________^___________
// sorry for the long lines :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
thanks - it works now, well that bit anyway. here's the entire page, and
the output below it. im trying to work out php/mysql, so im just trying to
get it to print out all the fields in the 'name' field in the 'stock'
table in the 'houseproudlancs_co_uk1' database.
<?php
$dbcnx = @mysql_connect("server", "username", "password");
$select = @mysql_select_db("houseproudlancs_co_uk1");
$command = "SELECT id FROM stock";
$qresult = mysql_query($command) or die('Error ' . mysql_error() . ' in ' . $command); echo ("START<P><HR>");
while ($row = mysql_fetch_array($qresult)) {
echo ($row ["name"]);
echo ("<br>");
}
echo ("<P><HR><P>END");
?>
START
--------------------------------
--------------------------------
END
Matthew Robinson wrote: <?php $dbcnx = @mysql_connect("server", "username", "password"); $select = @mysql_select_db("houseproudlancs_co_uk1");
$command = "SELECT id FROM stock"; $qresult = mysql_query($command) or die('Error ' . mysql_error() . ' in ' . $command); echo ("START<P><HR>");
while ($row = mysql_fetch_array($qresult)) { echo ($row ["name"]);
Do you want the "name" or the "id"?
At this point $row['name'] -- I prefer single quotes :) -- does not exist.
Either also select the name: "SELECT id, name FROM stock"
or change id's identification: "SELECT id as name FROM stock"
START --------------------------------
empty, of course :) -------------------------------- END
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
oh ye, just realised i didn't mention that the database has 2 rows, both
with the 'name' column not null, so the output should be different to what
it is.
id is the primary key, so i thought it would be best to use that as the
one to identify the row.
name is what i want to print to the screen.
Matthew Robinson wrote: oh ye, just realised i didn't mention that the database has 2 rows, both with the 'name' column not null, so the output should be different to what it is.
When you do
$sql = 'select col1, col2, col4 from table';
$obj = mysql_query($sql) or die(mysql_error());
$res=mysql_fetch_array($obj);
// $res as as many elements as columns in your select, and their
// index is the name used in the select.
// so, now you can do
echo $res['col1'], $res['col2'], $res['col4'];
// but
echo $res['col3'];
// does not work even if the table has a column named "col3"
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
CODE:
<?php
$dbcnx = @mysql_connect("SERV", "USR", "PWD");
$select = @mysql_select_db("houseproudlancs_co_uk1");
echo ("START<P><HR>");
$command = 'SELECT id, name, description, price FROM stock';
$qresult = mysql_query($command) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo ($row ["name"]);
echo ("<br>");
}
echo ("<P><HR><P>END");
?>
OUTPUT:
START
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 17
END
sorry about the posting twice about the same thing again, but the line in
question is the one with while on it
Matthew Robinson wrote: $qresult = mysql_query($command) or die(mysql_error());
$qresult here
while ($row = mysql_fetch_array($result)) {
but here you have $result
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 17
$result is *not* an object returned from mysql_query() function :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
thanks for the help pedro, im not used to programming properly, as i used
to program vb, which wipes your bum for you. anyway, thanks again. this
has been a problem for days. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert |
last post by:
<?php
echo "HI " . $name;
$result = mysql_query("SELECT * FROM album WHERE username='{$name}'");
while ($next_row = mysql_fetch_array($result)) {
$album_name = $next_row;
echo "<a...
|
by: james |
last post by:
I am new to PHP and am trying to run a simple query and display the
result, with no luck. Here is the code I am using.
<?php
//start session
session_start();
//store cmpid from querystring...
|
by: Konrad |
last post by:
In the part of code:
$polecenie = "SELECT osoby.Id ,osoby.Imie ,
osoby.Nazwisko,osoby.Tytul,osoby.Email,adrespraca.Adres AS ap,
adrespraca.KodPoczt AS...
|
by: Good Man |
last post by:
Hey there
I have a dumb question....
Let's say i have a database full of 4000 people.... I select everything
from the database by:
$result = mysql_query("SELECT * FROM People");
|
by: Pratchaya |
last post by:
Hi Everyone
==============================================================
About PHP::: Error/Problem PHP Warning: mysql_fetch_array():...
|
by: Marcel Brekelmans |
last post by:
Hello,
I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example:
I have a simple table 'tblName':
ID Name
1 Jane
2 Joe
2 Doe
|
by: Petr Vileta |
last post by:
Hi, I'm new here and excuse me if this question was be here earlier.
I have a simple code
<html><body>
<?php
<?php
$link = mysql_connect("localhost", "user", "password")
or die("Grr: " ....
|
by: student2008 |
last post by:
Sorry about the title its a tricky one.
I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button...
|
by: chemlight |
last post by:
I'm having a problem. I'm sure I'm going to kick myself over the answer...
I have a table that stores vendors and their languages. This table starts out blank. I am querying the table to see if a...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |