1 Replies - 1026 Views - Last Post: 08 July 2011 - 04:15 PM Rate Topic: -----

#1 wirelesstrendz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 12-May 11

trying to add data validation to a form

Posted 08 July 2011 - 04:13 PM

hello, i am trying to add some data validation to this form, but i am not having any luck with inserting code from other forums with data validation information. any help would be greatly appreciated. thank you in advance.


here is the form page test.html

<html>

<head>

 <title>cellphone purchase form</title>

<h1> WIRELESS TRENDZ PHONE PURCHASE SYSTEM</h1>

</head>



<body>

<div id="content">

<form action="insert.php" method="post" name="form" enctype="multipart/form-data">
First name: <input type="text" name="First_Name" </br>
</br>
Last name: <input type="text" name="Last_Name" </br>
</br>
DL Number: <input type="text" name="License_Num" </br>
</br>
Address: <input type="text" name="Address" </br>
</br>
City: <input type="text" name="City" </br>
</br>
State: <input type="text" name="usaState" </br>
</br>
Zip Code: <input type="text" name="Zip_code" </br>
</br>
Carrier:
<select name="Carrier">
<option value="AT&T">AT&T</option>
<option value="SPRINT">SPRINT</option>
<option value="T-MOBILE">T-MOBILE</option>
<option value="VERIZON">VERIZON</option>
<option value="OTHER">OTHER</option></select><br />
</br>
Phone make: <input type="text" name="Make" </br>
</br>
Phone model: <input type="text" name="Model" </br>
</br>
IMEI/HEX/DEC: <input type="text" name="IMEI_Hex_ESN" </br>
</br>
Phone condition:
<select name="phoneCondition">
<option value="Good">Good</option>
<option value="Parts">Parts</option>
<option value="Water">Water</option>
<option value="Other">Other</option></select><br />
</br>
Phone price: <input type="text" name="Paid" </br>
</br>
Date purchased: <input type="text" name="Date"</br>
use YYYY-MM-DD format for Date purchased
<br>

<input type="hidden" name="submitted" value="1">

</br>
<input type="submit"</br>
</br>

 </div>

<br>
<FORM><INPUT TYPE="button" VALUE="Back" onclick="history.go(-1);return true;">
<INPUT TYPE="BUTTON" VALUE="Main Menu" onclick="window.location.href='open.html'">
</FORM>

</body>
</html>




and here is the php page insert.php


<html>
<body>
<?php
$con = mysql_connect('localhost','root','');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("trendzphones")or die(mysql_error());


$result = mysql_query("INSERT INTO customer_table (License_Num, First_Name, Last_Name, Address, City, usaState, Zip_code)
VALUES
('$_POST[License_Num]','$_POST[First_Name]','$_POST[Last_Name]','$_POST[Address]','$_POST[City]','$_POST[usaState]','$_POST[Zip_code]')")
or die(mysql_error());



$result1 = mysql_query("INSERT INTO phone_table (Carrier, Make, Model, IMEI_Hex_ESN, phoneCondition, Date, Paid, Customer_ID)
VALUES
('$_POST[Carrier]','$_POST[Make]','$_POST[Model]','$_POST[IMEI_Hex_ESN]','$_POST[phoneCondition]','$_POST[Date]','$_POST[Paid]',LAST_INSERT_ID())")
or die(mysql_error());






echo "1 phone record added ";

echo " 1 customer record added";

mysql_close($con)
?>


<FORM>
<INPUT TYPE="BUTTON" VALUE="Main Menu" onclick="window.location.href='open.html'">

</FORM>


</body>
</html>





once again thank you for any help in the right direction

Is This A Good Question/Topic? 0
  • +

Replies To: trying to add data validation to a form

#2 maniacalsounds   User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • Posts: 474
  • Joined: 27-June 10

Re: trying to add data validation to a form

Posted 08 July 2011 - 04:15 PM

Well, you have NO validation on the code you showed. You only have inserting into the database.

Article on validation:
http://buildinternet...ing-php-part-1/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1