Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- task8.html -->
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Prac 3 Task 8</title>
- </head>
- <body>
- <h1>Customer Order Information</h1>
- <form id="userinfo" action="task8.php" method="post"><!-- Method switched to post, cleaner.-->
- <p>Search For A Customer</p>
- <p>
- Customer ID <input type="text" name="customer" />
- </p>
- <p>
- <input type="submit" value="submit"/>
- <input type="reset" value="reset"/>
- </p>
- </form>
- </body>
- </html>
- and my php:
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Tack 8.php</title>
- </head>
- <body>
- <?php
- if( isset($_POST['customer'])){
- // You should at least be using MySQLi Funtions instead of MySQL, as MySQL functions are deprecated.
- $conn = mysql_connect("localhost", "username", "password") or die( 'Cannot Connect to MySQL<br/>' . mysql_error());
- mysql_select_db("warehouse###", $conn) or die ('Database not found ' . mysql_error( $conn ) );
- $customer = mysql_real_escape_string( $_POST['customer'] ); // MySQL injection protection
- $query = "SELECT customerID FROM customer WHERE customerID='{$customer}' LIMIT 1";
- // No need to return all the data, if you are simply looking if it exists,
- // one column will do. If you later want to also display the info, change
- // the return column to appropriate column names or '*'
- $res = mysql_query($query) or die ("ERROR: sql = \"".$query."\"<br>" . mysql_error($conn) );
- if($res && mysql_num_rows($res) === 1){ // If the results are valid (although the die with the query makes this check already) and the number of returned rows is 1, then you have success.
- echo "Success";
- } else {
- echo "Fail";
- }
- }else{
- echo '<h2 style="color: #A00;">Error</h2>';
- echo '<p>This page requires form input from here.</p>';
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement