-1

I'm trying to create a form using php in which the user will input some data, and I'll be able to store them in my database.

so far my code is this

<h1>Join Head Hunters <span class="colored-text">NOW</span>!</h1>
        <form class="sform" method="get">
            <input type="text" name="username" value="" placeholder="Username" method="get" maxlength="30">
            <input type="password" name="password" value="" placeholder="Password" method="get" maxlength="30">
            <input type="text" name="first_name" value="" placeholder="First name" method="get" maxlength="30">
            <input type="text" name="last_name" value="" placeholder="Last name" method="get" maxlength="30">
            <input type="text" name="address" value="" placeholder="Address" method="get" maxlength="80">
            <input type="text" name="phone" value="" placeholder="Phone" method="get" maxlength="60">
            <input type="text" name="mail" value="" placeholder="email" method="get" maxlength="40">
            <input type="text" name="prof" value="" placeholder="Profession" method="get">
            <input type="text" name="account" value="" placeholder="Bank Account" method="get">

            <select multiple id="studies" class="specialColor" method="get">
                <option value="highschool degree">Highschool Degree</option>
                <option value="bachelors degree">Bachelors Degree</option>
                <option value="MSc">MSc</option>
                <option value="PhD">PhD</option>
                <option value="MD">MD</option>
                <option value="EdD">EdD</option>
                <option value="JD">JD</option>
            </select>


            <select multiple="multiple" id="skillz" name="skillz[]" method="get">
                <option value="administering programs">Administering Programs</option>
                <option value="advising people">Advising people</option>
                <option value="analyzing data">Analyzing data</option>
                <option value="assembling apparatus">Assembling apparatus</option>
                <option value="auditing financial reports">Auditing financial reports</option>
                <option value="budgeting expenses">Budgeting expenses</option>
                <option value="calculating numerical data">Calculating numerical data</option>
                <option value="finding information">Finding information</option>
                <option value="handling complaints">Handling complaints</option>
                <option value="imagining new solutions">Imagining new solutions</option>
                <option value="interpreting languages">Interpreting languages</option>
                <option value="speaking to the public">Speaking to the public</option>
                <option value="writing letters/papers/proposals">Writing letters/papers/proposals</option>
                <option value="listening to others">Listening to others</option>
                <option value="deciding uses of money">Deciding uses of money</option>
                <option value="determining a problem">Determining a problem</option>
                <option value="setting work/committee goals">Setting work/committee goals</option>
                <option value="maintaining emotional control under stress">Maintaining emotional control under stress</option>
            </select>

            <select multiple="multiple" id="languages" name="languages[]" method="get">
                <option value="english">English</option>
                <option value="greek">Greek</option>
                <option value="german">German</option>
                <option value="japanese">Japanese</option>
                <option value="spanish">Spanish</option>
                <option value="italian">Italian</option>
                <option value="french">French</option>
                <option value="wookie">Wookie</option>
                <option value="klingon">Klingon</option>
                <option value="other">Other</option>
            </select>

            <input type="submit" class="button" name='create_account' value="Create Account"></input>

        </form>

and the PHP for that:

<?php
                $sservername = "localhost";
                $susername = "root";
                $spassword = "";
                $sdbname = "projectDB";
                mysql_connect($sservername, $susername, $spassword) or die("Cannot connect to server.");
                mysql_select_db($sdbname) or die("Cannot select DataBase.");



                if (isset($_POST["create_account"])) {
                    echo "<br><br><br><br><br>Button clicked";

                    //header("Location: signupsuccess.php");
                    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
                    //some error checking, now...
                    if (!preg_match($email_exp, $mail)) {
                        $error_message .= "<font color='red'>The Email address you entered does not appear to be valid.<br/></font>";
                        header("Refresh:0");
                        echo $error_message;
                    }
                }
            ?>

Problem is that no matter how many times I try and press the button it never echos the "Button clicked" message and I can't figure out why!

Keep in mind, this is my first attempt on php and mysql. Any help? I've googled too much and I can't figure out my mistake.

Jack
  • 722
  • 3
  • 8
  • 24
  • **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Jan 15 '16 at 10:49
  • 1
    Your regular expression will reject many perfectly valid email addresses (such as those with a `+` in the user component or with a TLD that has more than 4 letters in it). – Quentin Jan 15 '16 at 10:50
  • @Quentin I'm trying to get the submit button to work first, then I'll try and edit the pattern – Jack Jan 15 '16 at 10:52

1 Answers1

1
<form class="sform" method="get">
if (isset($_POST["create_account"]))

A GET form will put the data in the query string, not the request body. $_POST won't be populated. Set the method to post.


Additionally, at present you are always going to output the Refresh 0 header, so it is quite likely that even if you did output the HTML then the page would refresh immediately and you wouldn't see it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335