kaf Posted March 31, 2011 Share Posted March 31, 2011 hey everyone I'm really new to php so basically this text keeps coming up here are my two codes 'connect.php' <?php DEFINE ('DB_USER', root); DEFINE ('DB_PSWD', password); DEFINE ('DB_HOST', localhost); DEFINE ('DB_NAME', movies); $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); ?> and search1.php <html> <head> <title> Movies Search </title> <style type="text/css"> table{ background-color: #FCF; } th { width: 150px; text-align: left; } </style> </head> <body> <h1> Movie Search </h1> <form method="post" action="search1.php"> <input type="hidden" name="submitted" value="true" /> <label> Search Category: <select name="category"> <option value="title">Title</option> <option value="genre">Genre</option> <option value="director">Director</option> </select> </label> <label> Search Criteria: <input type="text" name="criteria" /></label> <input type="submit" /> </form> } <?php if (isset($_POST['submitted'])) { //connect to the database <?php include 'connect.php'?> $category = $_POST['category']; $criteria = $_POST['criteria']; $query = "SELECT * FROM 'movies' WHERE '"$category"' = '"$criteria"'"; $result = mysqli_query($query, $dbcon) or die ('error getting data'); echo "<table>"; echo "<tr> <th>Movie_ID</th> <th>Title</th> <th>Genre</th> <th>Director</th> </tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ echo "<tr><td>"; echo $row['movie_id']; echo "<td><td>"; echo "<tr><td>"; echo $row['title']; echo "<td><td>"; echo "<tr><td>"; echo $row['genre']; echo "<td><td>"; echo "<tr><td>"; echo $row['director']; echo "<td><tr>"; } echo "</table>"; } // end of main if statement ?> </body> </html> I got my codes from this guy on youtube http://www.youtube.com/user/rrphillips#p/search/5/IYmS5HRo6JI seems to be working for everyone else... Would really appreciate your help Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/ Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 How are you accessing the file with the browser, not by using File --> Open, right? Are you sure php is installed and running on the server? Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195050 Share on other sites More sharing options...
kaf Posted March 31, 2011 Author Share Posted March 31, 2011 I'm using xampp so phpmyadmin and localhost/ to try out the code... Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195051 Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 Then for some reason, it seems the php interpreter isn't parsing the file. Create a new script, and in it put the code that follows. Save it in the web document root (htdocs, perhaps?) and load it in your browser. See if it gives you output or not. <?php phpinfo(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195055 Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 Oh, wait. I spotted the issue, I believe. Your <?php opening and closing tags are out of whack. See the comment in the code below . . . <?php if (isset($_POST['submitted'])) { //connect to the database <?php include 'connect.php'?> // Remove the <?php and ?> tags here. $category = $_POST['category']; $criteria = $_POST['criteria']; $query = "SELECT * FROM 'movies' WHERE '"$category"' = '"$criteria"'"; Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195056 Share on other sites More sharing options...
kaf Posted March 31, 2011 Author Share Posted March 31, 2011 thanks that worked got rid of most the code and the table which isn't meant to show up till after the retrieval of the data thanks this is what it looks like now i think i have to change these echo tags somewhere hmmm Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195063 Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 Post your revised code between . . . tags, please. Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195067 Share on other sites More sharing options...
kaf Posted March 31, 2011 Author Share Posted March 31, 2011 <html> <head> <title> Movies Search </title> <style type="text/css"> table{ background-color: #FCF; } th { width: 150px; text-align: left; } </style> </head> <body> <h1> Movie Search </h1> <form method="post" action="search1.php"> <input type="hidden" name="submitted" value="true" /> <label> Search Category: <select name="category"> <option value="title">Title</option> <option value="genre">Genre</option> <option value="director">Director</option> </select> </label> <label> Search Criteria: <input type="text" name="criteria" /></label> <input type="submit" /> </form> } <?php if (isset($_POST['submitted'])) { //connect to the database include 'connect.php' $category = $_POST['category']; $criteria = $_POST['criteria']; $query = "SELECT * FROM 'movies' WHERE '"$category"' LIKE '"$criteria"'"; $result = mysqli_query($query, $dbcon) or die ('error getting data');} echo "<table>"; echo "<tr> <th>movie_id</th> <th>title</th> <th>genre</th> <th>director</th> </tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ echo "<tr><td>"; echo $row['movie_id']; echo "<td><td>"; echo "<tr><td>"; echo $row['title']; echo "<td><td>"; echo "<tr><td>"; echo $row['genre']; echo "<td><td>"; echo "<tr><td>"; echo $row['director']; echo "<td><tr>"; } echo "</table>"; } ?> // end of main if statement </body> </html> thanks Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195071 Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 I don't think that code can be producing that output. The output you pasted shows 'movie_ID Title Genre Director', but in the code none of those are capitalized at the point I believe they're being echoed. Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195081 Share on other sites More sharing options...
Pikachu2000 Posted March 31, 2011 Share Posted March 31, 2011 Of course, once again I spoke too soon. The <label> for the <select> form field has its closing </label> tag counterpart misplaced. It needs to be where the label's text ends, not after the </select> closing tag. The entire <select> field is being interpreted as label text. Quote Link to comment https://forums.phpfreaks.com/topic/232307-issues-with-my-php-data-retrieving-script/#findComment-1195083 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.