0

I have one question! How can i check form fields against the database and then display an error! Please help me for example go to mycsmi.org There is a form on the index.php page .... a user submits the info to the database but what if there is a duplicate .... how would i display to the user that the information is already provided!

Thanks and Have a Blessed Day!

2
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by mycsmi
0

Query the database with the information you are going to insert. If a record exists, do not do the insert and specify a 'duplicate message', otherwise continue and make an insert database call.

0

Query the database with the information you are going to insert. If a record exists, do not do the insert and specify a 'duplicate message', otherwise continue and make an insert database call.

Please explain that to me cause im a beginner with MySQL/PHP 5

0
<!-- The contact form starts from here-->
<?php $error       = ''; // error message 
$fname        = ''; // sender's name
$lname        = ''; // sender's name
$email       = ''; // sender's email address
$myspace     = ''; // myspace
$client      = ''; // IM Client
$screenname  = ''; // IM screen name
$service     = ''; // service
$phone       = ''; // address
$address        = ''; // address
$city        = ''; // address
$state        = ''; // address
$country        = ''; // address 
$zip       = ''; // zip code
$tos       = ''; // agree to terms of service

            if(isset($_POST['send']))
            {$fname     = $_POST['fname'];
            $lname     = $_POST['lname'];
            $email    = $_POST['email'];
            $myspace     = $_POST['myspace'];
            $client      = $_POST['client'];
            $screenname  = $_POST['screenname'];
            $service     = $_POST['service'];
            $phone     = $_POST['phone'];
            $address     = $_POST['address'];
            $city      = $_POST['city'];
            $state       = $_POST['state'];
            $country      = $_POST['country'];
            $zip      = $_POST['zip'];
            $tos       = $_POST['tos'];
            $ip       = $_POST['ip'];

                if(trim($fname) == '')
                {
                    $error = '<div class="errormsg">Please enter your first name!</div>';
                }
                if(trim($lname) == '')
                {
                    $error = '<div class="errormsg">Please enter your last name!</div>';
                }
                    else if(trim($email) == '')
                {
                    $error = '<div class="errormsg">Please enter your email address!</div>';
                }
                else if(!isEmail($email))
                {
                    $error = '<div class="errormsg">Invalid Email address, Try Again!</div>';
                }
                if(trim($myspace) == '')
                {
                    $error = '<div class="errormsg">Please enter you MySpace URL</div>';
                }
                if(trim($client) == '')
                {
                    $error = '<div class="errormsg">Please select an IM Client!</div>';
                }
                if(trim($screenname) == '')
                {
                    $error = '<div class="errormsg">Please enter your IM screen name!</div>';
                }
                if(trim($service) == '')
                {
                    $error = '<div class="errormsg">Please select a Service!</div>';
                }
                if(trim($address) == '')
                {
                    $error = '<div class="errormsg">Please enter your address!</div>';
                }
                if(trim($phone) == '')
                {
                    $error = '<div class="errormsg">Please enter your Phone Number (USA EX: 19996382764)</div>';
                }
                if(trim($zip) == '')
                {
                    $error = '<div class="errormsg">Please enter your zip code!</div>';
                }
                if(trim($tos) == '')
                {
                    $error = '<div class="errormsg">Please agree to MDT(CSMI) Terms of Use/Privacy Policy!</div>';
                }
                if($error == '')
                {
                    if(get_magic_quotes_gpc())
                    {
                        $message = stripslashes($message);
                    }

                    // the email will be sent here
                    // make sure to change this to be your e-mail
                    $to      = "MDT@mycsmi.org";

                    // the email subject
                    // '[Contact Form] :' will appear automatically in the subject.
                    // You can change it as you want

                    $subject = 'MDT(CHRISTSPACE) Service Request!';

                    // the mail message ( add any additional information if you want )
                    $msg     = "From : $fname $lname \r\nAccount Number: $id\r\nE-Mail : $email \r\nMySpace : $myspace \r\nIM 24/7 : $client | $screenname \r\nMinistry Service : $service \r\nPhone: $phone \r\nAddress : $address $city, $state $zip, $country \r\nAgree To MDT(CSMI) TOS : $tos";

                    mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
            ?>
                  <!-- Message sent! (change the text below as you wish)-->
<div style="text-align:center;"><table width="500" height="105" border="0">
<tr><td height="101"><h5 align="center" class="style38 style8 style8 style8 style55">Welcome to MDT International </h5>
    <h5 align="center" class="style1 style8 style8 style8">Thank you <?=$fname;?> <?=$lname;?> , we have recieved your <br>
      Service Request Application!<br>
      <br>WE WILL RESPOND WITHIN 15 HOURS! </h5></td>
</tr></table></div><p><!--End Message Sent-->
<?php
                }
            }

            if(!isset($_POST['send']) || $error != '')
            {
            ?></p>
<table width="516" border="0" align="center">
  <tr><td><div align="center" class="style49"><?=$error;?></div></td> </tr></table>
<form  method="post" name="contFrm" id="contFrm" onSubmit="return jcap();">
<table width="516" height="376" border="0" align="center">
  <tr>
<td width="145" height="36"><div class="float-left"><strong><span class="required">*</span> First/Last Name:</strong></div></td>
<td width="384"><input name="fname" type="text" class="box" id="fname" size="23" value="<?=$fname;?>" /> 
<input name="lname" type="text" class="box" id="lname" size="23" value="<?=$lname;?>" /></td></tr>
<tr><td width="145" height="36"><div class="float-left"><strong><span class="required">*</span> Email: </strong></div></td>
<td><input name="email" type="text" class="box" id="email" size="30" value="<?=$email;?>" /></td></tr>
<tr><td width="145" height="36"><div class="float-left"><strong><span class="required">*</span> MySpace URL: </strong></div></td>
<td>myspace.com/<input name="myspace" type="text" class="box" id="myspace" size="30" value="<?=$myspace;?>" /> 
<a href="extras/LifePoint/viewtopic.php?f=31&t=11">WANT 1 </a></td>
</tr>
<tr><td width="145" height="36"><div class="float-left"><strong><span class="required">* </span>IM 24/7 : </strong></div></td>
<td><select name="client" id="client">
                  <option value="AOL AIM" selected>AOL AIM</option>
                  <option value="Google Talk">Google Talk</option>
                  <option value="MSN Live">MSN Live</option>
                  <option value="MySpace IM">MySpace IM</option>
                  <option value="Yahoo! IM">Yahoo! IM</option>
                </select> 
                  | 
<input name="screenname" type="text" class="box" id="screenname" size="20" value="<?=$screenname;?>" /></td></tr>
<tr><td height="34"><div class="float-left"><strong><span class="required">*</span> Ministry Service: </strong></div></td>
                <td><select name="service" id="service">
                    <option value="MDT(CSMI)" selected>MDT(CHRISTSPACE)</option>
                    <option value="IM 24/7">IM 24/7</option>
                    <option value="NSR">NO SHAME</option>
                    <option value="FICA(GOTCHRIST)">FICAMAIL</option>
                    <option value="MINISTRYKONNECT">MINISTRYKONNECT</option>
                    <option value="T3 STREET">T3 STREET</option>
                    <option value="MYSPACE">MYSPACE</option>
                    <option value="VOLUNTEER">MDT(CSMI) VOLUNTEER</option>
                  </select> 
                  <a href="extras/LifePoint/">MORE DETAILS ... </a></td></tr>
<tr><td width="145" height="36"><div class="float-left"><strong><span class="required">*</span> Phone Number: </strong></div></td>
<td><input name="phone" type="text" class="box" id="phone" value="<?=$phone;?>" size="10" maxlength="10" /> 
<span class="style46"><strong><a href="services/MKI/">INTERNATIONAL USERS</a> </strong></span></td>
</tr>
<tr><td height="36" valign="top"><div class="float-left"><strong><span class="required">*</span> Address: </strong></div></td>
<td><input name="address" type="text" class="box" id="address" size="30" value="<?=$address;?>" /></td></tr>
<tr><td height="36" valign="top"><div class="float-left"><strong><span class="required">*</span> City, State: </strong></div></td>
<td><p><input name="city" type="text" class="box" id="city" size="20" value="<?=$city;?>" />, <span class="right">
                    <select class="other" name="state" id="state" onBlur="validate(this,'Required')">
                      <option>PR</option>
                      <option>GU</option>
                      <option>USVI</option>
                      <option>NMI</option>
                      <option>--</option>
                      <option>AL</option>
                      <option>AK</option>
                      <option>AR</option>
                      <option>AZ</option>
                      <option>CA</option>
                      <option>CO</option>
                      <option>CT</option>
                      <option>DC</option>
                      <option>DE</option>
                      <option>FL</option>
                      <option>GA</option>
                      <option>HI</option>
                      <option>ID</option>
                      <option>IL</option>
                      <option>IN</option>
                      <option>IA</option>
                      <option>KS</option>
                      <option>KY</option>
                      <option>LA</option>
                      <option>ME</option>
                      <option>MD</option>
                      <option>MA</option>
                      <option>MI</option>
                      <option>MN</option>
                      <option>MS</option>
                      <option>MO</option>
                      <option>MT</option>
                      <option>NE</option>
                      <option>NV</option>
                      <option>NH</option>
                      <option>NJ</option>
                      <option>NM</option>
                      <option>NY</option>
                      <option>NC</option>
                      <option>ND</option>
                      <option>OH</option>
                      <option>OK</option>
                      <option>OR</option>
                      <option>PA</option>
                      <option>RI</option>
                      <option>SC</option>
                      <option>SD</option>
                      <option>TN</option>
                      <option>TX</option>
                      <option>UT</option>
                      <option>VT</option>
                      <option>VA</option>
                      <option>WA</option>
                      <option>WV</option>
                      <option>WI</option>
                      <option>WY</option>
                    </select></span></td></tr>
<tr><td width="145" height="36" valign="top"><div class="float-left"><strong><span class="required">*</span> Country, ZIP Code: </strong></div></td><td><p><span class="right">
                    <select class="other" name="country" id="country" onBlur="validate(this,'Required')">
                      <option selected="selected">United States</option>
                      <option>Abkhazia</option>
                      <option>Afghanistan</option>
                      <option>United Kingdom Akrotiri and Dhekelia</option>
                      <option>Aland</option>
                      <option>Albania</option>
                      <option>Algeria</option>
                      <option>American Samoa</option>
                      <option>Andorra</option>
                      <option>Angola</option>
                      <option>Anguilla</option>
                      <option>Antigua and Barbuda</option>
                      <option>Argentina Argentina</option>
                      <option>Armenia</option>
                      <option>Aruba</option>
                      <option>United Kingdom Ascension Island</option>
                      <option>Australia</option>
                      <option>Austria</option>
                      <option>Azerbaijan</option>
                      <option>The Bahamas</option>
                      <option>Bahrain</option>
                      <option>Bangladesh</option>
                      <option>Barbados</option>
                      <option>Belarus</option>
                      <option>Belgium</option>
                      <option>Belize</option>
                      <option>Benin</option>
                      <option>Bermuda</option>
                      <option>Bhutan</option>
                      <option>Bolivia</option>
                      <option>Bosnia and Herzegovina</option>
                      <option>Botswana</option>
                      <option>Brazil</option>
                      <option>Brunei</option>
                      <option>Bulgaria</option>
                      <option>Burkina Faso</option>
                      <option>Burundi</option>
                      <option>Cambodia</option>
                      <option>Cameroon</option>
                      <option>Canada</option>
                      <option>Cape Verde</option>
                      <option>Cayman Islands</option>
                      <option>Central African Republic</option>
                      <option>Chad</option>
                      <option>Chile</option>
                      <option>People's Republic of China</option>
                      <option>Republic of China</option>
                      <option>Christmas Island</option>
                      <option>Cocos (Keeling) Islands</option>
                      <option>Colombia</option>
                      <option>Comoros</option>
                      <option>Congo</option>
                      <option>Cook Islands</option>
                      <option>Costa Rica</option>
                      <option>C�te d'Ivoire</option>
                      <option>Croatia</option>
                      <option>Cuba</option>
                      <option>Cyprus</option>
                      <option>Czech Republic</option>
                      <option>Denmark</option>
                      <option>Djibouti</option>
                      <option>Dominica</option>
                      <option>Dominican Republic</option>
                      <option>Ecuador</option>
                      <option>Egypt</option>
                      <option>El Salvador</option>
                      <option>Equatorial Guinea</option>
                      <option>Eritrea</option>
                      <option>Estonia</option>
                      <option>Ethiopia</option>
                      <option>Falkland Islands</option>
                      <option>Faroe Islands</option>
                      <option>Fiji</option>
                      <option>Finland</option>
                      <option>France</option>
                      <option>French Polynesia</option>
                      <option>Gabon</option>
                      <option>The Gambia</option>
                      <option>Georgia</option>
                      <option>Germany</option>
                      <option>Ghana</option>
                      <option>Gibraltar</option>
                      <option>Greece</option>
                      <option>Greenland</option>
                      <option>Grenada</option>
                      <option>Guam</option>
                      <option>Guatemala</option>
                      <option>Guernsey</option>
                      <option>Guinea</option>
                      <option>Guinea-Bissau</option>
                      <option>Guyana Guyana</option>
                      <option>Haiti Haiti</option>
                      <option>Honduras</option>
                      <option>Hong Kong</option>
                      <option>Hungary</option>
                      <option>Iceland</option>
                      <option>India</option>
                      <option>Indonesia</option>
                      <option>Iran</option>
                      <option>Iraq</option>
                      <option>Ireland</option>
                      <option>Israel</option>
                      <option>Italy</option>
                      <option>Jamaica</option>
                      <option>Japan</option>
                      <option>Jersey</option>
                      <option>Jordan</option>
                      <option>Kazakhstan</option>
                      <option>Kenya</option>
                      <option>Kiribati</option>
                      <option>North Korea</option>
                      <option>South Korea</option>
                      <option>Kosovo</option>
                      <option>Kuwait</option>
                      <option>Kyrgyzstan</option>
                      <option>Laos</option>
                      <option>Latvia</option>
                      <option>Lebanon</option>
                      <option>Lesotho</option>
                      <option>Liberia</option>
                      <option>Libya</option>
                      <option>Liechtenstein</option>
                      <option>Lithuania</option>
                      <option>Luxembourg</option>
                      <option>Macau</option>
                      <option>Macedonia</option>
                      <option>Madagascar</option>
                      <option>Malawi</option>
                      <option>Malaysia</option>
                      <option>Maldives</option>
                      <option>Mali</option>
                      <option>Malta</option>
                      <option>Marshall Islands</option>
                      <option>Mauritania</option>
                      <option>Mauritius</option>
                      <option>Mayotte</option>
                      <option>Mexico</option>
                      <option>Micronesia</option>
                      <option>Moldova</option>
                      <option>Monaco</option>
                      <option>Mongolia</option>
                      <option>Montenegro</option>
                      <option>Montserrat</option>
                      <option>Morocco</option>
                      <option>Mozambique</option>
                      <option>Myanmar</option>
                      <option>Nagorno-Karabakh</option>
                      <option>Namibia</option>
                      <option>Nauru</option>
                      <option>Nepal</option>
                      <option>Netherlands</option>
                      <option>Netherlands Antilles</option>
                      <option>New Caledonia</option>
                      <option>New Zealand</option>
                      <option>Nicaragua</option>
                      <option>Niger</option>
                      <option>Nigeria</option>
                      <option>Niue</option>
                      <option>Norfolk Island</option>
                      <option>Turkish Republic of Northern Cyprus</option>
                      <option>Northern Mariana</option>
                      <option>Norway</option>
                      <option>Pakistan</option>
                      <option>Palau</option>
                      <option>Palestine</option>
                      <option>Panama</option>
                      <option>Papua New Guinea</option>
                      <option>Paraguay</option>
                      <option>Peru</option>
                      <option>Philippines</option>
                      <option>Pitcairn Islands</option>
                      <option>Poland</option>
                      <option>Portugal</option>
                      <option>Transnistria Pridnestrovie</option>
                      <option>Puerto Rico</option>
                      <option>Qatar</option>
                      <option>Romania</option>
                      <option>Russia</option>
                      <option>Rwanda</option>
                      <option>Saint Barthelemy</option>
                      <option>Saint Helena</option>
                      <option>Saint Kitts and Nevis</option>
                      <option>Saint Lucia</option>
                      <option>Saint Martin</option>
                      <option>Saint Pierre and Miquelon</option>
                      <option>Saint Vincent and the Grenadines</option>
                      <option>Samoa</option>
                      <option>San Marino</option>
                      <option>S�o Tom� and Pr�ncipe</option>
                      <option>Saudi Arabia</option>
                      <option>Senegal</option>
                      <option>Serbia</option>
                      <option>Seychelles</option>
                      <option>Sierra Leone</option>
                      <option>Singapore</option>
                      <option>Slovakia</option>
                      <option>Slovenia</option>
                      <option>Solomon Islands</option>
                      <option>Somalia</option>
                      <option>Somaliland</option>
                      <option>South Africa</option>
                      <option>South Ossetia</option>
                      <option>Spain</option>
                      <option>Sri Lanka</option>
                      <option>Sudan</option>
                      <option>Suriname</option>
                      <option>Svalbard</option>
                      <option>Swaziland</option>
                      <option>Sweden</option>
                      <option>Switzerland</option>
                      <option>Syria</option>
                      <option>Tajikistan</option>
                      <option>Tanzania</option>
                      <option>Thailand</option>
                      <option>Timor-Leste</option>
                      <option>Togo</option>
                      <option>Tokelau</option>
                      <option>Tonga</option>
                      <option>Trinidad and Tobago</option>
                      <option>Tristan da Cunha</option>
                      <option>Tunisia</option>
                      <option>Turkey</option>
                      <option>Turkmenistan</option>
                      <option>Turks and Caicos Islands</option>
                      <option>Tuvalu</option>
                      <option>Uganda</option>
                      <option>Ukraine</option>
                      <option>United Arab Emirates</option>
                      <option>United Kingdom</option>
                      <option>Uruguay</option>
                      <option>Uzbekistan</option>
                      <option>Vanuatu</option>
                      <option>Vatican City</option>
                      <option>Venezuela</option>
                      <option>Vietnam</option>
                      <option>British Virgin Islands</option>
                      <option>US Virgin Islands</option>
                      <option>Wallis and Futuna</option>
                      <option>Western Sahara</option>
                      <option>Yemen</option>
                      <option>Zambia</option>
                      <option>Zimbabwe</option>
</select>
</span> 
      <input name="zip" type="text" class="box" id="zip" value="<?=$zip?>" size="5" maxlength="5" /></td></tr>
<tr>
  <td height="32"><div class="float-left"><strong><span class="required">*</span> Agree to TOS: </strong></div></td>
  <td><label>
    <input name="tos" type="checkbox" id="tos" value="Y">
    <span class="style46"><strong>YES, I ABIDE BY THE MDT(CSMI) TERMS </strong></span></label></td>
</tr></table>
<input name="send" type="submit" class="button" id="send" value="" onClick="return checkForm();" />
<?php 
} else {
$fname     = $_POST['fname'];
$lname     = $_POST['lname'];
$email    = $_POST['email'];
$myspace     = $_POST['myspace'];
$client      = $_POST['client'];
$screenname  = $_POST['screenname'];
$service     = $_POST['service'];
$phone     = $_POST['phone'];
$address     = $_POST['address'];
$city     = $_POST['city'];
$state     = $_POST['state'];
$country     = $_POST['country'];
$zip       = $_POST['zip'];
$tos       = $_POST['tos'];
$ip       = $_POST['ip'];

mysql_query("INSERT INTO `MDT(CSMI)`
(fname, lname, email, myspace, client, screenname, service, phone, address, city, state, country, zip, tos) VALUES ('$fname','$lname','$email','$myspace','$client','$screenname','$service','$phone','$address','$city','$state','$country','$zip','$tos' ) ");
}
?>
<?php


            function isEmail($email)
            {
                return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
                        ,$email));
            }
            ?></p>

Edited by mike_2000_17: Fixed formatting

0

In the code from 475-505 is the coding that is used to communicate with MySQL! I hope u can help me better answer my question.

From 35-81 is the PHP that contains the error code is that where i need to validate the form field AGAINST the database!

For example: when i update the form i will add a username field so how would i check to see if the username is taken with PHP/MySQL!

Also, I am in the need to create custom account number beginning with
MDT############ to work with PHP/MySQL. The way i need the account number is:

EXAMPLE: MDT122506154108

1. First 2 digits are the month - 12
2. Digits 3-4 are the day - 25
3. Digits 5-6 are the year - 06
4. Digits 7-8 are the hour - 15
5. Digits 9-10 are the minute - 41
6. Digits 11-12 are the second - 08

So, now its easier to understand my number system, now i need to implement it!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.