Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

PHP and Updateable Queries.

Codes here !

Moderators: macek, egami, gesf

PHP and Updateable Queries.

Postby mccareth » Wed Oct 02, 2002 6:08 am

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.
mccareth
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Oct 02, 2002 6:02 am

Postby DoppyNL » Wed Oct 02, 2002 6:22 am

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
DoppyNL
 

Is this correct then?

Postby mccareth » Wed Oct 02, 2002 6:27 am

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.
mccareth
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Oct 02, 2002 6:02 am

Postby DoppyNL » Wed Oct 02, 2002 6:38 am

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
DoppyNL
 

No Error

Postby mccareth » Wed Oct 02, 2002 6:50 am

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
mccareth
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Oct 02, 2002 6:02 am

Interesting new problem

Postby mccareth » Wed Oct 02, 2002 7:25 am

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
mccareth
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Oct 02, 2002 6:02 am

Postby DoppyNL » Wed Oct 02, 2002 7:30 am

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
DoppyNL
 

Err.....

Postby mccareth » Wed Oct 02, 2002 7:34 am

Ummm, I appologize again for my "newbie-ness", but I have no idea what you mean at the moment.....
mccareth
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Oct 02, 2002 6:02 am

GOT IT!!!

Postby mccareth » Wed Oct 02, 2002 7:40 am

I reread your post, I understand now and found the problem! Thank you very much for your help DoppyNL!!!

-mccareth
mccareth
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Oct 02, 2002 6:02 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.