Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Empty data inserted into database from web form

$
0
0

I was working on a web page while learning CSHTML and using the ASP.NET Razor syntax to process form data and submit it into a MySQL database that I created. I created the database outside of the WebMatrix software but connected the database using the connection creation mechanism in the software interface which worked fine.

My specific problem is that my code is executing properly and actually doing everything and finishes with the following web page that is supposed to be opened when the data is inserted into the table is complete actually opening and I am getting no errors. What I am not getting is viewable data in the database. The code I am using to insert the data is inserting empty strings into the database, or it is data that I cannot see in the table columns. I am posting the page code and looking for an answer to why I am not seeing data in the database tables.

Any help would be appreciated.

@{Validation.RequireField("fname","Your first name is required");Validation.RequireField("lname","Your last name is required");Validation.RequireField("address","Please enter your street address");Validation.RequireField("city","Please enter the city name");Validation.RequireField("state","Please enter your state");Validation.RequireField("zip","Please enter a zip code");Validation.RequireField("homephone","Your home phone number is required");Validation.RequireField("mobile","Please enter your mobile phone number");Validation.RequireField("license","Please enter your drivers license number");Validation.RequireField("email","Your e-mail address is required");Validation.RequireField("password","Please enter a password");varFirstName=" ";varLastName=" ";varAddress=" ";varCity=" ";varState=" ";varZipCode=" ";varHomePhone=" ";varMobilePhone=" ";varLicense=" ";varEmail=" ";varPassword=" ";if(IsPost&&Validation.IsValid()){FirstName=Request["fname"];LastName=Request["lname"];Address=Request["address"];City=Request["city"];State=Request["state"];ZipCode=Request["zip"];HomePhone=Request["homephone"];MobilePhone=Request["mobile"];License=Request["license"];Email=Request["email"];Password=Request["password"];vardb=Database.Open("drivers");varinsertProfile="INSERT INTO driver_reg (firstname, lastname, address, city, state, zipcode, 
homephone, mobilephone, license, email, password) VALUES(FirstName, LastName, Address, City, State,
ZipCode, HomePhone, MobilePhone, License, Email, Password)"
;db.Execute(insertProfile,FirstName,LastName,Address,City,State,ZipCode,HomePhone,MobilePhone,
Email,Password);vardbLogin=Database.Open("drivers");varinsertLogin="INSERT INTO driver_login (firstname, lastname, email, password)
VALUES(FirstName, LastName, Email, Password)"
;db.Execute(insertLogin,FirstName,LastName,Email,Password);Response.Redirect("~/RegSuccess");}}<!DOCTYPEhtml><htmllang="en"><head><metacharset="utf-8"/><title>Driver Profile Entry</title><styletype="text/css"><!--*{margin:0;padding:0;}body*{font: 13pxhelvetica, arial, freesans, clean, sans-serif;line-height: 1.5em;}a{color: #281EE3;text-decoration: none;}a:hover{color: #61ef3e;text-decoration: none;}.profile_form.h1{background-color:#3366CC;border-style: solid;border-width: 2px;border-color: #000000;}h2{font-size:130%;font-weight:bold;color:#2f424e;}.profile_form{margin:5emauto;width:70em;}.profile_form.formbody{padding:2em;background-color:#97BAE7;border-style:solid;border-width:2px;border-color:#000000;}.profile_form.table{background-color: #000000;text-align: center;}.profile_form.tr{background-color: #9F9F9F;}.profile_form.td{width: 225px;text-align: center;padding: .5em;}.profile_formh1{color:#fff;font-size:16px;font-weight:bold;border:1pxsolid#000000;padding:10px20px;}.profile_formh1a{font-size:70%;color:#E9F1F4;}.profile_formformlabel{font-size:110%;color:#2f424e;display:inline-block;cursor:text;font-weight:bold;}.profile_formformlabela{font-size:90%;}.profile_formforminput[type=submit]{display:inline-block;height:35px;width:75px;position:relative;top:3px;font-family:helvetica, arial, freesans, clean, sans-serif;font-weight:bold;font-size:12px;color:#fff;background-color:#3366CC;border:1pxsolid#333333;cursor:pointer;padding:010px;}.profile_formforminput[type=submit]:hover{color:#fff;}input[type=text], input[type=password]{font:95%Verdana, Geneva, sans-serif;width:25em;padding:5px;border:1pxsolid#000000;margin:.2em01em0;font-size:105%;}input[type=text]:focus, input[type=password]:focus{border-color:#0770a0;}.validation-summary-errors{border:2pxdashedred; color:red; background-color:#FFFFFF; font-weight:bold; margin:10px;padding-left: 2em; } --></style></head><body><divclass="profile_form"><imgsrc="huffman_logo.jpg"height="75"width="200"><tableclass="table"><trclass="tr"><tdclass="td"><ahref="driver_home.cshtml">Driver Home</a><br/></td><tdclass="td"><ahref="driver_list.cshtml">Driver Listing</a><br/></td><tdclass="td"><ahref="driver_reg.cshtml">New Driver Registration</a><br/></td><tdclass="td"><ahref="login.cshtml">Driver Login</a><br/></td></tr></table><h1class="h1">Driver Profile Creation Form:</h1><divclass="formbody">@Html.ValidationSummary()<formmethod="post"><labelfor="fname">First Name:<br/><inputclass="text"id="fname"name="fname"type="text"value="@Request.Form["fname"]"/></label><labelfor="lname">Last Name:<br/><inputclass="text"id="lname"name="lname"type="text"value="@Request.Form["lname"]"/></label><labelfor="address">Street Address:<br/><inputclass="text"id="address"name="address"type="text"
value
="@Request.Form["address"]"/></label><labelfor="city">City:<br/><inputclass="text"id="city"name="city"type="text"value="@Request.Form["city"]"/></label><labelfor="state">State:<br/><inputclass="text"id="state"name="state"type="text"value="@Request.Form["state"]"/></label><labelfor="zip">Zip Code:<br/><inputclass="text"id="zip"name="zip"type="text"value="@Request.Form["zip"]"/></label><labelfor="homephone">Home Phone Number:<br/><inputclass="text"id="homephone"name="homephone"type="text"
value
="@Request.Form["homephone"]"/></label><labelfor="mobile">Mobile Phone Number:<br/><inputclass="text"id="mobile"name="mobile"type="text"value="@Request.Form["mobile"]"/></label><labelfor="license">Driver License Number:<br/><inputclass="text"id="license"name="license"type="text"value="@Request.Form["license"]"/></label><h2>Create User Login:</h2><labelfor="email">E-mail Address:<br/><inputclass="text"id="email"name="email"type="text"value="@Request.Form["email"]"/></label><labelfor="password">Password:<br/><inputclass="text"id="password"name="password"type="password"
value="@Request.Form["password"]"/></label><labelclass="submit_btn"><inputname="commit"type="submit"value="Submit"/></label></form></div></div></body></html>

Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>