TJMAudio Posted September 30, 2007 Share Posted September 30, 2007 <?php case 'register': $addr = $_SERVER['REMOTE_ADDR']; $username = $_POST['username']; $password = $_POST['password']; $cpassword = $_POST['cpassword']; $email = $_POST['email']; $cemail = $_POST['cemail']; $challenge = $_POST['recaptcha_challenge_field']; $response = $_POST['recaptcha_response_field']; if(empty($addr) || empty($username) || empty($password) || empty($cpassword) || empty($email) || empty($cemail) || empty($challenge) || empty($response)) { echo "<script>window.location.href='index.php?m=register&e=0'</script>"; exit; } $checkmultipleusers = mysql_query("SELECT * FROM users WHERE username='$username'"); if(mysql_num_rows($checkmultipleusers) >= 1) { echo "<script>window.location.href='index.php?m=register&e=1'</script>"; exit; } if($password != $cpassword) { echo "<script>window.location.href='index.php?m=register&e=2'</script>"; exit; } if($email != $cemail) { echo "<script>window.location.href='index.php?m=register&e=3'</script>"; exit; } require_once('includes/recaptchalib.php'); $privatekey = "..."; $resp = recaptcha_check_answer ($privatekey, $addr, $challenge, $response); if (!$resp->is_valid) { echo "<script>window.location.href='index.php?m=register&e=4'</script>"; exit; } $activationcode = md5($username); $registerdate = date("F j, Y"); $registeruser = mysql_query("INSERT INTO users (`id`, `permissions`, `registerdate`, `username`, `password`, `email`, `ip`, `secondip`, `thirdip`, `fourthip`, `fifthip`, `activation`, `ipflag`) VALUES (NULL, '0', $registerdate, $username, $password, $email, $addr, '', '', '', '', '$activationcode', '0')"); if($registeruser) { $_SESSION['username'] = $username; echo "<script>window.location.href='index.php?m=home'</script>"; } else { echo "Something went wrong."; exit; } break; Even if all of the error checks pass, the MySQL will not insert the information in to the table.. not even partial. Link to comment https://forums.phpfreaks.com/topic/71275-php-script-not-inserting-data/ Share on other sites More sharing options...
Barand Posted September 30, 2007 Share Posted September 30, 2007 string values in the query, such as $username, $password etc need single quotes eg INSERT INTO tablename (user,pwd) VALUES ('$username', '$password'); If, when you use mysql_query() you trap for error messages, it tells you thing like this. $result = mysql_query(...) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/71275-php-script-not-inserting-data/#findComment-358557 Share on other sites More sharing options...
TJMAudio Posted September 30, 2007 Author Share Posted September 30, 2007 string values in the query, such as $username, $password etc need single quotes eg INSERT INTO tablename (user,pwd) VALUES ('$username', '$password'); If, when you use mysql_query() you trap for error messages, it tells you thing like this. $result = mysql_query(...) or die(mysql_error()); Ah, so obvious, thank you. I haven't coded PHP in a couple of years, still rusty on some of the finer details. Link to comment https://forums.phpfreaks.com/topic/71275-php-script-not-inserting-data/#findComment-358598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.