Warning: mysql_fetch_row(): supplied argument is not a valid

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Warning: mysql_fetch_row(): supplied argument is not a valid

Post by MKEMouse »

This should be my last question. What does

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
mean?

// When I have code like the below stuff -------

$sql = "SELECT * FROM member_table WHERE member_id=$member_id";

$result = mysql_query($sql);

$myrow = mysql_fetch_row($result);
//

Thanks for your problem solving efforts.

MKEMouse :o
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

obviously the query failed and $result does not refer to an valid result-set identifier.
try

Code: Select all

$result = mysql_query($sql) or die($sql.' :'.mysql_error());
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

SELECT * FROM member_table WHERE member_id=$member_id :Unknown column '$member_id' in 'where clause'

This is what I got returned when I used your code? Does that mean I can't use $member_id as a PHP variable for a <FORM> radio button value?

1) I created a display screen with clients and their information:


$result1 = mysql_query("SELECT * FROM member_table WHERE expiration=2003");
while($row1 = mysql_fetch_array($result1)) {




?>
<br />
<tr>
<td bgcolor="#6999CC">
<input type="radio" name="radiobutton" value="<?php echo $row1["member_id"] ?>" />


I have a radio button in a form that I check to determine which record in the HTML table to edit when an "Edit" button is pushed.

2) When the "Edit" button is pushed it calls a form action:

<form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=$member_id">

3) When this page is called the warning message I mentioned appeared.
Now the message in the top of this posting appears after you gave me the snippet of code.

I appreciate your help.

If you need anything aside from American beer let me know.

MKEMouse
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

<form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=$member_id">
you probably want $member_id to be replaced by its current value by php when the form element is printed. But this only happens within a php-block (<?php ... ?>). Do you a) echo then <form ....>-element or do you b) put it outside a php-block?

a) the syntax suggests you have done something like

Code: Select all

echo'&lt;form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=$member_id"&gt;';
which is valid but will not lead to variable replacement since this only happens in double-quoted strings ('this "is still" a single-quoted string' ;) ). Try

Code: Select all

echo '&lt;form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=', $member_id,' "&gt;';
b) Try

Code: Select all

&lt;form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=&lt;?php echo $member_id; ?&gt;"&gt;
or if short-tags are enabled

Code: Select all

&lt;form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=&lt;?=$member_id?&gt;"&gt;
p.s.: uhhh...the board still eats closing php-tags :(
to see the whole thing you have to press "quote" on this post and then copy it
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Or you could use

Code: Select all

&lt;?phpecho '&lt;form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id='.$member_id.' "&gt;';
?&gt;
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

Thanks for all the suggestions. I will try them.

One thing the <form> is actually outside the <?php ?> codes. It is on the client side not server-side scripting.

1) Here is the newest error message after I added to the display page:

<form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=<?php echo $member_id;?>">

2) When the submit ("Edit") button is pushed in the display page and calls the Edit page :

SELECT * FROM member_table WHERE member_id= :You have an error in your SQL syntax near '' at line 1

Thanks again.


M. Mouse

PS. Not to be political but my I am very sorry for all those families and victims of the incident in Bali. I wish there was something we could do. :(
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Try quoting your variable in your SQL...so:

Code: Select all

$sql = "SELECT * FROM member_table WHERE member_id='$member_id'";
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

Thanks, I tried the code, no more error messages. :D

The only thing left is the edit page shows up but the textfields in the form are not populated with the member's record. I thought that I could place a radio button next to each record put into the HTML table in a form on the display page and assign it a member_id. I thought that when someone clicked on the radio button and then clicked the "Edit" (submit) button that the edit page would have its form fields filled in.
I don't know what happened.

Again I appreciate your suggestions. :D


MKEMouse
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

You kind of lost me there...

But, if what you're trying to do is pre-fill a form with information pulled from a DB you need to build your query (as you've done above) and then use the results of your query to fill-in your form. For example, if you have:

Code: Select all

$sql = "SELECT first_name FROM members WHERE member_id='$member_id'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
Then, you construct your form:

Code: Select all

<form name="form" blah, blah...>
<input type="text" name="first_name" value="<?php echo $row&#1111;first_name]; ?>" size="18">
The form element will display the value for first_name. Hope this helps... :)
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

Thanks for getting back to this. I appreciate the ideas.
What want to happen is that an administrator can view members of their organization in a display screen. I created the display screen. It is a a scrolling HTML table filled with member records that I pulled from the database. I also have a radio button next to each member record.

I thought that if the administrator clicked on the radio button next to the record (displayed in the HTML table) they wanted to edit, and then hit the submit ("Edit") button that I could call the edit_wqi_member.php with:

<form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id='.$member_id.' ">';

and then populate the form on it with the member record that had a radio button clicked in the display screen. The radio button in the display screen table has the following code:

<input type="radio" name="radiobutton" value="<?php echo $row1["member_id"] ?>" />


I guess I am lost :?
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Okay, to display the member's information on the edit form on your edit_wqi_member.php page you'll need to either pass all of the variables using the submit from display screen (don't do this) or perform another query in edit_wqi_member.php that will get the information you want to display.

So, after the administrator submited on the display page the edit_wqi_member.php would be loaded and you would do a query before the form. The data would the be displayed as I explained earlier.

Remember, you are only passing the $member_id variable to the edit page. If you want to display the member's information on the edit page in the form, you've got to go get it! :)
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

Wow thanks. :o One thing though: :idea:
Remember, you are only passing the $member_id variable to the edit page. If you want to display the member's information on the edit page in the form, you've got to go get it
I was passing the member_id as .../edit_wqi_member.php?member_id=$member_id because that's how I have seen it done.
My free email for example, the page knows which mailbox to display based on my username and password like : mailserver.blahhaha.com/mailbox.php?id=12219

How can I perform the same function/task as the free email service is doing with their php documents?
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

I got this idea from an example for a PHP calculator somewhere online:

1. member_id=$radiobutton which is the name of the input of type radio.

)<form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=$radiobutton">';

2. According to his code he referred to the value through the radio button's name (ie. if(op=="add") { } ) // op was the name of the group of radio buttons in the PHP calculator- add, subtract, division, etc.

<input type="radio" name="radiobutton" value="<?php echo $row1["member_id"]; ?>" />

In any case you can see that I changed the PHP variable name from $member_id to $radiobutton.

I'm trying, but no result.
:(
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

MKEMouse wrote:I was passing the member_id as .../edit_wqi_member.php?member_id=$member_id ...
That's exactly what I was saying earlier. Again, the only variable you are passing to edit_wqi_member.php is member_id (e.g. ...?member_id=$member_id). So, the only piece of information edit_wqi_member.php has about the member is his id. So, on the edit_wqi_member.php page, before you display anything, you've got to perform a query to get the rest of the member's information so you can display it. E.g.:

Code: Select all

$query = "SELECT * FROM member WHERE member_id='$member_id'";
$result = mysql_query($query) or die("Cannot perform MEMBER query.");
$row = mysql_fetch_array($result);
And from this you can echo whatever you'd like into your edit form. E.g.:

Code: Select all

<form name="form" blah, blah...> 
<input type="text" name="first_name" value="<?php echo $row&#1111;first_name]; ?>" size="18">
Maybe I just don't understand what you're trying to do. What problems are you having when trying to implement this? :?: :?
MKEMouse
Forum Newbie
Posts: 19
Joined: Sun Oct 20, 2002 10:41 pm
Location: Milwaukee

Post by MKEMouse »

I did have a query at the beginning for the edit page but it did not populate of the fields eventhough I was using the member_id to locate the correct records from the database. Now I modified the code for the display page as:

<form name="form1" id="form1" method="post" action="edit_wqi_member.php?member_id=$radiobutton&l_name=$lastname&f_name=$firstname&m_name=$middlename&street=$street&city=$city&state=$state&zip=$zip&phone=$phone&email=$email">
<table width="760" cellspacing="2" cellpadding="0">


I created hidden fields on the display screen to store the record data
such as:

<input type="hidden" name="lastname" value="<?php echo $row1["l_name"]; ?
<input type="hidden" name="firstname" value="<?php echo $row1["f_name"]; ?>" />
<input type="hidden" name="middlename" value="<?php echo $row1["m_name"]; ?>"
<input type="hidden" name="street" value="<?php echo $row1["street"]; ?>" />
<input type="hidden" name="city" value="<?php echo $row1["city"]; ?>" />
<input type="hidden" name="state" value="<?php echo $row1["state"]; ?>" />
<input type="hidden" name="zip" value="<?php echo $row1["zip"]; ?>" />
<input type="hidden" name="phone" value="<?php echo $row1["phone"]; ?>" />
<input type="hidden" name="email" value="<?php echo $row1["email"]; ?>" />


The form action=edit_wqi_member.php?blahblahblah would take all the data stored and spit it out to the edit screen...

But now for some reason the very first person I selected to edit constantly populates the edit page fields even though I am selecting a different radio button (corresponding to a different member.)
I printed the member_id to the display screen as well as the edit page screen and found that the member_id was being passed from the display page to the edit page. But after that nothing happens.

When I then hit the submit button at the bottom of the edit page it does not update the database.

So I have two lousy new problems, but I guess progress is being made.
I just don't know where to go from here. :?:

Thanks again for your suggestions. I really appreciate your time.

I'm lost now.

8O
Post Reply