473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL not returning value even though it's there...

Hello Everyone,

I have been having fits with a simple PHP script and I'm hoping it's
something that someone here can help me with. Basically, when I execute the
SQL statement directly on the MySQL CLI, it returns. But when I run the same
statement through the following PHP script, I *think* it returns an empty
set.

I say I think because the if(mysql_num_ro ws($recset) > 0){} block is
executed. But when I try to retreive values stored in my array, I get
blanks. Can someone offer me some help? Thanks in advance -- Anthony

=== SCRIPT ===
<?php
include("db.php ");

$incoming_user = stripslashes($_ POST['username']);

$sql = "SELECT * FROM tblSisters WHERE username != '$incoming_user ' AND
isTaken != 'yes' ORDER BY RAND() LIMIT 1";

$recset = mysql_query($sq l, $conn);

if(mysql_num_ro ws($recset) > 0){
$row = mysql_fetch_row ($recset);
echo "<table border=\"1\" align=\"center\ " cellspacing=\"7 \">\n";
echo "<tr>\n";
echo "<th>USERNA ME</th>\n";
echo "<th>WANTS MAIL</th>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>$row[username]</td><td>$row[wsm]</td>\n";
echo "</tr>\n";
echo "</table>\n";

// Update the database to reflect the new selection

$sql2 = "UPDATE tblSisters SET isTaken='yes', takeBy='$incomi ng_user' WHERE
username='row[username]'";
mysql_query($sq l2, $conn);
}
else{
echo "<h2><u><b>RECO RD RETREIVAL FAILURE</b></u></h2><br>\n";
echo "The secret sister database could not be queried. Please try again ";
echo "later or contact the system administrator.\ n";
}
?>
=== END SCRIPT ===
Jul 17 '05 #1
5 2173
Anthony Papillion II wrote:
I say I think because the if(mysql_num_ro ws($recset) > 0){} block is
executed. But when I try to retreive values stored in my array, I get
blanks. Can someone offer me some help? Thanks in advance -- Anthony [snip] if(mysql_num_ro ws($recset) > 0){
$row = mysql_fetch_row ($recset); [snip] echo "<td>$row[username]</td><td>$row[wsm]</td>\n";


If you were running with error_reporting set to E_ALL, you would see an
"undefined array index" notice here which would have helped you diagnose
the problem: mysql_fetch_row returns an enumerated array, not an
associative array.

If you want to access columns by name, use mysql_fetch_arr ay (or
mysql_fetch_obj ect to use object syntax).

See the online manual for additional information:
http://www.php.net/error_reporting
http://www.php.net/mysql_fetch_row

-- brion vibber (brion @ pobox.com)
Jul 17 '05 #2
.oO(Anthony Papillion II)
I have been having fits with a simple PHP script and I'm hoping it's
something that someone here can help me with. Basically, when I execute the
SQL statement directly on the MySQL CLI, it returns. But when I run the same
statement through the following PHP script, I *think* it returns an empty
set.

I say I think because the if(mysql_num_ro ws($recset) > 0){} block is
executed. But when I try to retreive values stored in my array, I get
blanks. Can someone offer me some help? Thanks in advance -- Anthony


Use mysql_fetch_ass oc() instead of mysql_fetch_row (). The first returns
an associative array, the latter a numeric one.

Micha
Jul 17 '05 #3

Hi

mysql_fetch_row () creates an integer indexed array. You are using
associated indexes to output the row data. The index does not exist.
To use associative indexes simply change mysql_fetch_row () to
mysql_fetch_arr ay() or mysql_fetch_ass oc()

e.g => $row = mysql_fetch_arr ay($recset);

Regards
Peter

Anthony Papillion II wrote:
Hello Everyone,

I have been having fits with a simple PHP script and I'm hoping it's
something that someone here can help me with. Basically, when I execute the
SQL statement directly on the MySQL CLI, it returns. But when I run the same
statement through the following PHP script, I *think* it returns an empty
set.

I say I think because the if(mysql_num_ro ws($recset) > 0){} block is
executed. But when I try to retreive values stored in my array, I get
blanks. Can someone offer me some help? Thanks in advance -- Anthony

=== SCRIPT ===
<?php
include("db.php ");

$incoming_user = stripslashes($_ POST['username']);

$sql = "SELECT * FROM tblSisters WHERE username != '$incoming_user ' AND
isTaken != 'yes' ORDER BY RAND() LIMIT 1";

$recset = mysql_query($sq l, $conn);

if(mysql_num_ro ws($recset) > 0){
$row = mysql_fetch_row ($recset);
echo "<table border=\"1\" align=\"center\ " cellspacing=\"7 \">\n";
echo "<tr>\n";
echo "<th>USERNA ME</th>\n";
echo "<th>WANTS MAIL</th>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>$row[username]</td><td>$row[wsm]</td>\n";
echo "</tr>\n";
echo "</table>\n";

// Update the database to reflect the new selection

$sql2 = "UPDATE tblSisters SET isTaken='yes', takeBy='$incomi ng_user' WHERE
username='row[username]'";
mysql_query($sq l2, $conn);
}
else{
echo "<h2><u><b>RECO RD RETREIVAL FAILURE</b></u></h2><br>\n";
echo "The secret sister database could not be queried. Please try again ";
echo "later or contact the system administrator.\ n";
}
?>
=== END SCRIPT ===

Jul 17 '05 #4
Brion Vibber <br***@pobox.co m> wrote in message news:<31******* ******@uni-berlin.de>...
<snip>
If you were running with error_reporting set to E_ALL


or even better E_ALL | E_STRICT under PHP 5 in developement servers.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
> If you want to access columns by name, use mysql_fetch_arr ay (or
mysql_fetch_obj ect to use object syntax).


LOL I can't believe it was something THAT simple and THAT obvious. I *knew*
that mysql_fetch_arr ay() was the function to use (I've been using it
forever) but I totally spaced it out on this one. I didn't even know that
there was a mysql_fetch_row () function. Geez, now I feel stupid. Thanks for
your input.

Anthony
Jul 17 '05 #6

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

Similar topics

5
22657
by: Member | last post by:
Hi All. Maybe someone in here could help on this too.... Uusally I can return a value from a stored procedure without any problem. Today I ran into something I cannot figure out. Basically....what I am doing is a couple of inserts or updates depending on what is being passed.
25
2945
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default construction and then.. // some other processing and/or changing 'retval' return retval; }
11
1895
by: Justin Naidl | last post by:
class Foo { protected: char foo_stuff; public: char* get_foo_stuff(); } Given the above example. What I want to know is the "proper/standard" way
19
2965
by: Rick | last post by:
Hi, I was wondering, can it be safely assumed that any function that returns a *char will return a NULL terminated string? Or does the function explicitly mention this always (and the ones that don't do not return null terminated strings?) Rick
41
3829
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x = rand(); y = rand();
10
3171
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences in levels of indirection, so I feel it must have something to do with the way I am representing the array in the call and the return. Below I have commented the problem parts. Thanks in advance for any help offered. Pete
17
3262
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
6
1863
by: RThaden | last post by:
Hi together, I am a bit clueless about the following problem: In the following code excerpt std::string getStr() { std::string bla="asdfsa";
6
1083
by: rowe_newsgroups | last post by:
I just noticed this about value types and return values, and it kind of bugs me that the compiler won't treat it as an error, even with Option Strict On. Try this out: Option Strict On Public Class MyClass
4
1558
by: rbjorkquist | last post by:
This is my first attempt at writing/using web services, so any and all comments will be greatly appreciated. With that said, I am also by no means saying this is the correct either. I have noticed that when returning a new TPastePart, created and filled by the web service, that if the "PastePartID" and "PastePart" properties do not have "set" accessor methods, their respective data is not returned, even though the object has contains...
0
10237
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, 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...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
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,...
0
9882
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 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...
0
8905
agi2029
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...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3987
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
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.