Some Queries Won't Excute?

Post here if you need help with SQL.
Post Reply
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Some Queries Won't Excute?

Post by Helx »

Hi,

I have this page with 3 database connections setup (correctly)
But whenever I try to insert data into ONE table, it just won't do anything.

There are no errors, and query never executes.
My database connection: (The problematic one)
[syntax=php]$db1 = mysql_connect("127.0.0.1", "USERNAME", "LOLPASSWORD")or die("Connection error (AUTH|Mi)");
mysql_select_db("DB_NAME")or die("Connection error (DB|Mi)");[/syntax]

The script I'm trying to run:
[syntax=php]$for = mysql_real_escape_string(htmlentities($_POST['acc_for']),$db1);
$reg_id = mysql_real_escape_string(htmlentities($_POST['reg_id']),$db1);
$reg_pass = mysql_real_escape_string(htmlentities($_POST['reg_pass']),$db1);
$crt = mysql_real_escape_string(htmlentities($_POST['crt']),$db1);
mysql_query("INSERT INTO reg_id (for, registration_number, registration_password, CRT, registrar) VALUES ('$for', '$reg_id', '$reg_pass', '$crt', '$usr')", $db1);[/syntax]

I could only assume syntax? Thats always the problem with me :P
Please help me, its been annoying me all day :/
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Some Queries Won't Excute?

Post by jacek »

I think CRT is a MySQL keyword (since the syntax highlighting capitalised it), try putting backticks around the table and column names.
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: Some Queries Won't Excute?

Post by Helx »

I did a bit of a change around with the code, but the part where it inserts the username and password is where it just seems to 'skip out' completely.

[syntax=php]$cs = make_salt(50);
$s1 = make_salt(20);
$s2 = make_salt(30);
$s3 = make_salt(40);

$bHDw = hash('gost',$_POST['bHDw']);
$ins_salt = "INSERT INTO salt (email, coresalt, salt1, salt2, salt3) VALUES ('{$bHDw}', '{$cs}', '{$s1}', '{$s2}', '{$s3}')";
$ins_salt = mysql_query($ins_salt,$db2);
$email_register = base64_encode($_POST['bHDw']);
$email_register = str_replace('=','',$email_register);
$pass_register = $_POST['jdYhs'];
$pass_ins = enc($email_register,$pass_register,$cs,$s1,$s2,$s3);

$ip_4 = $_SERVER['HTTP_CF_CONNECTING_IP'];
$ip_6 = v4tov6($ip_4);

$cntry = $_SERVER['HTTP_CF_IPCOUNTRY'];
$username = htmlentities(strip_tags($_POST['u']));
$joinUNIX = time();

// This part is problematic.
mysql_insert('usr', array(
'email' => $email_register,
'username' => $username,
'password' => $pass_ins,
'ipv4' => $ip_4,
'ipv6' => $ip_6,
'joined' => $joinUNIX,
'country' => $cntry,
));[/syntax]

/EDIT:
Oops XD heres the mysql_insert function that somebody wrote on the PHP.net page:
[syntax=php]function mysql_insert($table, $inserts){
$values = array_map('mysql_real_escape_string', array_values($inserts));
$keys = array_keys($inserts);
return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}[/syntax]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Some Queries Won't Excute?

Post by jacek »

I would try writing your own SQL, or at least print out the SQL that the function create to make sure it makes sense.
Image
Post Reply