Raised This Month: $12 Target: $400
 3% 

PHP+SQL Need help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gameplayonline
Member
Join Date: Jun 2017
Old 06-17-2018 , 13:41   PHP+SQL Need help
Reply With Quote #1

I want get ID which have autoincrement value and save to variable because i want sue it in next table.

I dont knwo why it dont work and result is every time 0 or unknown value

I tried it rework 150x nothing works i really dont knwo where is problem

Im parsig variables here:
Code:
$url = filter_input_array( INPUT_GET );
		$url['sms'] = trim( $url['sms'] );
		$url['credit'] = intval( trim( $url['credit'] ) );
		$url['real_credit'] = intval( trim( $url['real_credit'] ) );
		$url['time'] = trim( $url['time'] );
		$url['id'] = intval( trim( $url['id'] ) );
		$url['customer_text'] = trim( $url['customer_text'] );
		$url['custom_NICK'] = trim( $url['custom_NICK'] );
		$url['custom_STEAMID'] = trim( $url['custom_STEAMID'] );
		$url['custom_PASSWORD'] = trim( $url['custom_PASSWORD'] );
		$url['refip'] = $_SERVER['REMOTE_ADDR'];
Here is main program:
Code:
$result = @mysql_query( "INSERT INTO `".$mysql_prefix."sms_keys` (`sms_text`, `sms_credit`, `sms_real_credit`, `sms_time`, `sms_id`, `sms_customer_text`, `sms_custom_nick`, `sms_custom_steamid`, `sms_custom_password`, `sms_refip`) VALUES ('".mysql_real_escape_string( $url['sms'] )."', '".mysql_real_escape_string( $url['credit'] )."', '".mysql_real_escape_string( $url['real_credit'] )."', '".$url['time']."', '".$url['id']."', '".mysql_real_escape_string( $url['customer_text'] )."', '".mysql_real_escape_string( $url['custom_NICK'] )."', '".mysql_real_escape_string( $url['custom_STEAMID'] )."', '".mysql_real_escape_string( $url['custom_PASSWORD'] )."', '".mysql_real_escape_string( $url['refip'] )."')" ) or die (mysql_error());
            logfile( "../log.txt", "a", " Write to Mysql Database Sucessfull!");
            mysql_close($db_connect);

            $mysqli2_host = "MOJHOST";
            $mysqli2_user = "MOJUSER";
            $mysqli2_pass = "MOJEHESLO";
            $mysqli2_name = "MOJEMENO";
            $mysql2_prefix = "MOJPREFIX";
        
            $db_connect2 = @mysql_connect( $mysqli2_host, $mysqli2_user, $mysqli2_pass );
            $db_select2 = @mysql_select_db( $mysqli2_name );

            if( !$db_connect2 || !$db_select2 )
                { 
                    logfile( "../log.txt", "a", "MySQL Connect Error (".mysql_error().") ".mysql_errno() );
                }
                else    
                {
                    $result = @mysql_query( "INSERT INTO `".$mysql2_prefix."amxadmins` (`username`, `password`, `access`, `flags`, `steamid`, `nickname`, `ashow`, `days`) VALUES ('".mysql_real_escape_string( $url['custom_NICK'] )."', '".mysql_real_escape_string( $url['custom_PASSWORD'] )."', '".mysql_real_escape_string( 'bnopqrstz')."', '".mysql_real_escape_string( 'a')."', '".mysql_real_escape_string( $url['custom_STEAMID'] )."', '".mysql_real_escape_string( $url['custom_NICK'] )."', '".mysql_real_escape_string( '0')."', '".mysql_real_escape_string( '30')."')" ) or die (mysql_error());                    
$id = @mysql_query( "SELECT `id` FROM `".$mysql2_prefix."amxadmins` WHERE (`username`, `password`, `access`, `flags`, `steamid`, `nickname`, `ashow`, `days`) = ('".mysql_real_escape_string( $url['custom_NICK'] )."', '".mysql_real_escape_string( $url['custom_PASSWORD'] )."', '".mysql_real_escape_string( 'bnopqrstz')."', '".mysql_real_escape_string( 'a')."', '".mysql_real_escape_string( $url['custom_STEAMID'] )."', '".$url['custom_NICK']."', '".mysql_real_escape_string( '0')."', '".mysql_real_escape_string( '30')."')" ) or die (mysql_error());                        
$id = (int) $row['id'];
$answer = "  ".$id." ";
exit( $answer );
                    $result2 = @mysql_query( "INSERT INTO `".$mysql2_prefix."admins_servers`(`admin_id`, `server_id`, `custom_flags`, `use_static_bantime`) VALUES ('".mysql_real_escape_string( '$id')."', '".mysql_real_escape_string( '6')."', '".mysql_real_escape_string( 'bnopqrstz')."', '".mysql_real_escape_string( 'no' )."') ") or die (mysql_error());
                    logfile( "../VIP_LOG/vip_act_log.txt", "a", "Write to Mysql Database Sucessfull! " );
When i remove

Code:
$id = (int) $row['id'];
I got this:
Code:
Resource id #9
(id is not good)

This works for me in phpmyadmin SQL it return good value in this example 67
Code:
SELECT `id` FROM `amx_amxadmins` WHERE (`username`, `password`, `access`, `flags`, `steamid`, `nickname`, `ashow`, `days`) = ("HODNOTA", "HODNOTA", "bnopqrstz", "a", "HODNOTA", "HODNOTA", "0", "30");
Can you help please?
gameplayonline is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 06-17-2018 , 14:09   Re: PHP+SQL Need help
Reply With Quote #2

mysql_query (and related mysql_ functions) have been deprecated, and won't be there in PHP 7+, so you might want to switch it out to either MySQLi or PDO, to ensure compatibility, in the event that you should ever decide to come out of the stone age.

To grab the "new" ID from auto increment rows, you can use the following:

MySQLi: mixed $mysqli->insert_id;
PDO: public string PDO::lastInsertId ([ string $name = NULL ] )
Legacy stone age functions: int mysql_insert_id ([ resource $link_identifier = NULL ] )
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
gameplayonline
Member
Join Date: Jun 2017
Old 06-17-2018 , 14:56   Re: PHP+SQL Need help
Reply With Quote #3

Thank you really much! 8 hours i tried to solve...
gameplayonline is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode