thara Posted July 14, 2012 Share Posted July 14, 2012 Hi.. everyone.. I have a problem in my php form now. Earlier it worked properly. It mean I registered 7 institutes and it was no problem the form worked very well. But when I try to register my 8 institute using same php script I cant register it. It is very confusing for me and I cant think actually what has happen. There is no error message as well. This is my form ]http://www.lankainstitute.com/centersignup/institute_registration_form.php[/b] can anybody tell me what has happen? any comments are greatly appreciated. Thank YOu. Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/ Share on other sites More sharing options...
lordshoa Posted July 14, 2012 Share Posted July 14, 2012 What is the code around the line 314 of the institute_registration_form.php '/home/www/lankainstitute.com/centersignup/institute_registration_form.php' on line 314: Undefined index: category '/home/www/lankainstitute.com/centersignup/institute_registration_form.php' on line 314: Invalid argument supplied for foreach() Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361502 Share on other sites More sharing options...
lordshoa Posted July 14, 2012 Share Posted July 14, 2012 The category seem to be mssing from the form drop down so you cannot select them maybe look at the code and see why they are missing Undefined index: category City option is missing from the send form as I can see it [district] => 3 [tel] => The array should be [district] => 3 [city] => [tel] => Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361510 Share on other sites More sharing options...
scootstah Posted July 14, 2012 Share Posted July 14, 2012 Post code please. Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361514 Share on other sites More sharing options...
thara Posted July 16, 2012 Author Share Posted July 16, 2012 This is my php code... if (empty($reg_errors)) { // If everything's OK... // Make sure the email address and username are available: $qy = "SELECT email FROM login WHERE email='$email'"; $re = mysqli_query ($dbc, $qy); // Get the number of rows returned: $rows = mysqli_num_rows($re); if ($rows == 0) { // No problems! // Add the login details to the database... $qy1 = "INSERT INTO login (email, password, login_level, last_login) VALUES ('$email', SHA1('$pass'), 2, now() )"; $re1 = mysqli_query ($dbc, $qy1); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. $loginId = mysqli_insert_id($dbc); // Add the address details to the database... $q1 = "INSERT INTO address (address_one, address_two, city_id ) VALUES ('$address1', '$address2', '$cityId' )"; $r1 = mysqli_query ($dbc, $q1); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. $addressId = mysqli_insert_id($dbc); // Add the contact details to the database... $q2 = "INSERT INTO contact (telephone, mobile, email, web_address, fb_address, twitter_address, google_address, best_time_call, privacy_setting ) VALUES ('$tel', '$mobile', '$email', '$web', '$facebook', '$twitter', '$google', '$bestTime', '$privacy' )"; $r2 = mysqli_query ($dbc, $q2); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. $contactId = mysqli_insert_id($dbc); // Auto Generating the Institute Code $q3 = 'SELECT institute_code FROM institutes ORDER BY registration_date DESC LIMIT 1'; $r3 = @mysqli_query ($dbc, $q3); if ( mysqli_num_rows($r3) == 1 ) { // Valid login ID. $row = mysqli_fetch_array ($r3, MYSQLI_ASSOC); $instituteCode = $row['institute_code']; $instituteCode += 1; } else { $instituteCode = 1200; } // Create the activation code: $active = md5(uniqid(rand(), true)); $q4 = "INSERT INTO institutes ( login_id, address_id, contact_id, institute_code, institute_name, institute_slogan, introduction_note, institute_history, institute_present, active, registration_date ) VALUES ( '$loginId', '$addressId', '$contactId', '$instituteCode', '$insName', '$Slogan', '$instroduction', '$history', '$present', '$active', NOW() )"; $r4 = mysqli_query ($dbc, $q4); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. $instituteId = mysqli_insert_id($dbc); // Send the email: $body = "Thank you for registering at www.lankainstitute.com website. To activate your institute profile, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$active"; mail( '[email protected]', 'Institute Profile: Registration Confirmation', $body, 'From: ' . $email . ''); foreach( $medium as $value){ $q = "INSERT INTO institute_medium ( medium_id, institute_id ) VALUES ( '$value', '$instituteId' )"; $r = mysqli_query ($dbc, $q); } foreach( $group as $value){ $q = "INSERT INTO institute_option ( option_id, institute_id ) VALUES ( '$value', '$instituteId' )"; $r = mysqli_query ($dbc, $q); } foreach( $_SESSION['category'] as $value ) { $q = "INSERT INTO institute_category ( institute_id, category_id ) VALUES ( ?, ? )"; $stmt = mysqli_prepare( $dbc, $q ); mysqli_stmt_bind_param( $stmt, 'ii', $instituteId, $value ); mysqli_stmt_execute( $stmt ); } unset($_SESSION['category']); // Clear $_POST: $_POST = array(); $url = 'http://localhost/lanka_institute/centersignup/register_success.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. // Print a message: //echo '<span style="text-transform: uppercase; font-weight: bold;">Your Institute has been added to the Lanka Institute Web Site.</span>'; } } } } } else { // The email address or username is not available. $reg_errors['email'] = 'This email address has already been registered. Try again with a different email'; } // End of $rows == 0 IF. } // End of empty($reg_errors) IF Data insert to login, address, contact table very well. But data is not inserting to institute table. It works earlier but now it is not. Anybody can tell me where I have gone wrong.... Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361802 Share on other sites More sharing options...
carugala Posted July 16, 2012 Share Posted July 16, 2012 thara, what changed? Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361804 Share on other sites More sharing options...
scootstah Posted July 16, 2012 Share Posted July 16, 2012 Which query isn't working? This one? $q4 = "INSERT INTO institutes ( login_id, address_id, contact_id, institute_code, institute_name, institute_slogan, introduction_note, institute_history, institute_present, active, registration_date ) VALUES ( '$loginId', '$addressId', '$contactId', '$instituteCode', '$insName', '$Slogan', '$instroduction', '$history', '$present', '$active', NOW() )"; Have you checked if there is a MySQL error? $r4 = mysqli_query ($dbc, $q4) or die ('MySQL error!<br />Query: ' . $q4 . '<br />Error: ' . mysqli_error($dbc)); Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361805 Share on other sites More sharing options...
thara Posted July 16, 2012 Author Share Posted July 16, 2012 yes.. I checked it.. it works properly.. Script also work in localhost but not work in live server.. Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361806 Share on other sites More sharing options...
scootstah Posted July 16, 2012 Share Posted July 16, 2012 Can you echo the problem query out and post it here? echo $q4; (or whatever query is the problem). Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361808 Share on other sites More sharing options...
thara Posted July 16, 2012 Author Share Posted July 16, 2012 code is not execute in this if loop.. 'if (mysqli_affected_rows($dbc) == 1) { // If it ran OK'. But this loop working properly in localhost.. if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. $contactId = mysqli_insert_id($dbc); // Auto Generating the Institute Code $q3 = 'SELECT institute_code FROM institutes ORDER BY registration_date DESC LIMIT 1'; $r3 = @mysqli_query ($dbc, $q3); if ( mysqli_num_rows($r3) == 1 ) { // Valid login ID. $row = mysqli_fetch_array ($r3, MYSQLI_ASSOC); $instituteCode = $row['institute_code']; $instituteCode += 1; } else { $instituteCode = 1200; } // Create the activation code: $active = md5(uniqid(rand(), true)); $q4 = "INSERT INTO institutes ( login_id, address_id, contact_id, institute_code, institute_name, institute_slogan, introduction_note, institute_history, institute_present, active, registration_date ) VALUES ( '$loginId', '$addressId', '$contactId', '$instituteCode', '$insName', '$Slogan', '$instroduction', '$history', '$present', '$active', NOW() )"; $r4 = mysqli_query ($dbc, $q4); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. $instituteId = mysqli_insert_id($dbc); // Send the email: $body = "Thank you for registering at www.lankainstitute.com website. To activate your institute profile, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$active"; mail( '[email protected]', 'Institute Profile: Registration Confirmation', $body, 'From: ' . $email . ''); foreach( $medium as $value){ $q = "INSERT INTO institute_medium ( medium_id, institute_id ) VALUES ( '$value', '$instituteId' )"; $r = mysqli_query ($dbc, $q); } foreach( $group as $value){ $q = "INSERT INTO institute_option ( option_id, institute_id ) VALUES ( '$value', '$instituteId' )"; $r = mysqli_query ($dbc, $q); } foreach( $_SESSION['category'] as $value ) { $q = "INSERT INTO institute_category ( institute_id, category_id ) VALUES ( ?, ? )"; $stmt = mysqli_prepare( $dbc, $q ); mysqli_stmt_bind_param( $stmt, 'ii', $instituteId, $value ); mysqli_stmt_execute( $stmt ); } unset($_SESSION['category']); // Clear $_POST: $_POST = array(); $url = 'http://www.lankainstitute.com/centersignup/register_success.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. // Print a message: //echo '<span style="text-transform: uppercase; font-weight: bold;">Your Institute has been added to the Lanka Institute Web Site.</span>'; } } But data is inserting into contact table. Quote Link to comment https://forums.phpfreaks.com/topic/265669-form-data-cant-insert-now/#findComment-1361809 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.