MySQL not allowing INSERT querys or im bad at coding one of the two

Daltron

Web Developer
Aug 6, 2015
283
154
Alrighty so, here is my code

PHP:
<?php require_once("inc/core.god.php");
    
    if(Loged == TRUE)
    {
        header("Location: me");
        exit;
    }
    
    if(MANTENIMIENTO == '1')
    {
        header("Location: mantenimiento");
        exit;
    }
    
    if(isset($_POST['Usuario']) && isset($_POST['Mail']) && isset($_POST['Contrasena']) && isset($_POST['RContrasena']) && isset($_POST['Contracode']))
    {   
        
        $Getnombre = mysql_query("SELECT * FROM users WHERE username = '". $_POST['Usuario'] ."'");
        $Getmail = mysql_query("SELECT * FROM users WHERE mail = '". $_POST['Mail'] ."'");
        
        if(empty($_POST['Usuario']) || empty($_POST['Mail']) || empty($_POST['Contrasena']) || empty($_POST['RContrasena']) || empty($_POST['Contracode']))
        {
            $regerror = 'Do not leave the fields empty';
        }
        elseif(mysql_num_rows($Getnombre) > 0)
        {
            $regerror = 'The username is already in use, put another';
        }
        elseif(mysql_num_rows($Getmail) > 0)
        {
            $regerror = 'The email is already in use, put another';
        }
        elseif($_POST['Contrasena'] !== $_POST['RContrasena'])
        {
            $regerror = 'Passwords do not match';
        }
        elseif(strlen($_POST['Usuario']) > 12 || strlen($_POST['Usuario']) < 3)
        {
            $regerror = 'The username must be between 3 and 12 characters';
        }
        elseif(strrpos($_POST['Usuario'], "MOD-") !== false)
        {
            $regerror = 'You can not register with the prefix <i>MOD-</i>';
        }
        elseif(strrpos($_POST['Usuario'], " ") || strrpos($_POST['Usuario'], " ") !== false)
        {
            $regerror = 'Your name can not contain spaces';
        }
        elseif(strrpos($_POST['Usuario'], ".") || strrpos($_POST['Usuario'], ".") !== false)
        {
            $regerror = 'Your name can not contain points';
        }
        else
        {
            mysql_query("INSERT INTO users (username, password, passcode, mail, look, gender, motto, ip_register, credits, account_created, account_day_of_birth) VALUES ('". filtro($_POST['Usuario']) ."', '".md5($_POST['Contrasena'])."', '".md5($_POST['Contracode'])."', '". filtro($_POST['Mail']) ."', '". $Holo['look'] ."', '". $Holo['gender'] ."', '". $Holo['mision'] ."', '". $ip ."', '". $Holo['monedas'] ."', '" . time() ."', '" . time() ."')");
            $_SESSION['Username'] = $_POST['Usuario'];
            $_SESSION['Password'] = $_POST['Contrasena'];
            $_SESSION['Contracode'] = $_POST['Contracode'];
            header("Location: way");
        }
    }
    
    $_GET['Usuario'] = $_POST['Usuario'];
    $_GET['Mail'] = $_POST['Mail'];
    $_GET['Contrasena'] = $_POST['Contrasena'];
    $_GET['RContrasena'] = $_POST['RContrasena'];
    $_GET['Contracode'] = $_POST['Contracode'];
    
?>

so basically upon registration it takes me to the /me page but it doesnt ever add the user into the users table.
All help is greatly appreciated thanks xx
 

Higoka

Active Member
Dec 16, 2018
174
74
enable error reporting and register again. post any errors here.
PHP:
error_reporting(E_ALL);

ini_set('display_errors', true);
ini_set('display_startup_errors', true);

do you use arcturus database? if so both columns ip_register and ip_current need to have a value. you only have ip_register.
 

Daltron

Web Developer
Aug 6, 2015
283
154
enable error reporting and register again. post any errors here.
PHP:
error_reporting(E_ALL);

ini_set('display_errors', true);
ini_set('display_startup_errors', true);

do you use arcturus database? if so both columns ip_register and ip_current need to have a value. you only have ip_register.
Yes, Im using arc
Post automatically merged:

only error
Line 108:
Deleting the line doesn't fix the issue.
Added ip_current, still doesn't work.
Is STRICT_TRANS_TABLES enabled?
Turned off strict trans, restarted mysql still doesn't allow me to insert.

It also act's like im registered and sends me to /me page.
 
Last edited:

Higoka

Active Member
Dec 16, 2018
174
74
add echo 'hello world'; before your execute the mysql_query. register again and see if the hello world is there if not you know that the query never gets executed.
 

Higoka

Active Member
Dec 16, 2018
174
74
That doesn't really prove much.

How are you changing the SQL mode?

it does. if you dont see the echo then you know the code inside the last else block never gets executed. so you can be sure the problem has to be somewhere above that. thats how i debug in php also var_dump is your best friend.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
it does. if you dont see the echo then you know the code inside the last else block never gets executed. so you can be sure the problem has to be somewhere above that. thats how i debug in php also var_dump is your best friend.
The conditions to reach that echo can still be met and have the query fail due to any number of reasons (ie - filtro() is not a default function and hopefully just a translation issue here). We know the else block is being reached because of the redirect.
 

Daltron

Web Developer
Aug 6, 2015
283
154
We know it reaches the header block because it redirects to /way. So could it be an issue with the privileges of the user for mysql?

could it be an issue in here?
<?php
session_start();

define("DR", $_SERVER['DOCUMENT_ROOT']);
ini_set('display_errors', 0);

if(file_exists(DR .'/inc/config.god.php')) {
require_once(DR .'/inc/config.god.php');
} else {
require_once('/inc/config.god.php');
}

$H = date('H');
$i = date('i');
$s = date('s');
$m = date('m');
$d = date('d');
$Y = date('Y');
$j = date('j');
$n = date('n');
$today = $d;
$month = $m;
$year = $Y;
$getmoney_date = date('d/m/Y',mktime($m,$d,$Y));
$birthday_date = date('d/m', mktime($m,$d));
$date_normal = date('d/m/Y',mktime($m,$d,$Y));
$date_full = date('d/m/Y - H:i:s',mktime($H,$i,$s,$m,$d,$Y));

function GetLast($a){
if(!empty($a) || !$a == ''){
if(is_numeric($a)){
$date = $a;
$date_now = time();
$difference = $date_now - $date;
if($difference <= '59'){ $echo = ''. $difference .' seconds ago'; }
elseif($difference <= '3599' && $difference >= '60'){
$minutos = date('i', $difference);
if($minutos[0] == 0) { $minutos = $minutos[1]; }
if($minutos == 1) { $minutos_str = 'minute'; }
else { $minutos_str = 'minutes'; }
$echo = ''.$minutos.' '.$minutos_str.' ago';//Minutos
}elseif($difference <= '86399' && $difference >= '3600') {
$horas = floor(date('H', $difference));
if($horas == 1) { $horas_str = 'hour'; }
else { $horas_str = 'hours'; }
$echo = ''.$horas.' '.$horas_str.' ago';//Minutos
}elseif($difference <= '518399' && $difference >= '86400'){
$dias = floor(date('d', $difference));
if($dias == 1) { $dias_str = 'day'; }
else { $dias_str = 'days'; }
$echo = ''.$dias.' '.$dias_str.' ago';//Minutos
}elseif($difference <= '2678399' && $difference >= '518400'){
$semana = floor(date('d', $difference) / 7).'<!-- WTF -->';
if($semana == 1) { $semana_str = 'week'; }
else { $semana_str = 'weeks'; }
$echo = ''.floor($semana).' '.$semana_str.' ago';//Minutos
}else { $echo = ''.floor(date('m', $difference)).' month(s) ago'; }
return $echo;
}else{ return $a; }
}else{ return 'Account never been online'; }
}

function filtro($str) {
$str = mysql_real_escape_string(htmlspecialchars(trim($str)));;
$texto = $str;
$texto = str_replace("INSERT","IN-SER-T",$texto);
$texto = str_replace("DELETE","DE-LE-TE",$texto);
$texto = str_replace("TRUNCATE","TRUN-CA-TE",$texto);
$texto = str_replace("SELECT","SE-LEC-T",$texto);
$texto = str_replace("ALTER","AL-TER",$texto);
$texto = str_replace("UPDATE","UP-DA-TE",$texto);
$texto = str_replace("inert","IN-SER-T",$texto);
$texto = str_replace("delete","DE-LE-TE",$texto);
$texto = str_replace("truncate","TRUN-CA-TE",$texto);
$texto = str_replace("select","SE-LEC-T",$texto);
$texto = str_replace("alter","AL-TER",$texto);
$texto = str_replace("update","UP-DA-TE",$texto);
$texto = str_replace("script","",$texto);
$texto = str_replace("SCRIPT","",$texto);
$texto = str_replace('"','&#34;',$texto);
$texto = str_replace("'","&#39;",$texto);
$texto = str_replace("<","&#60;",$texto);
$texto = str_replace(">","&#62;",$texto);
$texto = str_replace("(","",$texto);
$str = str_replace(")","",$texto);
return $str;
}

function SacarIP() {
if($_SERVER) {
if($_SERVER["HTTP_X_FORWARDED_FOR"]) {
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif ($_SERVER["HTTP_CLIENT_IP"]) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if(getenv("HTTP_X_FORWARDED_FOR")) {
$realip = getenv("HTTP_X_FORWARDED_FOR");
} elseif(getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;
}
$ip = SacarIP();

function Onlines()
{
$on = mysql_query("SELECT * FROM users WHERE online = '1'");
$on1 = mysql_num_rows($on);
$ons = $on1;
return $ons;
}

function OnlineStatusButton()
{
$host = "";
$port = 3000;

$waitTimeoutInSeconds = 1;

if($fp = @fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)) {

echo("<div class='online'><i class='fas fa-restroom'></i> <span class='count'>".Onlines()."</span> Neons Online</div>");

fclose($fp);

} else {

echo("<div class='online'>The hotel is closed</div>");
}
}

function OnlineStatusBigButton()
{
$host = "";
$port = 3000;

$waitTimeoutInSeconds = 1;

if($fp = @fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)) {

echo("<div class='col-xl-4 col-lg-6 text-center d-none d-lg-block'><a href='/hotel' target='_blank' class='enter'><i class='fas fa-arrow-circle-right'></i> Enter Neon</a></div>");

fclose($fp);

} else {

echo("");
}
}

function OnlineStatusEntryMenu()
{
$host = "";
$port = 3000;

$waitTimeoutInSeconds = 1;

if($fp = @fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)) {

echo("<div class='col-lg-12 col-12'><a href='/hotel' target='_blank' class='enter'><div><i class='fas fa-arrow-circle-right'></i> Enter Neon</div></a></div>");

fclose($fp);

} else {

echo("");
}
}

function OnlineStatusHotel()
{
$host = "";
$port = 3000;

$waitTimeoutInSeconds = 1;

if($fp = @fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)) {

echo("");

fclose($fp);

} else {

echo("<meta http-equiv='refresh' content='60'>");
die("<link rel='stylesheet' href='/css/client.css'><div id='client'><habbo-client-error><div class='client-error__background-frank'><div class='client-error__text-contents'><h1 class='client-error__title'>Frank está dormindo</h1><p>Parece que o nosso gerente tirou um tempinho para cochilar, aliás todos merecem descansar um pouco, não concorda com a gente?<br><br>Volte em breve, talvez ele já tenha acordado!</p></div></div></habbo-client-error></div>");
}
}

function OnlineStatusRcon()
{
$host = "";
$port = 3000;

$waitTimeoutInSeconds = 1;

if($fp = @fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)) {

echo("");

fclose($fp);

} else {

die("<div class='col-12'><div class='card rules-card'><div class='card-body'><div class='alert alert-danger' role='alert'><div class='row align-items-center'><div class='col-1 alert-icon-col'><i class='fas fa-file-invoice' style='font-size: 36px;'></i></div><div class='col'><b>O Hotel está desligado!</b><br>Este recurso não vai funcionar enquanto o Emulador estiver desligado.<br><br>Estamos te levando de volta em Cinco segundos...</div></div></div></div></div></div><meta http-equiv='refresh' content='6; url=home.php'>");
}
}

if(isset($_SESSION['Username']) && isset($_SESSION['Password']))
{
$Sesion = mysql_query("SELECT * FROM users WHERE username = '". $_SESSION['Username'] ."' AND password = '". md5($_SESSION['Password']) ."'");

if(mysql_num_rows($Sesion) > 0)
{
$myrow = mysql_fetch_assoc($Sesion);
define("Loged", TRUE);
}
}
else
{
define("Loged", FALSE);
}

$last_new = mysql_fetch_assoc(mysql_query("SELECT * FROM cms_news ORDER BY id DESC LIMIT 1"));

$chb = mysql_query("SELECT * FROM bans WHERE user_id = '". $myrow['id'] ."' OR ip = '". $myrow['ip_last'] ."'");

$mantenimiento = mysql_query("SELECT * FROM cms_mantenimiento");
$mantenimientoo = mysql_fetch_assoc($mantenimiento);
$mant = $mantenimientoo['mantenimiento'];
define("MANTENIMIENTO", $mant);
?>
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
Enable MySQL's general query log. The query is attempting to be executed and you will be able to see exactly what is being passed. If it's not already showing in it's err log then attempting to re-run the query will give a more meaningful error.
 

Daltron

Web Developer
Aug 6, 2015
283
154
general_log has been turned on, nothing is being posted to the log once i use register.php to register but yet it still redirects me to way.php? Ecko could you add me on discord Caz#5227 and maybe we could TV to attempt to fix this. @Ecko
 

Users who are viewing this thread

Top