kaosjon Posted September 17, 2011 Share Posted September 17, 2011 i am currently in the process of creating a registration page for my website, i have managed to make it work and it adds the user to my main table user_info, however i also have other tables that i want the system to insert the user into when they join, such as a log for their ip address, the problem is i thought it would be a simple cas of selecting the user info and then inserting the fields into the ip_address table, but i keep getting the 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 'terminated')' at line 1" Anyway here is the code that i just added that created the error $sql_id = ("SELECT * FROM user_info WHERE username = '$username'"); $result = mysql_query($sql_id); $sql_result = mysql_fetch_array($result); $sql = mysql_query("INSERT INTO ip_log (id, ip_log) VALUES ('$id', '$ipaddress'") or die (mysql_error()); And the code below is the code for the whole registration page. Thanks <?php if (isset ($_POST['firstname'])){ $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = preg_replace('#[^A-Za-z0-9]#i', '', $_POST['username']); // filter everything but letters and numbers $email = $_POST['email']; $password = $_POST['password']; $cpassword = $_POST['cpassword']; $paypal_email = $_POST['paypal_email']; $country = $_POST['country']; $kingdom_name = $_POST['kingdom_name']; $kingdom_motto = $_POST['kingdom_motto']; $referal = $_POST['referal']; $email = stripslashes($email); $password = stripslashes($password); $cpassword = stripslashes($cpassword); $email = strip_tags($email); $password = strip_tags($password); $cpassword = strip_tags($cpassword); // Connect to database include_once "connect_to_mysql.php"; $emailCHecker = mysql_real_escape_string($email); $emailCHecker = str_replace("`", "", $emailCHecker); // Database duplicate username check setup for use below in the error handling if else conditionals $sql_uname_check = mysql_query("SELECT username FROM user_info WHERE username='$username'"); $uname_check = mysql_num_rows($sql_uname_check); // Database duplicate e-mail check setup for use below in the error handling if else conditionals $sql_email_check = mysql_query("SELECT email FROM user_info WHERE email='$emailCHecker'"); $email_check = mysql_num_rows($sql_email_check); // Error handling for missing data if ((!$firstname) || (!$lastname) || (!$username) || (!$email) || (!$password) || (!$cpassword) || (!$paypal_email) || (!$kingdom_name) || (!$kingdom_motto)) { $errorMsg = 'ERROR: You did not submit the following required information:<br /><br />'; if(!$firstname){ $errorMsg .= ' * Firstname<br />'; } if(!$lastname){ $errorMsg .= ' * Lastname<br />'; } if(!$username){ $errorMsg .= ' * Username<br />'; } if(!$email){ $errorMsg .= ' * Email<br />'; } if(!$password){ $errorMsg .= ' * Password<br />'; } if(!$cpassword){ $errorMsg .= ' * Password Check<br />'; } if(!$paypal_email){ $errorMsg .= ' * Paypal Email<br />'; } if(!$kingdom_name){ $errorMsg .= ' * Kingdom Name<br />'; } if(!$kingdom_motto){ $errorMsg .= ' * Kingdom Motto<br />'; } } else if ($password != $cpassword) { $errorMsg = 'ERROR: Your Password fields below do not match<br />'; } else if (strlen($username) < 4) { $errorMsg = "<u>ERROR:</u><br />Your User Name is too short. 4 - 20 characters please.<br />"; } else if (strlen($username) > 20) { $errorMsg = "<u>ERROR:</u><br />Your User Name is too long. 4 - 20 characters please.<br />"; } else if ($uname_check > 0){ $errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside of our system. Please try another.<br />"; } else if ($email_check > 0){ $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside of our system. Please use another.<br />"; } else { // Error handling is ended, process the data and add member to database //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $email = mysql_real_escape_string($email); $password = mysql_real_escape_string($password); // Add MD5 Hash to the password variable $db_password = md5($password); // GET USER IP ADDRESS $ipaddress = getenv('REMOTE_ADDR'); // Add user info into the database table for the main site table $sql = mysql_query("INSERT INTO user_info (firstname, lastname, username, email, password, country, sign_up_date) VALUES('$firstname','$lastname','$username','$email','$password', '$country', now())") or die (mysql_error()); $id = mysql_insert_id(); // Create directory(folder) to hold each user's files(pics, MP3s, etc.) mkdir("members/$id", 0755); //////////////////////////////////////////////////////////////////////// ///////////////BUILDING THE USER PROFILES/////////////////////////////// $sql_id = ("SELECT * FROM user_info WHERE username = '$username'"); $result = mysql_query($sql_id); $sql_result = mysql_fetch_array($result); $sql = mysql_query("INSERT INTO ip_log (id, ip_log) VALUES ('$id', '$ipaddress'") or die (mysql_error()); include_once 'registration_success.php'; exit(); } // Close else after duplication checks } else { // if the form is not posted with variables, place default empty variables so no warnings or errors show $errorMsg = ""; $firstname = ""; $lastname = ""; $username = ""; $email = ""; $password= ""; $cpassword = ""; $paypal_email = ""; $kingdom_name = ""; $kingdom_motto = ""; $referal = ""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247346-php-error-on-new-insert/ Share on other sites More sharing options...
creata.physics Posted September 17, 2011 Share Posted September 17, 2011 $sql = mysql_query("INSERT INTO ip_log (id, ip_log) VALUES ('$id', '$ipaddress'") or die (mysql_error()); Well I do see we're missing a ) and that a " is in the wrong place. Why not just use it in a more understanding manor? $sql = mysql_query("INSERT INTO ip_log (id, ip_log) VALUES ('$id', '$ipaddress')"); if (!$sql) { die( mysql_error() ); } Quote Link to comment https://forums.phpfreaks.com/topic/247346-php-error-on-new-insert/#findComment-1270281 Share on other sites More sharing options...
kaosjon Posted September 17, 2011 Author Share Posted September 17, 2011 Thanks for your help, i must be up too late, i normally would write it like that, and good news is that it works and inserts into the new table aswell. Rather than creating a whole new thread and just out of curiosity, is there any reason why the ip_address field is showing as ::1 in my database and not an actual ip address, is it because i am using the computer? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/247346-php-error-on-new-insert/#findComment-1270283 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 Do you know if your using IPv6? It seems that's why it's showing up like that, however I'm not too sure since I'm not knowledgeable about IPv6 at all. Quote Link to comment https://forums.phpfreaks.com/topic/247346-php-error-on-new-insert/#findComment-1270286 Share on other sites More sharing options...
kaosjon Posted September 18, 2011 Author Share Posted September 18, 2011 Yes i am using IPv6, its not a concern at the moment as i am still on testing the website locally, when i start testing on the actual internet, then i think i will get a better idea of if it is a concern. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/247346-php-error-on-new-insert/#findComment-1270287 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 Not a problem, glad to help. Also, please remember to mark this topic as solved. Quote Link to comment https://forums.phpfreaks.com/topic/247346-php-error-on-new-insert/#findComment-1270292 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.