SQL issues. -
JoelR - 30.12.2012
For some reason, the following two SQL queries aren't doing anything.
pawn Code:
format(Query, sizeof(Query), "INSERT INTO `contracts` (`cID`, `ucon`, `ucen`, `price`) VALUES (NULL, '%s', '%s', '%i')", cContractor, cContractee, cContractPrice);
mysql_query(Query);
print(Query);
and
pawn Code:
format(query, sizeof(query), "SELECT `user` FROM accounts WHERE `user`='%s'", name);
mysql_query(query);
print(query);
if(!mysql_num_rows())
{
SendClientMessage(playerid, GREY, "That name isn't in the database.");
}
Please could someone help?
Re: SQL issues. -
Abreezy - 30.12.2012
Read the debug file and see what it does. Post what you see in the debug
Re: SQL issues. -
JoelR - 30.12.2012
Code:
[08:22:43] >> mysql_query( Connection handle: 1 )
[08:22:43] CMySQLHandler::Query(SELECT `user` FROM accounts WHERE `user`='test') - Successfully executed.
[08:22:43] >> mysql_num_rows( Connection handle: 1 )
[08:22:43] CMySQLHandler::NumRows() - You cannot call this function now. (Reason: Dead Connection)
[08:22:43] >> mysql_query( Connection handle: 1 )
[08:22:43] CMySQLHandler::Query(INSERT INTO `contracts` (`cID`, `ucon`, `ucen`, `price`) VALUES (NULL, 'Jamie_Gervin', 'test', '50000')) - An error has occured. (Error ID: 2014, Commands out of sync; you can't run this command now)
[08:22:43] >> mysql_free_result( Connection handle: 1 )
[08:22:43] CMySQLHandler::FreeResult() - The result is already empty.
Re: SQL issues. -
Abreezy - 30.12.2012
It looks like your database is being connected or so, are you sure it connects perfectly?
Re: SQL issues. -
JoelR - 30.12.2012
It has done so up until I created this command:
pawn Code:
command(contract, playerid, params[])
{
new name[24], price, string[128], query[128];
if(sscanf(params, "s[24]i", name, price))return SendClientMessage(playerid, GREY, "Usage: /contract [Full_Name] [price]");
{
if(price < 50000)return SendClientMessage(playerid, GREY, "The minimum price for a contract is $50,000.");
if(price > 1000000)return SendClientMessage(playerid, GREY, "The maximum price for a contract is $1,000,000.");
if(price > Player[playerid][Money]) return SendClientMessage(playerid, GREY, "You don't have enough money to place this contract.");
format(query, sizeof(query), "SELECT `user` FROM accounts WHERE `user`='%s'", name);
mysql_query(query);
print(query);
if(!mysql_num_rows())
{
SendClientMessage(playerid, GREY, "That name isn't in the database.");
}
else
{
Player[playerid][Money] -= price;
format(string, sizeof(string), "[Contract] A contract for $%s has been added to your PDA. Please check it now.", FormatNumber(price));
SendFactionMessage(2, YELLOW, string);
SaveContract(pName(playerid), name, price);
format(string, sizeof(string), "You have successfully placed a hit on %s for $%s.", name, FormatNumber(price));
SendClientMessage(playerid, YELLOW, string);
}
}
return 1;
}
When I remove:
pawn Code:
format(query, sizeof(query), "SELECT `user` FROM accounts WHERE `user`='%s'", name);
mysql_query(query);
print(query);
if(!mysql_num_rows())
{
SendClientMessage(playerid, GREY, "That name isn't in the database.");
}
else
It has no problem, just can't check the name.
Re: SQL issues. -
Peach - 30.12.2012
Give this a whirl.
PHP Code:
format(query, sizeof(query), "SELECT `user` FROM accounts WHERE `user`='%s' LIMIT 1", name);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
Player[playerid][Money] -= price;
format(string, sizeof(string), "[Contract] A contract for $%s has been added to your PDA. Please check it now.", FormatNumber(price));
SendFactionMessage(2, YELLOW, string);
SaveContract(pName(playerid), name, price);
format(string, sizeof(string), "You have successfully placed a hit on %s for $%s.", name, FormatNumber(price));
SendClientMessage(playerid, YELLOW, string);
return true;
}
else
{
SendClientMessage(playerid, GREY, "That name isn't in the database.");
return true;
}