Jump to content

Php help:inserting data via website form


Recommended Posts

I am trying to create a membership form that inserts data into mysql. I am using phpmyadmin, mysql 5.0 through M6.net

I belive I have the connection set up right, but I am a newbie and self-taught.

So, here is the form and script please help...

 

This is in an html page but saved as driver_form.php

 

<form name="driver_form" method="post" action="process_driver.php"  >

 

<table border="0" cellpadding="3" cellspacing="3" summary="">

<tr>

<td>First name</td>

<td><input type="text" name="first_name" size="30"/></td>

<td>Last name</td>

<td><input type="text" name="last_name" size="30"/></td>

</tr>

<tr>

<td>Create Username<br />

</td>

<td><input type="text" name="username" size="30"></td>

<td>Create Password<br />

<font size="4">*5-12 characters long</font></td>

<td><input type="password" maxlength="12" name="password" size="15"/></td>

</tr>

<tr>

<td>Home Address<br />

<font size="3">street name<br />

city,state,zip</font></td>

<td><textarea rows="2" cols="30" name="home_address" >

</textarea></td>

<td>Work Address<br />

<font size="3">street name<br />

city,state,zip</font></td>

<td><textarea rows="2" cols="30" name="work_address" >

</textarea></td>

</tr>

<tr>

<td>Work Shift</td>

<td><select name="shift" >

<option>Day</option>

<option>Evening</option>

<option>Night</option>

</select></td>

</tr>

<tr>

<td>Time you go to work: </td>

<td><input type="text" name="start_time" size="10" /> <font size="3">include am or pm</font></td>

<td>Time you go home:</td>

<td><input type="text" name="end_time" size="10" /><font size="3"> include am or pm</font></td>

</tr>

<tr>

<td>Gas money expected</td>

<td><input type="text" size="10" name="gas_money"/> per week</td></tr>

<tr>

<td>Contact me by:</td>

<td>Email<br />

<input type="text" name="email" value="optional"/><br />

Phone<br />

<input type="text" name="phone" value="optional"/></td>

</tr>

</table><br />

<center><button type="submit" name="Submit" value="Send">Send</button> <input type="reset"/></center>

</form>

 

Ok, now here is my script process_driver.php

 

<?php

 

include 'data_info.php'//this is host,username,password info

include 'openCTdb.php'//this is connection:

looks like this:

 

<?php

 

// connect and select the database

$conn = mysql_connect("$hostname", "$user", "$password") or die(mysql_error());

$dbname='ctmembers07';

$db = mysql_select_db($dbName, $conn) or die(mysql_error());

?>

 

 

// Get values from form

 

$first_name=$_POST['first_name'];

$last_name=$_POST['last_name'];

$username=$_POST['username'];

$password=$_POST['password'];

$home_address=$_POST['home_address'];

$work_address=$POST['work_address'];

$shift=$_POST['shift'];

$start_time=$_POST['start_time'];

$end_time=$_POST['end_time'];

$email=$_POST['email'];

$phone=$_POST['phone'];

$gas_money=$POST['gas_money'];

 

// Insert data into mysql

 

$sql = mysql_query("INSERT INTO members

('first_name', 'last_name', 'username','password','home_address','work_address','shift','start_time','end_time','email','phone','gas_money','membership_type')

VALUES('$first_name', '$last_name','$username','MD5($password)','$home_address','$work_address','$shift','$start_time','$end_time','$email','$phone','$gas_money','$01')");

$result=mysql_query($sql);

 

 

 

// if successfully insert data into database, displays message "Successful".

if($result){

echo "Successful";

echo "<BR>";

echo "<a href='../index.htm'>Back to Home page</a>";

}

 

else {

echo "ERROR";

}

 

// close connection

include 'closeCTdb.php';

?>

 

When I try to test it on my site, it loads quickly to a blank page.

 

Please help anyone. :'(

Link to comment
https://forums.phpfreaks.com/topic/50158-php-helpinserting-data-via-website-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.