Jump to content

poorrichard

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

poorrichard's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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>';
  2. Parse error: syntax error, unexpected $end
  3. Getting more errors of the same DB Failure to connect variety <?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']; } else { mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database");
  4. i'm getting some DB connect issues with the code. I've entered my username and pass here, and changed nothing else $users['username'] = "*****"; $users['password'] = "*****"; $users['database'] = "contacts";
  5. are all the variables supposed to be $users for your code miles?
  6. Could you assist me on how to do that?
  7. I'm working on a project that has two parts. 1.) A php form that uploads user entries into my database. This part is done. 2.) The same form, used to search the database and return the found results to the user. What ive been able to do so far, is have the form re-print my data that i entered, but it does not matter if it is on my db or not. Here is the code, any help would be appreciated. (Note, im an absolute beginner and my job requires me to do things that i do not know how to do. That's why i'm here ) <?php if (!empty($_POST['submit'])) { $username=""; $password=""; $database="contacts"; $first=$_POST['first']; $last=$_POST['last']; $dept=$_POST['dept']; $book=$_POST['book']; $conf=$_POST['conf']; $journal=$_POST['journal']; $email=$_POST['email']; $web=$_POST['web']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT first, last, dept, email, web, book, conf, journal FROM contacts WHERE first LIKE '%$first%' and last LIKE '%$last%' and dept LIKE '%$dept%' and email LIKE '%$email%' and web LIKE '%$web%' and book LIKE '%$book%' and conf LIKE '%$conf%' and journal LIKE '%$journal%')"; mysql_query($query); mysql_close(); echo "<b>PLEASE ONLY HIT SUBMIT ONCE ON THIS FORM</b>"; } ?> <html> <body> <form action="search.php" method="post"> First Name: <input type="text" name="first"> Last Name: <input type="text" name="last"><br> Department: <input type="text" name="dept"><br> E-mail-Add: <input type="text" name="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>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.