Freelancer.com

Go Back   Warrior Forum - The #1 Internet Marketing Forum & Marketplace > Warrior Support Forums > Website Design
Register Blogs Social Groups Advertise with usHelp Desk

Reply
LinkBack Thread Tools
Unread 12th February 2010, 12:03 AM   #1
Warrior Member
 
Join Date: 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to make a registration form and connect it to Mysql in cpanel?

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...

worldpeace1988 is offline   Reply With Quote
Unread 12th February 2010, 12:22 AM   #2
Warrior Member
 
Join Date: 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: How to make a registration form and connect it to Mysql in cpanel?

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.

maeli25me is offline   Reply With Quote
Unread 12th February 2010, 01:10 PM   #3
HyperActive Warrior
War Room Member
 
osegoly's Avatar
 
Join Date: 2009
Location: Vancouver ,BC
Posts: 136
Thanks: 10
Thanked 13 Times in 12 Posts
Default Re: How to make a registration form and connect it to Mysql in cpanel?

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' rel="nofollow" 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>

Last edited on 12th February 2010 at 01:52 PM. Reason: missing php closing tag
osegoly is offline   Reply With Quote
Reply

  Warrior Forum - The #1 Internet Marketing Forum & Marketplace > Warrior Support Forums > Website Design

Bookmarks

Tags
connect, cpanel, form, make, mysql, registration

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:47 AM.