1
Script Discussion / Re: Full document for Squirrel plugins
« on: October 05, 2014, 01:13:06 am »if ( q && mysql_num_rows( q ) > 0 )THANKXXXXXXX
worked :}
(Why didn,t i think of that >.<)
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
if ( q && mysql_num_rows( q ) > 0 )THANKXXXXXXX
Thankx it works perfectly but only if data already exist in database if we change the Name "TestUser" to something else it shows index `Name` does not existCode: [Select]function onScriptLoad()
{
local DB = mysql_connect("localhost", "user", "pass", "database");
if ( DB )
{
local q = mysql_query(DB, "SELECT * FROM accounts WHERE `username` = '" + mysql_escape_string( DB, "TestUser") + "'");
if ( q )
{
local row = mysql_fetch_assoc( q );
print( "Username: " + row["username"] );
print( "IP: " + row["ip"] );
}
else
print("Query failed: " + mysql_error( DB ) );
}
else
print("Connection to MySQL failed: " + mysql_error( DB ) );
}
Returns:Quote[SCRIPT] Username: TestUser
[SCRIPT] IP: 127.0.0.1
<?php
$db = mysql_connect('localhost','root','mypass');
$mydb = mysql_select_db('sk');
function getip($name){
$sql = "SELECT * FROM testaccount where name = '$name'";
$row = mysql_fetch_assoc( mysql_query($sql) );
$ip = $row['IP'];
return $ip;
}
echo $getip = getip('sk');
?>
this above code works good for php page but now check it out for squirrelfunction onScriptLoad()
{
stats <- array( GetMaxPlayers(), null );
db <- mysql_connect("localhost","root","mypass","Sk");
}
function getip(player){
local sql = "SELECT * FROM 'testaccount' where 'Name' = '"+player.Name+"'";
local row = mysql_fetch_assoc( mysql_query(db,sql) );
local ip = row["IP"];
return ip;
}
function onPlayerCommand( player , cmd , text){
if ( cmd == "myip"){
local myip = getip(player);
MessagePlayer("Your last used ip was : " + myip,player);
}
Note = 'mypass' is not my original pass.