Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <FORM>
- ID: <input type="text" name="id"><br />
- NM: <input type="text" name="nm"><br />
- Company: <input type="text" name="company"><br />
- Address: <input type="text" name="address"><br />
- City: <input type="text" name="city"><br />
- Zip: <input type="text" name="zip"><br />
- State: <input type="text" name="state"><br />
- Phone: <input type="text" name="phone"><br />
- Website: <input type="text" name="web_site"><br />
- </FORM>
- <?php
- $agent_nm = $_POST['nm']; // gather all the variables
- $company = $_POST['company'];
- $address = $_POST['address'];
- $city = $_POST['city'];
- $zip = $_POST['zip'];
- $state = $_POST['state'];
- $phone = $_POST['phone'];
- $web_site = $_POST['web_site'];
- $batch_id = $_POST['batch_id']; // added batch id
- //connect
- $conn = new mysqli('local', 'admin', 'pass', 'DB');
- if(mysqli_connect_errno()) {
- exit('Connect failed: '. mysqli_connect_error());
- }
- //generate the query (doesn't add id because id is autoincremented)
- $query = "INSERT INTO t_agent VALUES (NULL, " . $agent_nm . ", " . $company . ", " . $address . ", " . $city . ", " . $zip . ", " . $state . ", " . $phone . ", " . $web_site . ", " . $batch_id . ")";
- //insert and close.
- mysqli_query($conn, $query);
- mysqli_close($conn);
- <form method="post" action="process.php" id="myForm" name="myForm" >
- <label for="ID">ID</label>: <input type="text" name="ID" /><br />
- <label for="nm">NM:</label> <input type="text" name="nm"><br />
- <label for="company">Company:</label> <input type="text" name="company"><br />
- <label for="address">Address:</label> <input type="text" name="address"><br />
- <label for="city">City</label>: <input type="text" name="city"><br />
- <label for="zip">Zip</label>: <input type="text" name="zip"><br />
- <label for="state">State</label>: <input type="text" name="state"><br />
- <label for="phone">Phone</label>: <input type="text" name="phone"><br />
- <label for="web_site">Website</label>: <input type="text" name="web_site"><br />
- <input type="submit" name="submit" />// this is your submit button
- </form>
- //get your inputs from the form
- $ID = $_POST['ID'];
- //do the same for each of the text inputs
- <?php
- $host= "xxx";
- $username="xxx";
- $password="xxx";
- $database="xxx ";
- // Gets data from URL parameters
- $name = $_POST['nm'];
- //Repeate for all other parameters
- // Opens a connection to a MySQL server
- try {
- // DBH means "DB Handle"
- // MySQL with PDO_MYSQL
- $DBH = new PDO("mysql:host=$host;dbname=$database", $username, $password);
- }
- catch(PDOException $e) {
- echo $e->getMessage();
- }
- // STH means "Statement Handle"
- $STH = $DBH->prepare("INSERT INTO mytable ( id, nm,company,address,city,zip,state,phone,web_site ) values ( NULL,:nm,:company,:address,:city,:zip,:state,:phone,:web_site)");
- $STH->bindParam(':name', $name);
- //Repeate for all other parameters
- $STH->execute();
- //# close the connection
- $DBH = null;
- ?>
Add Comment
Please, Sign In to add comment