PHP and Updateable Queries.

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Hello,

I appologize in advance for my niavété since I'm rather new to the PHP world but I'm having some problems with this. I have mySQL set up and I've been receiving information from it through PHP with no problem, but when I try to change information through it with an Updateable query it does not do it. I try it directly in mySQL and it works fine.

My only explanation is I have not set up mySQL right or my permissions are not set correctly to do this sort of query.

If anyone could help me, I would appreciate it greatly.

- mccareth

P.S. I'm not sure it pretains, but I'm using mySQL and PHP on Windows.
 
An update query can only be succesfull if the user you login with in the database has update-rights.
This ofcourse also counts for select, insert, delete, etc query's.

It is also possible that you're update-query is incorrect.

Greetz Daan
 
SQL statements are fairly universal, unless mySQL does something a little different.

UPDATE tblPlayers
SET fldCountry='USA',
fldAge=22
WHERE fldNickName="Something";

Pretty well standard of all I'd think, not to mention I used that same Update Query in mySQL directly using the same account as the one I use for PHP and it did work fine.
 
The query fails in PHP but works in mySQL directly??

What error does PHP return??
you might want to use this function to track the error-message:
http://www.php.net/manual/en/function.mysql-error.php

Greetz Daan
 
Ok,

When I put in the Errno and Error functions into my PHP page it returned a 0 with no Error message, so I'm under the assumption that like most other languages, that meant the query went through fine. Perhaps I'll post my code and let you guys see what I've done, maybe there is something that needs to be added that I've missed.

@ $database = mysql_pconnect("localhost","blah","blah");

if (!$database)
{
echo "Error message"
exit;
}


mysql_select_db("database");

$txtCountry = addslashes($txtCountry);
$txtAge = addslashes($txtAge);
$txtNickName = addslashes($txtNickName);

$qryQuery = "UPDATE tblPlayers
SET fldCountry='".$txtCountry."',
fldAge=".$txtAge."
WHERE fldNickName='".$txtNickName."'";
$rsResult = mysql_query($qryQuery);
echo mysql_errno().": ".msyql_error()."\n";


I hope it's just something I missed. Also I want to thank you all for looking and posting, especially of course DoppyNL.

-mccareth
 
Hello again everyone,

I was just playing around and thought for the heck of it, I'd replace my Updateable query to a Delete query... Same problem as the update query. It tells me that there are no errors in executing, but it just won't delete the record, but likewise to the update query I have no problem in executing it directly in MySQL.

I'm not sure what's going on......

-mccareth
 
Sometimes strange things can happen when using ' and " because it may do something a little different then expected.
print out the query on the page after you build it, then you know exactly what php is executing, might be a little different than expected.

Greetz Daan
 
Ummm, I appologize again for my "newbie-ness", but I have no idea what you mean at the moment.....
 
I reread your post, I understand now and found the problem! Thank you very much for your help DoppyNL!!!

-mccareth
 
Back
Top