Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:01:00+00:00 2026-06-13T17:01:00+00:00

I am trying to store information sent via a form into a MySQL DB.

  • 0

I am trying to store information sent via a form into a MySQL DB. It doesn’t load the next page nor does it store the information.

My header requires init.php which I can confirm has the correct database connection credentials.

The following is my HTML and “uploader” script – I know it must be something silly but this is where the issue lies, in the html and/or the uploader.php.

If someone could run through my code and point out each issue (and possibly a re-work of my code) it would be very much appreciated! Thank you!!

HTML (I’ve reduced the Date of Birth options so there’s less code here)

        <h2>Choose Your File</h2>
                 <form id="submit-photo" action="index.php?p=uploader" enctype="multipart/form-data" method="POST">

    <input type="hidden" name="MAX_FILE_SIZE" value="5242880" />   
            <div id="FileUpload">

                <input type="file" name="photo" id="BrowserHidden" onchange="getElementById('FileField').value = getElementById('BrowserHidden').value;" />

                <div id="BrowserVisible"><input type="text" id="FileField" /></div>
            <span class="error"><?php if(isset($_SESSION['flash_message']['photo'])) echo $_SESSION['flash_message']['photo'] ?>
            </span></div>               

            <fieldset>
                <label for="name">Name</label>
                <input type="text" name="name" id="name">
            </fieldset>

            <fieldset>
            <label for="dob">DOB</label>
            <div class="dob-select">
            <select name="dob_day" id="dob_day">
            <option value="01">01</option>
            <option value="02">02</option>
            <option value="03">03</option>
            <option value="04">04</option>
            <option value="05">05</option>
            </select>
            </div>
            <div class="dob-select">
            <select name="dob_month" id="dob_month">
            <option value="01">Jan</option>
            <option value="02">Feb</option>
            <option value="03">Mar</option>
            <option value="04">Apr</option>
            </select>
            </div>
            <div class="dob-select">
            <select name="dob_year" id="dob_year">
            <option value="2012">2012</option>
            <option value="2011">2011</option>
            <option value="2010">2010</option>
            </select>
            </div>
            </fieldset>

            <fieldset>
                <label for="postcode">Postcode</label>
                <input type="text" class="short" name="postcode" id="postcode">
            </fieldset>

            <fieldset>
                <label for="email">Email</label>
                <input type="email" name="email" id="email">
            </fieldset>

            <fieldset>                
                <label for="subscribe"><input type="checkbox" class="left" id="subscribe"> <p class="left">subscribe</p></label>
                <input type="submit" name="submit">
            </fieldset>       
        </form>

DB Columns

  • id (auto-incremented)
  • name
  • photo (path to file)
  • email
  • date (date of birth: day, month, year to be combined to form this)
  • postcode
  • subscribe (should be 0 or 1)
  • approve
  • created (timestamp)

Database

Uploader PHP

<?php $error = array();
require_once 'init.php';
//Is request?
if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') {

    //$friend = ( $_POST['friend'] == 'true' ) ? 1 : 0;

    $required_array = array(
        'name' => 'Name',
        'dob_day' => 'Day',
        'dob_month' => 'Month',
        'dob_year' => 'Year',
        'postcode' => 'Postcode',
        'email' => 'Email Address',
        'subscribe' => 'subscribe'
    );
    $required_error = array();
    foreach( $required_array as $field_name => $field ) {
        if(!isset($_POST[$field_name]) OR empty($_POST[$field_name]) OR $_POST[$field_name] == '') {
            $required_error[$field_name] = 'Please insert your '. $field;
        }
    }

    $_POST['email'] = verify_email($_POST['email']);
    if($_POST['email'] == FALSE && !isset($error['email']))
        $error['email'] = 'Please use a valid email address';


    //Validate the form key
    if(!isset($_POST['form_key']) || !$formKey->validate()) {
        //Form key is invalid, show an error
        $error['general'] = 'Use the real form!';
    } else {
        if((!empty($_FILES["photo"])) && ($_FILES['photo']['error'] == 0)) {
            $filename = basename($_FILES['photo']['name']);
            $ext = substr($filename, strrpos($filename, '.') + 1);

            //Check if the file is JPEG image and it's size is less than 1Mb
            if ( ($ext == "jpg") && ($_FILES["photo"]["type"] == "image/jpeg") && ($_FILES["photo"]["size"] <= 5242880) ) {
                //Determine the path to which we want to save this file
                $newname = str_replace( ' ', '_', trim( strip_tags( $_POST['name'] ) ) ) . _ . $formKey->generateKey() . '_' . time() . '.jpg';

                //Check if the file with the same name is already exists on the server
                if (!file_exists($newname)) {
                    if (sizeof($required_error) == 0) {
                        //Attempt to move the uploaded file to it's new place
                        if ((move_uploaded_file($_FILES['photo']['tmp_name'], './photos/'. $newname))) {
                            $move_status = 'done';
                        } else {
                            $error['photo'] = "A problem occurred during file upload!";
                        }
                    }
                } else {
                    $error['photo'] = "File ".$_FILES["photo"]["name"]." already exists";
                }
            } else {
                $error['photo'] = "Only .jpg images under 5Mb are accepted for upload". $_FILES["photo"]["size"] . $_FILES["photo"]["type"] . '====' . $ext;
            }
        } else {
            $error['photo'] = "No photo uploaded";
        }
    }

    $error = $error + $required_error;

    if (sizeof($error) == 0 AND $move_status == 'done') {
                    $_POST['date'] = $_POST['dob_day'].'-'.$_POST['dob_month'].'-'.$_POST['dob_year'];
        $query = sprintf("INSERT INTO `$db_name`.`submissionform` (`id` , `name` , `photo` , `email` , `date` , `postcode` , `subscribe` , `approve` , `created` )
            VALUES ( NULL , '%s', '%s', '%s', '%s', '%s', '%s', '0', CURRENT_TIMESTAMP );",
            mysql_real_escape_string($_POST['name']),
            mysql_real_escape_string($newname),
            mysql_real_escape_string($_POST['email']),
            mysql_real_escape_string($_POST['date']),
            mysql_real_escape_string($_POST['postcode']),
            mysql_real_escape_string($_POST['subscribe']),
            mysql_real_escape_string($_POST['approve']),
            mysql_real_escape_string($_POST['message'])
            );
        mysql_query('SET AUTOCOMMIT=0');
        $result1 = mysql_query($query);

        $last_id = mysql_insert_id();

        if ($result1)
            $success = 'Done';
        else
            $error['general'] = 'Error when submitting your form, please try again.';

        //mysql_free_result($result);
        mysql_close();
    }

}


if ($success == 'Done') {
    $page = 'uploader';
    include 'header.php';
    echo '<img height="782" style="float:left;" src="./assets/img/success.png" />';
    include 'footer.php';
} else {
    $_SESSION['flash_message'] = $error;
    $_SESSION['recent_field'] = $_POST;
    header('Location: ./index.php');
}
?>

edit: I did some debugging- by placing ini_set('display_errors', 'On'); error_reporting(E_ALL); at the top of uploader.php

Errors are:

Notice: Undefined variable: success in …./uploader.php on line 100

Warning: Cannot modify header information – headers already sent by (output started at…./uploader.php:100) in ….uploader.php on line 110

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:01:01+00:00Added an answer on June 13, 2026 at 5:01 pm

    checkbox subscribe doesn’t have a name field, in these lines,

    <fieldset>                
       <label for="subscribe"><input type="checkbox" class="left" id="subscribe"> <p class="left">subscribe</p></label>
       <input type="submit" name="submit">
    </fieldset>    
    

    So the check inside foreach won’t pass through.

    foreach( $required_array as $field_name => $field ) {
        if(!isset($_POST[$field_name]) OR empty($_POST[$field_name]) OR $_POST[$field_name] == '') {
            $required_error[$field_name] = 'Please insert your '. $field;
        }
    }
    

    Also, $_POST['form_key'] is not being set, which wouldn’t pass this line,

    //and subsequently have an $error and not execute the query.
    if(!isset($_POST['form_key']) || !$formKey->validate()) { 
    

    Is id a primary key? you’re inserting a NULL value to it, in the query. It won’t auto-increment if you pass an id value in the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to store some DOM information into an Array so I can
I'm trying to store information on a form by using sessions in case the
I am trying to store recurrence event information into a database. I want to
I am trying to read a file and store the information in unsigned char
I'm trying to store an image into an SQL database without using temporary files.
I am trying to store information in NSUserdefault. My intention is to show a
Hello iam trying to store sum information inside a SQL Server table , but
We have an XMPP application that uses MySQL to store information. We are not
I'm trying to store some information using XML, what would be the correct method
Hey so I am trying to use Shared Preferences to store information that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.