...

View Full Version : Coverting PHP form to be submitted to MYSQL database



david4u
05-31-2007, 05:18 PM
Goodday,

I have written a php form that can submit data into a file but could not get it working to submit unto MYSQL database.

Can anyone help me on what to do to change the form now to be able to submit unto mysql database.


[ ] <?php
$rand=rand("4567","7890");
$random=md5($rand);
$captcha= strtoupper(substr($random,0,4));
$hidden= "<input name='captcha' type='hidden' id='userlevel' value='$captcha'>";
echo <<<html
<head>
<title>USER REGISTRATION</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>User Registration</title>
<style>
TEXTAREA
{
FONT-SIZE: 10px;
FONT-FAMILY: Verdana;
}
SELECT
{
FONT-SIZE: 10px;
FONT-FAMILY: Verdana;
}
INPUT
{
FONT-SIZE: 10px;
FONT-FAMILY: Verdana;
}
.error
{
FONT-FAMILY: verdana;
font-size: 10px;
color: #FF0000;
}
.blktext, .blktext:link, .blktext:visited
{
FONT-FAMILY: verdana;
font-size: 10px;
color: #000000;
}
.blktext:hover
{
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #ff9900;
}
.logininput
{
border: 1px solid #ff9900;
WIDTH: 70px;
FONT-SIZE: 10px;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
}
</style>
</head>

<body>
<script>
function CheckAgree()
{
var x = document.forms["regform"].agree.checked;
if (x) return true;
alert("You must agree to Terms and Conditions to continue registration");
return false;
}
</script>

<form action="adduser.php" method="POST" name="regform" onsubmit="return CheckAgree();">
<div align="center">
<center>
<table>
<tr><td align="center" height="11" width="448">&nbsp;
<div align="left">
<table border="0" width="438">
<tbody><tr><td colspan="2" width="430">
<p align="center"><b><font size="3">User Management </font></b>&nbsp;</td></tr>
<tr>
<td class="blktext" align="right" width="121"><b>Username</b></td>
<td class="blktext" width="303">
<input value="" name="username">
<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Password</b></td>
<td class="blktext" width="303">
<input value="" name="password" type="password" size="20">
<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Confirm Password</b></td>
<td class="blktext" width="303">
<input value="" name="retype" type="password" size="20">
<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Email address</b></td>
<td class="blktext" width="303">
<input value="" name="email">
<span class="error">* <b>(Valid email)</b></span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Name</b></td>
<td class="blktext" width="303">
<input value="" name="name" size="20">
<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Occupation</b></td>
<td class="blktext" width="303">
<font face="arial"><select size="1" name="category">
<option value="business">Business man</option>
<option value="student">Student</option>
<option value="job">On job</option>
<option value="working">Working</option>
<option value="working">NYSE (Still Serving)</option>
<option value="working">Researcher</option>
<option value="working">IT Professional</option>
<option value="working">Unemployed</option>

<option selected="selected" value="select">Select</option>
</select>
</font>
<span class="error">*</span>
</td>
</tr>



<!-- This is a change -->



<tr>
<td class="blktext" align="right" width="121"><b>Qualification</b></td>
<td class="blktext" width="303">
<font face="arial"><select size="1" name="category">
<option value="School">Secondary School Certificate</option>
<option value="OND">OND</option>
<option value="HND">HND</option>
<option value="BSC">BSC Degree</option>
<option value="working">Postgraduate Degree</option>
<option value="working">PhD Researcher</option>
<option value="working">Post Doctorate</option>
<option value="working">Other</option>

<option selected="selected" value="select">Select</option>
</select>
</font>
<span class="error">*</span>
</td>
</tr>

<!-- This is a change -->











<tr>
<td class="blktext" align="right" width="121"><b>Gender</b></td>
<td class="blktext" width="303">
<input name="gender" value="male" class="blktext" type="radio" checked><b>Male
</b> &nbsp;&nbsp;&nbsp;&nbsp; <input name="gender" value="female" class="blktext" type="radio">
<b>Female </b> &nbsp;<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Country</b></td>
<td class="blktext" width="303">
<font face="arial"><input name="country" id="useremail8" value="Pakistan" 50="" size="20" type="text">
</font>
<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121">
<b>Phone</b></td>
<td class="blktext" width="303">
<input value="" name="phone" size="20">
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121">
<b>Address/City</b></td>
<td class="blktext" width="350">
<input value="" name="city" size="30">
</td>
</tr>
<tr>
<td class="blktext" align="right" width="150"><b>Date of birth</b></td>
<td class="blktext" width="350">
<table cellpadding="0" cellspacing="0">
<tbody><tr>
<td> <table cellpadding="0" cellspacing="0">
<tbody><tr>
<td>
<select name="bmonth" size="1">
<option value="0">-
</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12 </option></select>
</td>
<td class="blktext" rowspan="2">&nbsp;/&nbsp;</td>
<td>
<select name="bdate" size="1">
<option value="0">-
</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31 </option></select>
</td>
<td class="blktext" rowspan="2">&nbsp;/&nbsp;</td>
<td>
<select name="byear" size="1">
<option value="0">-
</option><option value="1920">1920</option><option value="1921">1921</option><option value="1922">1922</option><option value="1923">1923</option><option value="1924">1924</option><option value="1925">1925</option><option value="1926">1926</option><option value="1927">1927</option><option value="1928">1928</option><option value="1929">1929</option><option value="1930">1930</option><option value="1931">1931</option><option value="1932">1932</option><option value="1933">1933</option><option value="1934">1934</option><option value="1935">1935</option><option value="1936">1936</option><option value="1937">1937</option><option value="1938">1938</option><option value="1939">1939</option><option value="1940">1940</option><option value="1941">1941</option><option value="1942">1942</option><option value="1943">1943</option><option value="1944">1944</option><option value="1945">1945</option><option value="1946">1946</option><option value="1947">1947</option><option value="1948">1948</option><option value="1949">1949</option><option value="1950">1950</option><option value="1951">1951</option><option value="1952">1952</option><option value="1953">1953</option><option value="1954">1954</option><option value="1955">1955</option><option value="1956">1956</option><option value="1957">1957</option><option value="1958">1958</option><option value="1959">1959</option><option value="1960">1960</option><option value="1961">1961</option><option value="1962">1962</option><option value="1963">1963</option><option value="1964">1964</option><option value="1965">1965</option><option value="1966">1966</option><option value="1967">1967</option><option value="1968">1968</option><option value="1969">1969</option><option value="1970">1970</option><option value="1971">1971</option><option value="1972">1972</option><option value="1973">1973</option><option value="1974">1974</option><option value="1975">1975</option><option value="1976">1976</option><option value="1977">1977</option><option value="1978">1978</option><option value="1979">1979</option><option value="1980">1980</option><option value="1981">1981</option><option value="1982">1982</option><option value="1983">1983</option><option value="1984">1984</option><option value="1985">1985</option><option value="1986">1986</option><option value="1987">1987</option><option value="1988">1988</option><option value="1989">1989</option><option value="1990">1990</option><option value="1991">1991</option><option value="1992">1992</option><option value="1993">1993</option><option value="1994">1994</option><option value="1995">1995</option><option value="1996">1996</option><option value="1997">1997</option><option value="1998">1998</option><option value="1999">1999</option><option value="2000">2000</option><option value="2001">2001</option><option value="2002">2002</option><option value="2003">2003</option><option value="2004">2004 </option></select>
</td>
</tr>
<tr>
<td class="blktext" align="center">Month</td>
<td class="blktext" align="center">Day</td>
<td class="blktext" align="center">Year</td>
</tr>
</tbody></table>
</td>
<td></td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="121"><b>Secret
Question</b></td>
<td class="blktext" width="303">
<select name="question" size="1"><option value="not">Select your password
security question</option><option value="last 4 digits of your social security number?">Last
4 digits of your social security number?</option><option value="what is your mother's maiden name?"> What
is your mother's maiden name?</option><option value="what city were you born in?"> What
city were you born in?</option><option value="what is the first school you attended?"> What
is the first school you attended?</option><option value="ur love's middle name?"> Ur
love's middle name?</option></select><span class="error">*</span>
<span id="question"><br><font face="Arial" size="1">This question will be used to verify your identity if you need to request your account name or password in the future.</font></span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="150"><b>Answer</b></td>
<td class="blktext" width="350">
<input value="" name="sanswer" size="20">
<span class="error">*</span>
</td>
</tr>
<tr>
<td class="blktext" align="right" width="150">&nbsp;</td>
<td class="blktext" width="350">
<input name="agree" type="checkbox">I agree with the <a href="terms.php" target="_blank"><b>Terms and Conditions</b></a>
</td>
</tr>
<tr><td colspan="2" height="10" width="430">$hidden</td></tr>
<tr>
<td colspan="2" align="center" width="430">
<table>
<tbody><tr><td colspan="2" class="blktext" align="center"><b>Please enter this number in the box below:</b></td></tr>
<tr>
<td class="blktext" valign="middle">
<p align="center">&nbsp;&nbsp;<b><font size="2"><span style="background-color: #FFFF00">$captcha</span></font></b></p>
</td>
<td class="blktext" valign="top"><input name="scheck" size="20"></td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td colspan="2" class="blktext" align="center" width="430"><input src="images/register.gif" border="0" type="image"></td>
</tr>
</tbody></table>
</div>
</form>
</table>
</center>
</div>
</body>
html;
?> [/ ]




Can anyone help?


Thanks.

LaRoza
05-31-2007, 05:41 PM
Try using the code tags so it is easier to read on the forum,



<?php
echo "see what I mean";
?>


I do not see any functions for mysql in use, are you asking "How do I use MySQL and PHP?".

To use MySQL with PHP, you need to first create the database and table(s).

For the PHP part, you need to:
1. Connect to MySQL && Select a database
2. Perform a query
3. Possibly Get the results.
4. Close the database.

LaRoza
05-31-2007, 05:51 PM
<form action="adduser.php" method="POST" name="regform" onsubmit="return CheckAgree();">

adduser.php should use the following functions:

mysqli_connect()
mysqli_query()
mysqli_close()

This is the minimum.

I was looking at your code, and you have mixed JavaScript, CSS, and XHTML in on document.

For cleaner and valid code, try using external JavaScript and CSS. Also, there seems to be no need to "echo" the html document, especially the way you are doing it.

Your document is not valid html, it doesn't have the <html> tag as it should.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum