Validating form in php

01-Oct-2017 22:16

I think what I have to do now is insert some data from the html form into that table. php $con=mysqli_connect("localhost","userdb","",""); // Check connection if (mysqli_connect_errno()) $sql = "INSERT INTO `userdb`.`users` (`name`, `password`) VALUES (\'eric\', \'123456\');"; ? First you'll need to fix the mark-up a bit.*the exammple code doesn't show it, but the form tag should have action and method attributes.

To Submit user input, (unless you use javascript, but that can wait), you need to put the inputs - and a submit button - inside of form tags. in your form file (unless the form and database code are in the same file, then maybe)When the form is submitted the input values will be sent as $_POST variables to where "action" points to and PHP can use them.

I have created one in phpmyadmin / xampp called mydb.

I can successfully connect to this database using In this database I created a table called 'users, and in this table I created two, "rows" I think they are called? I'm not really sure what the primary key for this is, because I'm confused by the interface, but I think/hope it's the name, because that was the first one I created. , I have created a webform with simple username / password fields And from here I don't really know where to go. Here is my whole html document, called Hi Granv11le, welcome to the forums For starters, a database table is like, well, a table eg.[table][tr][td][/td][td]columns[/td][/tr][tr][td][/td][td]name[/td][td]pw[/td][/tr][tr][td]row1[/td][td]Fred[/td][td]a1b[/td][/tr][tr][td]row2[/td][td]Mike[/td][td]ghj[/td][/tr][tr][td]row3[/td][td]Joe[/td][td]o9i[/td][/tr][/table]If you look at the attachment you posted you'll see it says "add column after" - ALTERing your table structure like shown is probably not what you want at this point.

I have been told to validate a form with a username and password using php and a mysql database.

So to do this I need to database to validate against.

It’s possible the user accidentally typed in a wrong character or maybe it was from a bad copy and paste.

By sanitizing the data, you take the responsibility of hunting for the mistake off of the user.

All fields are required, except those marked optional.But, we need to validate whether the email entered by user is valid or not.We alter our validation code for email as follows : why sanitize and not just validate?This is a basic form handling approach that should be followed while writing procedural php code.

But, this is not the recommended approach for large scale web apps.There is a tutorial here on Sitepoint that shows some validation, but it's not putting anything into a databse. i.e.[table][tr][td][/td][td]columns[/td][/tr][tr][td][/td][td]name[/td][td]new col[/td][td]pw[/td][/tr][tr][td]row1[/td][td]Fred[/td][td][/td][td]a1b[/td][/tr][tr][td]row2[/td][td]Mike[/td][td][/td][td]ghj[/td][/tr][tr][td]row3[/td][td]Joe[/td][td][/td][td]o9i[/td][/tr][/table] Primary Keys must be unique values, so unless you know every row will have different values, you may want to add an "id" column, usually AUTO INCREMENT eg.[table][tr][td][/td][td][/td][td]columns[/td][/tr][tr][td][/td][td]id[/td][td]name[/td][td]pw[/td][/tr][tr][td]row1[/td][td]1[/td][td]Fred[/td][td]a1b[/td][/tr][tr][td]row2[/td][td]2[/td][td]Mike[/td][td]ghj[/td][/tr][tr][td]row3[/td][td]3[/td][td]Joe[/td][td]o9i[/td][/tr][/table] Hi, thank you for your reply.