Jump to content

[SOLVED] My sql insert script isn't inserting? no errors


A2xA

Recommended Posts

I've made a script along with my forum register to add the same entries into a different database.  In the first register file it has the variables and such that are in the handle_this function passed over to SiteRegister.php

 

Where then the second SiteRegister.php file inserts into a database

 

 

The first file (with variables):

//Shit that won't work
    $memberID = registerMember($regOptions);
    require_once('/x/x/x/x/x/SiteRegister.php');
    handle_this($regOptions, $memberID);

 

Second file (SiteRegister.php):

<?php
function handle_this($regOptions, $memberID) {
global $db_prefix;



mysql_query("INSERT INTO users (userName, userUser, userPass, UserID, userEmail)
VALUES (" . $regOptions['username'] . ", " . $regOptions['username'] . ", " . $regOptions['password'] . ", " . $memberID . " " . $regOptions['email'] . ")");

}


?>

 

If someone could take a look at the code and tell me why it's not working I'd greatly appreciate it

Link to comment
Share on other sites

The only obvious problem is that string values must be enclosed in single-quotes.

 

You should form your query in a variable (for several reasons) and then echo it to make sure it contains what you expect.

 

Your mysql_query() also contains no error checking to get it tell you why it is failing.

 

At a minimum, add or die(mysql_error());

Link to comment
Share on other sites

I got this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a-3@inbox.com)' at line 2

 

I'm getting somewhere now.  The a-3@inbox.com is the e-mail I used in the registration.

Link to comment
Share on other sites

<?php

mysql_query("INSERT INTO users (userName, userUser, userPass, UserID, userEmail)
VALUES ('".$regOptions['username']."', '".$regOptions['username']."', '".$regOptions['password']."', '".$memberID."', '".$regOptions['email']."')");

?>

 

This still does not data sanitisation - make sure you check for the usual culprits like sql injection...

 

Cheers,

 

Paul

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.