Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function connect_db($db_name) {
- $con = mysql_connect('localhost', 'db_user', 'db_pass');
- $seldb = mysql_select_db($db_name);
- if($con && $seldb) {
- return true;
- }
- }
- function insert_user($name,$company,$address,$city,$zip,$state,$phone,$web_site) {
- $insert_user_q = "INSERT into USERS (name,company,address,city,zip,state,phone,web_site) VALUES ('" . $name . "','" . $company . "','" . $address . "','" . $city . "','" . $zip . "','" . $state . "','" . $phone . "','" . $web_site . "')";
- $insert_user_m = mysql_query($insert_user_q);
- if ($insert_user_m) {
- return true;
- }
- else {
- return false;
- }
- }
- if (isset($_REQUEST['name'])) {
- $conn_to_db = connect_db("db_name");
- if ($conn_to_db) {
- $name = $_REQUEST['name'];
- $company = $_REQUEST['company'];
- $address = $_REQUEST['address'];
- $city = $_REQUEST['city'];
- $zip = $_REQUEST['zip'];
- $state = $_REQUEST['state'];
- $phone = $_REQUEST['phone'];
- $web_site = $_REQUEST['web_site'];
- $insert_user = insert_user($name,$company,$address,$city,$zip,$state,$phone,$web_site);
- if ($insert_user) {
- $inserted = "done!";
- }
- else {
- $inserted = "error";
- }
- }
- else {
- $inserted = "error";
- }
- }
- ?>
- <html>
- <head>
- <title>Insert new user</title>
- <script>
- function allow_form_submit(form_id) {
- if(confirm("Are you sure that all new user data is ok?")) {
- document.forms[form_id].submit();
- }
- else {
- alert('You canceled registration')
- }
- }
- </script>
- </head>
- <body>
- <h1><?php print $inserted; ?></h1>
- <form action="" method="post" id="new_user_form">
- <p>
- <label>Name:</label> <input type="text" name="name">
- </p>
- <p>
- <label>Company:</label> <input type="text" name="company">
- </p>
- <p>
- <label>Address:</label> <input type="text" name="address">
- </p>
- <p>
- <label>City:</label> <input type="text" name="city">
- </p>
- <p>
- <label>Zip:</label> <input type="text" name="zip">
- </p>
- <p>
- <label>State:</label> <input type="text" name="state">
- </p>
- <p>
- <label>Phone:</label> <input type="text" name="phone">
- </p>
- <p>
- <label>Website:</label> <input type="text" name="web_site">
- </p>
- </form>
- <input type="button" name="chk_form" value="SAVE" onclick="allow_form_submit('new_user_form');" />
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement