• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[PHP]Some help needed with php

Newbie Spellweaver
Joined
Jul 11, 2012
Messages
15
Reaction score
0
Hi.
I have a question, so, i have tbl_guild and i'm adding a guild to it with php help, so when adding a guild i input characters name in input field and when proceeding i need script to check if user exists in tbl_users and NOT exist already in tbl_guild and if so proceed further with my script.
I'm new to php so i would appreciate some help here how to solve this problem.
I had a few ideas how to do so:

//Checking name in users is exists
$checkusername = mssql_query("SELECT name FROM tbl_users where name='$_POST[name]'");
$ccheckusername2 = mssql_fetch_array(checkusername)

//Checking name in _tblguild
$checkgname = mssql_query("SELECT name FROM tbl_guild where name='$_POST[name]'");
$checkgname2 = mssql_fetch_array($checkgname)

So how to put this in if statement together , if possible.

if ($checkgname2== ).....

And after that my mind blows :D
Thanks!
 
Newbie Spellweaver
Joined
May 8, 2010
Messages
20
Reaction score
2
PHP:
if (mysqli_num_rows(mysqli_query($link, "SELECT name FROM tbl_users where name='$_POST[name]'"))>=1) 
	{
		if((mysqli_num_rows(mysqli_query($link, "SELECT name FROM tbl_guild where name='$_POST[name]''"))===0)
			{
			// add guild operations...
			}   
		else
			{ 
			echo 'Guild already exist!';
			}
	}
else
	{
	echo "No User found!";
	}

In this example I used the row_count function of mysqli to count the results number in order to check if there is already a user with that name and if so, check if there is a guild with that name in order to create one that doesn't exist inside the database.

almost forgot, use some input data sanitization because nowdays there are alot of defacements using the sql inject exploit.
 
Pee Aitch Pee
Joined
Mar 30, 2011
Messages
630
Reaction score
422
He's using MSSQL (mssql_*), you can't just switch to MySQL (mysqli_*).
Better would be to use SQLSRV
 
Back
Top