How to make a registration form and connect it to Mysql in cpanel?

by 2 comments
Hi,

I am not a web designer apart from few basic stuffs which i know, I have been asked to make a small site for a event in school.The site has few pages of info which i have done in Html...they told me that i should have one page in the site for registration form to collect the details of the student participating in the event.

I have Cpanel hosting with hostmonster, can anyone tell me how to make a registration form and connect it to my MSQL in cpanel....I see lots of code available in google but they are all going above my head...can anyone tell me easily how to do this with my cpanel hosting...
#web design #connect #cpanel #form #make #mysql #registration
  • Profile picture of the author maeli25me
    Thank you worldpeace888, actually I am having problem with this too. I am working on mysql using xamp, and in hostmonster you will see mysql. but the thing is, I am having trouble with my php code for my password that is not connecting to my database, but I think I uploaded it correctly.
    • Profile picture of the author osegoly
      Hey,

      I hope the following code helps. The first few lines define your database information. Change those variables to correspond to your own database info. For example, if you were to create "dbuser" as your username you would need to change the DB_USER definition to:

      DEFINE ('DB_USER', 'dbuser');

      Leave DB_HOST as localhost (unless your website is running on a different server than your mysql database).

      Also, you'll need to create a new table in your MySQL database. This table will be used to store the data you have collected using your new form.
      The SQL line down the bottom (INSERT INTO table....) will need to be amended slightly. You'll need to change "table" to your actual table name and change the fields to correspond to the fields you have in your table. This is a pretty basic SQL command. If you're not sure about it I suggest that you look up "SQL Insert Command" on google. To create a new table and add the right fields to it you will likely have to use phpMyAdmin. This should be available from within your cpanel page. Create your database and username first prior to opening phpMyAdmin. Once you go in there you should see your new database, which will most likely be empty. Click on your database, scroll to the very bottom, and you should see two text boxes: one for your Table Name and one for the # of fields.

      Enjoy!
      Omer







      <?php

      DEFINE ('DB_USER', 'THE DB USERNAME YOU CREATED IN CPANEL');
      DEFINE ('DB_PASSWORD', 'THE DB PASSWORD YOU CREATED IN CPANEL');
      DEFINE ('DB_HOST', 'localhost');
      DEFINE ('DB_NAME','THE DB NAME YOU CREATED IN CPANEL');

      $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die('wrong password' . mysql_error());
      mysql_select_db(DB_NAME) OR die('<p>Could not select the database:</p>' . mysql_error());




      if(isset($_POST['submit']))
      {

      //ERRROR VALIDATOR

      $errors = ""; //Initalize errors var


      if(empty($_POST['fname']))
      {
      $errors='y';
      $fname_error="true";
      }
      else
      {
      $fname=$_POST['fname'];
      }

      if(empty($_POST['lname']))
      {
      $errors='y';
      $lname_error="true";
      }
      else
      {
      $lname=$_POST['lname'];
      }

      if(empty($_POST['phone']))
      {
      $errors='y';
      $phone_error="true";
      }
      else
      {
      $phone=$_POST['phone'];
      $phone = str_replace (" ", "", $phone);
      }

      if(empty($_POST['email']))
      {
      $errors='y';
      $email_error="true";
      }
      else
      {
      $email=$_POST['email'];
      }

      if(empty($_POST['address']))
      {
      $errors='y';
      $address_error="true";
      }
      else
      {
      $address=$_POST['address'];
      }


      if(empty($_POST['postalcode']))
      {
      $errors='y';
      $postalcode_error="true";
      }
      else
      {
      $postalcode=$_POST['postalcode'];
      $postalcode = str_replace (" ", "", $postalcode);
      }


      if(empty($_POST['city']))
      {
      $errors='y';
      $city_error="true";
      }
      else
      {
      $city=$_POST['city'];
      }


      if(empty($_POST['terms']))
      {
      $errors='y';
      $terms_error="true";
      }
      else
      {
      $terms=$_POST['terms'];
      }


      $age=$_POST['age'];
      $address2=$_POST['address2'];




      if(trim($errors)=="")
      {

      $query = "INSERT INTO table(id,fname,lname,age,phone,email,address,addre ss2,postalcode)VALUES('$id','$fname','$lname','$ag e',
      '$phone','$email','$address','$address2','$postalc ode')";
      $result = mysql_query($query);

      }

      }


      ?>


      <form action='' method='post'>

      <fieldset style='width:550px;text-align:left;border-width:2px;'><legend class='h3'>Dungeon Bootcamp Registration - Personal Information</legend>
      <br>
      <span style='color:#820010;font-size:12px;font-weight:normal;'>* required field</span><br><br>


      <table width='350' border='0' style='padding-left:20px;'>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='fname'>First Name</label></td>
      <td><input type='text' name='fname' id='fname' value='".$fname."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='lname'>Last Name</label></td>
      <td><input type='text' name='lname' id='lname' value='".$lname."'></td>
      </tr>

      <tr>
      <td></td>
      <td><label for='age'>Age</label></td>
      <td><input type='text' name='age' id='age' value='".$age."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='phone'>Contact Phone #</label></td>
      <td><input type='text' name='phone' id='phone' value='".$phone."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='email'>E-mail Address</label></td>
      <td><input type='text' name='email' id='email' value='".$email."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='address'>Address</label></td>
      <td><input type='text' name='address' id='address' value='".$address."'></td>
      </tr>

      <tr>
      <td></td>
      <td><label for='address2'>Address 2</label></td>
      <td><input type='text' name='address2' id='address2' value='".$address2."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='postalcode'>Postal Code</label></td>
      <td><input type='text' name='postalcode' id='postcode' value='".$postalcode."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='city'>City</label></td>
      <td><input type='text' name='city' id='city' value='".$city."'></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='province'>Province</label></td>
      <td><input type='text' name='province' id='state' value='Ontario' disabled></td>
      </tr>

      <tr>
      <td><span style='color:#820010;'>*</span></td>
      <td><label for='country'>Country</label></td>
      <td><input type='text' name='country' id='country' value='Canada' disabled></td>
      </tr>
      </table>
      <br>
      <input type='checkbox' name='terms' id='terms' value='terms'"; if(isset($terms)){echo "CHECKED";} echo"><label for='terms'>I have read and understood the <a href='policies.php' target='_blank'>terms and conditions</label></a>

      <table style='padding-left:20px;'>


      <input type='submit' name='submit' value='Next' style='background-color:#464443;font-size:11px;color:white;font-weight:bold;border:solid 1px white;padding:2px 5px 2px 5px;'>


      </fieldset>

      </form>

Next Topics on Trending Feed