Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- NEW.PHP
- Allows user to create a new entry in the database
- */
- // creates the new record form
- // since this form is used multiple times in this file, I have made it a function that is easily reusable
- function renderForm($user, $pass, $hwid, $code, $banned, $ip, $date, $error)
- {
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <title>New Record</title>
- </head>
- <body>
- <?php
- // if there are any errors, display them
- if ($error != '')
- {
- echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
- }
- ?>
- <form action="" method="post">
- <div>
- <strong>username: *</strong> <input type="text" name="username" value="<?php echo $user; ?>" /><br/>
- <strong>password: *</strong> <input type="text" name="password" value="<?php echo $pass; ?>" /><br/>
- <strong>hwid: *</strong> <input type="text" name="hwid" value="<?php echo $hwid; ?>" /><br/>
- <strong>code: *</strong> <input type="text" name="code" value="<?php echo $code; ?>" /><br/>
- <strong>banned: *</strong> <input type="text" name="banned" value="<?php echo $banned; ?>" /><br/>
- <strong>ip: *</strong> <input type="text" name="ip" value="<?php echo $ip; ?>" /><br/>
- <strong>date: *</strong> <input type="text" name="date" value="<?php echo $date; ?>" /><br/>
- <p>* required</p>
- <input type="submit" name="submit" value="Submit">
- </div>
- </form>
- </body>
- </html>
- <?php
- }
- // connect to the database
- include('connect-db.php');
- // check if the form has been submitted. If it has, start to process the form and save it to the database
- if (isset($_POST['submit']))
- {
- // get form data, making sure it is valid
- $username = mysql_real_escape_string(htmlspecialchars($_POST['username']));
- $password = mysql_real_escape_string(htmlspecialchars($_POST['password']));
- // check to make sure both fields are entered
- if ($username == '' || $password == '')
- {
- // generate error message
- $error = 'ERROR: Please fill in all required fields!';
- // if either field is blank, display the form again
- renderForm($user, $pass, $hwid, $code, $banned, $ip, $date, $error);
- }
- else
- {
- // save the data to the database
- mysql_query("INSERT Account SET username='$user', password='$pass', hwid='$hwid', code='$code', banned='$banned', ip='$date', date='$date'")
- or die(mysql_error());
- // once saved, redirect back to the view page
- header("Location: view.php");
- }
- }
- else
- // if the form hasn't been submitted, display the form
- {
- renderForm('','','');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement