database selection

A

Anonymous

Guest
hai guys 10 4ur guide that u all gave. but nw i need ur help. wic was i have done a application form to be post and the process but the problem is there are many type of enquiry. wat i wan is wen a user select 1 type of enquriy i wan them to be insert in the specific database wic i already prepared according to the type. so hw can i do that. pls help me. here i attach wit the application and the process coding.
tanks in advance

<table width="388" border="0">

<tr>
<th width="70" scope="row"><div align="justify" class="style94">NAME:</div></th>
<td width="302">
<form action="proses.php" name="form1" method="post" >
<label>

<input name="name" type="text" size="40" maxlength="" />
</label>

</td>
<td height="35"></tr>
<tr>
<th height="37" scope="row"><div align="justify" class="style94">AGE:</div></th>
<td>
<label>
<input name="age" type="text" size="5" maxlength="2" />
</label> </td>
</tr>
<tr>
<th scope="row"><div align="justify" class="style94">RACE:</div></th>
<td>
<label>
<select name="race">
<option selected="selected">[CHOOSE YOURS</option>
<option>MALAY</option>
<option>CHINESE</option>
<option>INDIAN</option>
<option>OTHERS</option>
</select>
</label> </td>
</tr>
<tr>
<th height="33" scope="row"><div align="justify" class="style94">NRIC:</div></th>
<td>
<label>
<input name="nric" type="text" size="15" maxlength="15" />
</label> </td>
</tr>
<tr>
<th height="33" scope="row"><div align="justify" class="style94">ADDRESS:</div></th>
<td>
<label>
<input name="address" type="text" size="30" maxlength="60" />
</label> </td>
</tr>
<tr>
<th height="38" scope="row"><div align="justify" class="style94">ADDRESS2:</div></th>
<td>
<label>
<input name="address2" type="text" size="30" maxlength="60" />
</label> </td>
</tr>
<tr>
<th height="34" scope="row"><div align="justify" class="style94">POSTCODE:</div></th>
<td>
<label>
<input name="postcode" type="text" size="10" maxlength="5" />
</label> </td>
</tr>
<tr>
<th height="33" scope="row"><div align="justify" class="style94">CITY:</div></th>
<td>
<label>
<input name="city" type="text" size="30" maxlength="30" />
</label> </td>
</tr>
<tr>
<th height="37" scope="row"><div align="justify" class="style94">STATE:</div></th>
<td>
<label>
<select name="state" id="state">
<option selected="selected">[CHOOSE YOURS]</option>
<option> PERLIS</option>
<option> PERAK</option>
<option> SELANGOR</option>
<option> NEGERI SEMBILAN</option>
<option> MELAKA</option>
<option> JOHOR</option>
<option> PAHANG</option>
<option> TERENGGANU</option>
<option> KELANTAN</option>
<option> KEDAH</option>
<option> SARAWAK</option>
<option> SABAH</option>
<option> KUALA LUMPUR </option>
</select>
</label> </td>
</tr>
</table>
<div class="style32" id="Layer18">[xx-xxxxxxxx]</div>
<div id="Layer19"><span class="style32">[e.g:mail@org.com]</span></div>
<p> </p>
<p> </p>
<table width="389" height="152" border="0">
<tr>
<th width="71" height="36" scope="row"><div align="justify" class="style94">HOME:</div></th>
<td width="302">
<label>
<input name="home" type="text" size="15" maxlength="11" />
</label> </td>
</tr>
<tr>
<th height="38" scope="row"><div align="justify" class="style94">EMAIL:</div></th>
<td>
<label>
<input name="email" type="text" size="25" maxlength="30" />
</label> </td>
</tr>
<tr>
<th height="34" scope="row"><div align="justify" class="style94">MOBILE:</div></th>
<td>
<label>
<input name="mobile" type="text" size="15" maxlength="11" />
</label>

<div id="Layer20"><span class="style32">[xxx-xxxxxxx]</span></div>
<div id="Layer21"><span class="style32">[DD-MM-YYYY]</span></div></td>
</tr>
<tr>
<th scope="row"><div align="justify" class="style94">OFFICE:</div></th>
<td>
<label>
<input name="office" type="text" size="15" maxlength="11" />
</label> </td>
</tr>
</table>
<p><img src="image/14.jpg" width="152" height="38" /></p>
<div id="Layer22"><span class="style33">[</span><span class="style32">xx-xxxxxxxx]</span></div>
<table width="387" height="69" border="0">
<tr>
<th width="72" height="32" scope="row"><div align="justify" class="style94">DATE:</div></th>
<td width="299">
<label>
<input name="date" type="text" size="10" maxlength="10" />
</label> </td>
</tr>
<tr>
<th scope="row"><div align="justify" class="style94">TYPE:</div></th>
<td>
<label></label>
<label>
<select name="type">
<option selected="selected">[CHOOSE YOURS]</option>
<option value="BIRTH CERTIFICATE"> BIRTH CERTIFICATE </option>
<option value="IC"> IC </option>
<option value="LEGAL ADVISE"> LEGAL ADVISE </option>
<option value="COUNSELLING"> COUNSELLING </option>
<option value="EDUCATION"> EDUCATION </option>
<option value="COURSES"> COURSES </option>
<option value="JOB"> JOB </option>
<option value="SEMINARS"> SEMINARS </option>
<option value="EPF"> EPF </option>
<option value="SOCSO"> SOCSO </option>
<option value="OTHERS"> OTHERS </option>
</select>
</label> </td>
</tr>
</table>
<table width="387" border="0">
<tr>
<th width="377" height="37" scope="row"><div align="justify" class="style94">ENQUIRY:</div></th>
</tr>
<tr>
<th scope="row"><div align="justify">

<label>
<textarea name="enquiry" cols="60" rows="10"></textarea>
</label>

</div></th>
</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="SUBMIT">
<input type="reset" name="reset" value="RESET"></p>
<div id="Layer16"><img src="image/12.jpg" width="268" height="37" /></div> </td>
</tr>
</form>
</table>

and the process

<?
echo "<h1><font face='Arial, Helvetica, sans-serif' size='4'>YOUR DETAILS HAS BEEN SAVED SUCCESSFULLY.THANK YOU.</font></h1>";

?>
<?php
$name = $_POST['name'];
$age = $_POST['age'];
$race = $_POST['race'];
$nric = $_POST['nric'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$postcode = $_POST['postcode'];
$city = $_POST['city'];
$state = $_POST['state'];
$home = $_POST['home'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$office = $_POST['office'];
$date = $_POST['date'];
$type = $_POST['type'];
$enquiry = $_POST['enquiry'];

// Insert data into database
$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("eraccdb") or die(mysql_error());

$SQLcommand = "INSERT INTO complaint (name,age,race,nric,address,address2,postcode,city,state,home,email,mobile,office,date,type,enquiry)
VALUES ('".$name."', '".$age."', '".$race."', '".$nric."', '".$address."', '".$address2."', '".$postcode."', '".$city."', '".$state."', '".$home."', '".$email."', '".$mobile."', '".$office."', '".$date."', '".$type."', '".$enquiry."')";

$result = mysql_query($SQLcommand,$connect);
?>
</span>
<p class="style6"><?
echo "<a href=\"add.php\">BACK</a>";
?> </p></td>
 
I don't understand the code very much...but I gather that it's a form attempting to collect various user information where afterwards it will insert the information into a database.

In order to direct your $_POST data to a certain database, you must first examine your form. Decide what form object will define which database the $_POST data will be inserted into...or create an addition form object.

Once you have done that. You need to create a $_POST data validation script that should be written at the very top of your page before any other php resources are utilized. The validation should test the value of your database defining form object. If it is a certain value, write code that inserts it into a certain database. Very simply. Here is an example:


Code:
<?php

// If post data exists, validate it //
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
     if (!empty ($_POST['nation'])){
          if ($_POST['nation'] == 'united states')
               $database = 'us_database';
          }
          else if ($_POST['nation'] == 'mexico'){
               $database = 'mx_database';
          }
          mysql_query ("INSERT INTO $database SET whatever='bla bla bla'");
     }

}

<HTML>
<FORM action="<?=$_SERVER['PHP_SELF'] ?>" method="POST">
<SELECT name="nation">
     <OPTION value="united states">United States</OPTION>
     <OPTION value="mexico">Mexico</OPTION>
</SELECT>
</HTML
?>
 
Back
Top