Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
After changing it to REQUEST, I got this:

OK, so now that we can inject the variable values, remove the print_r line, and use the long URL to manually enter the variables you want to update in your table. You will need to change the beginning lines of your code from $_POST["uname"] = to $_REQUEST["uname"] =...
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
So...

$uname = $_POST["uname"];
$email = $_POST["email"];
$acnt = $_POST["acnt"];
$cost = $_POST["cost"];

Change all the posts to REQUEST?
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
Change all the posts to REQUEST?
For the purpose of debugging your code, yes. But now that I think about it, maybe we should back up a step. You first started talking about the "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" warning, and no you know that this is because it was not getting the variable for $uname.

So at this point, it probably makes most sense to try accessing this page from the form originally designed to make the updates, rather than use the url manually. Does that work? If not, what is the code from the referring page?
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
heh, looking back at the code, maybe you should try removing the @ from
Code:
$dbNow=@mysql_select_db($currentDB, $hookup);
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
For the purpose of debugging your code, yes. But now that I think about it, maybe we should back up a step. You first started talking about the "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" warning, and no you know that this is because it was not getting the variable for $uname.

So at this point, it probably makes most sense to try accessing this page from the form originally designed to make the updates, rather than use the url manually. Does that work? If not, what is the code from the referring page?

OK good call. I changed the REQUESTS back to POST, and this is my code. As you can plainly see, this stuff isn't exactly my strongest skill, so be gentle...

http://nemo.mwd.hartford.edu/~bbarr/IIT310/Final/FinalPHPDB/dataUpdate.html

Code:
<form action="updateData.php" method="post">
  Company Name <br/>
  <input type="text" name="uname"  />
  <br />
  Contact Email <br />
  <input type="text" name="email"  />
  <br  />
   Account Number <br/>
  <input type="text" name="acnt"  />
  <br/>
   Site Cost <br/>
  <input type="text" name="cost"  />
  <br/>
  <input type="submit" value="Send" />
  
</form>

Still this error:
select * from boyfight3 where uname = 'BenCo'select * from boyfight3 where uname = 'BenCo'
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
I removed it, same error.
K, the problem is that your code is not connecting to your DB. Try changing your code to:
Code:
$hookup=mysql_connect($server, $user, $pass);
if (!$hookup) {
  die("Connection failed: " . mysql_error());
}
$dbNow=mysql_select_db($currentDB, $hookup);
if (!$dbNow) {
  die("Unable to select database: " . mysql_error());
}
And see what this returns.

BTW - I gotta go for now. I will try to check in later tonight. GL
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
I'll try that. Thanks a lot. I will leave my result here and you can take a look whenever you get back.
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
The form looks fine. I am beginning to wonder if you have SAFE mode turned on in your php.ini file? Enter this into a new file called test.php:
Code:
<?php
phpinfo();
?>
and load it from the browser. Look for the line that says SAFE_MODE.
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
OK, it's a new day - we can figure this thing out. In fact, I had a thought. Does the table "boyfight3' already exist? If not, you will need to create it first, before you can select anything from it.
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
This is really beginning to perplex me. :confused: Can you try to issue the SQL query in whatever program you used to set up your table in the first place? What is the result? You should copy the SQL statement directly from your code (substituting real values for variables of course) to see exactly what will result.
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
This is really beginning to perplex me. :confused: Can you try to issue the SQL query in whatever program you used to set up your table in the first place? What is the result? You should copy the SQL statement directly from your code (substituting real values for variables of course) to see exactly what will result.

I am not sure quite what you mean. I think one problem may be that I don't think I have a table. My database can be viewed at this page:

http://nemo.mwd.hartford.edu/~bbarr/IIT310/Final/FinalPHPDB/retrieveDisplayAll.php

That doesn't look like a table, maybe thats why it isn't working?

If that is indeed a table, and I am just missing something, you should explain what you mean in the post above in newbier terms. I am using dreamweaver to edit my code, if that helps.
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
By table, I am referring to the mySQL table. It has been a long time since I used DreamWeaver, but I seem to recall that there is a DB or Database tab under connections on the property inspector, right? You need to determine if you have set up a table called "boyfight3" in your "bbarr" database with the fields correctly set up.

And FWIW, I copied your code (both form and update) to my local machine, and after I set up the mySQL db, table and fields the code worked fine. So there is no problem with the code - only the communication with the database.
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
By table, I am referring to the mySQL table. It has been a long time since I used DreamWeaver, but I seem to recall that there is a DB or Database tab under connections on the property inspector, right? You need to determine if you have set up a table called "boyfight3" in your "bbarr" database with the fields correctly set up.

And FWIW, I copied your code (both form and update) to my local machine, and after I set up the mySQL db, table and fields the code worked fine. So there is no problem with the code - only the communication with the database.

OK cool, I am going to head home from work now so I can get to the code and everything. I will be back in 45 minutes, if you happen to be around, that would be great!

Thanks
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
Are you sure you put this code in your script?
Code:
$hookup=mysql_connect($server, $user, $pass);
if (!$hookup) {
  die("Connection failed: " . mysql_error());
}
$dbNow=mysql_select_db($currentDB, $hookup);
if (!$dbNow) {
  die("Unable to select database: " . mysql_error());
}
I was looking the updateData code a little bit, and if it mysql_connect fails or mysql_select_db fails it will generate the Warning about mysql_num_rows as you are seeing. If you put the above code in and either of those fail, the error will be returned and the mysql_num_rows will not be run.
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
OK back.

I have added that code to my program, but I am still getting the same error.

select * from boyfight3 where uname = ''select * from boyfight3 where uname = ''

I don't see why it wouldn't be connecting. The beginning of this code is basically the same as the beginning of all my other programs in this project, which work fine.

This is the beginning of my code, where I added that stuff:

Code:
<?php

	$server="localhost";
	$user="bbarr";
	$pass="******";
	$currentDB="bbarr";
	$currentTable="boyfight3";

$hookup=mysql_connect($server, $user, $pass);
if (!$hookup) {
  die("Connection failed: " . mysql_error());
}
$dbNow=mysql_select_db($currentDB, $hookup);
if (!$dbNow) {
  die("Unable to select database: " . mysql_error());
}

/* Pull all of the form variables and set them */
$uname = $_POST["uname"];
$email = $_POST["email"];
$acnt = $_POST["acnt"];
$cost = $_POST["cost"];

$query = "select * from $currentTable where uname = '$uname'";
echo $query;
$result = mysql_query($query);
echo $query;

etc.
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
I have added that code to my program, but I am still getting the same error.
Well if script is not exiting after you added that code, then the problem is not with the db connection, nor with the mysql_select_db. Which leaves the query. But it worked fine here, which I think means it is something with your mysql table.

Can you add this, under the $result= mysql_query($query):
Code:
if( !$result ) {
  echo "Query failed: " . mysql_error();
}
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
Code is:

Code:
$query = "select * from $currentTable where uname = '$uname'";
echo $query;
if( !$result ) {
  echo "Query failed: " . mysql_error();
}
$result = mysql_query($query);
echo $query;

Error is:

select * from boyfight3 where uname = ''Query failed: select * from boyfight3 where uname = ''

was I supposed to take out the first "echo $query;"?
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
From the php.net documentation (link):
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
Now I'm thinking this may be the problem.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.