php - Array within Form collecting multiple values with the same name possible? -


<'m Html>

Good Aftrn,

I tried'll start with the first goal, which I completed and Then the very basic sample of what I need to do.

target

Instead of collecting several variables and their names with the key, I decided to give in and handle an array using the structure After all the input of the same type and rules once I have the variable, I will validate against them and if 'OK' stores them in a MySQL table The table contains consumer information and will need to store several lines of information of the same type.

First Pass

I will separate the recognition part because I feel I need to understand the basics first

 . & Lt; Form action = "?" Method = "post" name = "form" & gt; Member1 First Name: & lt; Input type = "text" name = "member-first name []" /> gt; & Lt; Br / & gt; Member 1 Last Name: & lt; Input type = "text" name = "member listname [/]" & gt; & Lt; Br / & gt; Member1 Email: & lt; Input type = "text" name = "member e-mail []" /> gt; & Lt; Br / & gt; Member 2 First Name: & lt; Input type = "text" name = "member-first name []" /> gt; & Lt; Br / & gt; Member 2 Last Name: & lt; Input type = "text" name = "member listname []" /> gt; & Lt; Br / & gt; Member 2 Email: & lt; Input type = "text" name = "member email []" /> & Lt; Br / & gt; Member 3 First Name: & lt; Input type = "text" name = "member-first name []" /> gt; & Lt; Br / & gt; Member 3 Last Name: & lt; Input type = "text" name = "member listname []" /> gt; & Lt; Br / & gt; Member 3 email: & lt; Input type = "text" name = "member email []" /> gt; & Lt; Br / & gt; & Lt; Input type = "submit" name = "submit" value = "continue" /> & Lt; / Form & gt;  

I hope that will not overwrite each input the first name (has been a required field) of any data will generate a unique key for that particular entry and enter . Because I'm taking information in Page Two Page (checkout form), I change the post variable within a session, then finally I am storing it in a mysql database. I hope that:

  & lt ;? Php $ conn = mysql_connect ("localhost", "username", "password"); Mysql_select_db ("DBNAME", $ Conn); $ Sql ​​= "tablename VALUES ( '$ _SESSION [Member1FirstName] put in', '$ _SESSION [Member1LastName]', '$ _SESSION [Member1Email]', '$ _SESSION [Member2FirstName]', '$ _SESSION [Member2LastName]' , '$ _SESSION [subscriber 2 email]', '$ _SESSION [subscriber 1FirstName]', '$ _SESSION [subscriber 3LastName]', '$ _SESSION [subscriber 3 email]') "; $ Result = mysql_query ($ sql, $ conn) or die (mysql_error ()); Header ("location: complete.fp"); ? & Gt;  

Where members 1, member 2 and member 3 values ​​will appear in their row in the table. I know my code is wrong, but I am giving a first shot for the entire business purpose, I am trying to achieve it and learn how to code correctly.

I am very new to programming, so any 'child's advice' is highly appreciated.

  tablename values '$ _SESSION [Member1FirstName]', '$ _SESSION [Member1LastName]', '$ _SESSION [Member1Email]', ('$ _SESSION [Member2FirstName]', '$ _SESSION [Member2LastName]', '$ _SESSION [Member2Email]' ), ( '$ _SESSION [Member1FirstName]', '$ _SESSION [Member3LastName]', '$ _SESSION [Member3Email]') " 

will work on mysql view,.

However this is an answer that will take you much more trouble if you do not sanitize the input.

EDIT: Sanitizing attack, where wire database A passed directly constructs the attacker to change the database password or update references may be allowed to destroy the data

EDIT2 :. as php syntax, I think Here are the proper answers to which you can learn.


Comments