poorrichard Posted February 19, 2009 Share Posted February 19, 2009 Basically im trying to create code that will: -Take user entry from an HTML form -Compare it to my database and return the true results -Display an error message if wrong. I have about 5-7 diff fields in my table and here is some starter code (all it does is return whatever info i entered. it doesn't do the query/comparison in my db. Also i need to know what code to put in search.php as it is the file the form posts to. <?php $users = array(); if (!empty($_POST['submit'])) { $username="****; $password="****"; $database="contacts"; $users['first'] = $_POST['first']; $users['last'] = $_POST['last']; $users['dept'] = $_POST['dept']; $users['book'] = $_POST['book']; $users['conf'] = $_POST['conf']; $users['journal'] = $_POST['journal']; $users['email'] = $_POST['email']; $users['web'] = $_POST['web']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = mysql_query("SELECT * FROM contacts WHERE first LIKE '%first')"); $users = mysql_fetch_assoc($query); echo "<b>PLEASE ONLY HIT SUBMIT ONCE ON THIS FORM</b>"; } echo ' <html> <body> <form action="search.php" method="post"> First Name: <input type="text" name="first" value="' . $users['first'] . '"> Last Name: <input type="text" name="last" value="' . $users['last'] . '"><br> Department: <input type="text" name="dept"><br> E-mail-Add: <input type="text" name="email" value="' . $users['email'] . '"> <align="right"> Website: <input type="text" name="web"></align><br> <p>Book(s):<BR> <TEXTAREA NAME="book" COLS=40 ROWS=6></TEXTAREA><br> Conference(s):<BR> <TEXTAREA NAME="conf" COLS=40 ROWS=6></TEXTAREA><br> Journal(s):<BR> <TEXTAREA NAME="journal" COLS=40 ROWS=6></TEXTAREA><br> <input type="submit" name="submit" value="submit"> </form> </body>'; Quote Link to comment https://forums.phpfreaks.com/topic/145946-noob-question-about-database-script/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.