Jump to content

maplethorpej

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by maplethorpej

  1. I finally got it to work after I actually dug in and did some troubleshooting on my own. Sorry for the ignorance guys! By the way, that youTube video was perfect lol! I'll be more specific from now on
  2. I messed around with it a little more and found out that $query='SELECT * FROM TABLE WHERE '.$searchType.' like \''.$searchTerm'\''; echo $query; was breaking the script. When those lines were removed, something would show up again. Any thoughts?
  3. Below is the current, edited script. Unfortunately, nothing comes up... Not even the "Book-o-Rama Search Results" heading within the <h1> </h1> tags. What's going on?? I can't find the error <html> <head> <title>Search Results</title> </head> <body> <h1>Book-0-Rama Search Results</h1> <?php //create short variable names $searchType=$_POST['searchType']; $searchTerm=trim($_POST['searchTerm']); if(!$searchType || !$searchTerm){ echo 'You have not entered enough information to process the search'; exit; } if(!get_magic_quotes_gpc()){ $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } echo $searchType; echo $searchTerm; $db='books'; $host='localhost'; $username='root'; $password='root'; ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); if($mysql=mysql_connect($host,$username,$password)){ echo 'success connecting to mysql'; }else{ echo 'couldn\'t connect to mysql'; } if(mysql_select_db($db,$mysql)){ echo 'success choosing database.'; }else{ echo 'couldn\'t choose db'; } $query='SELECT * FROM TABLE WHERE '.$searchType.' like \''.$searchTerm'\''; echo $query; $result=mysql_query($query) or die(mysql_error()); mysql_close(); $array=array(); while($row=mysql_fetch_array($result)){ $array[]=$row; } print_r($array); foreach($array AS $rowarray){ for($i=0;$i<count($rowarray);$i++){ echo $rowarray[$i]; } } ?> </body> </html>
  4. <?php //create short variable names $searchType=$_POST['searchType']; $searchTerm=trim($_POST['searchTerm']); if(!$searchType || !$searchTerm){ echo 'You have not entered enough information to process the search'; exit; } if(!get_magic_quotes_gpc()){ $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } echo $searchType; echo $searchTerm; $table='books'; $host='localhost'; $username='root'; $password='root'; ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); $mysql=mysql_connect($host,$username,$password); mysql_select_db($table,$mysql) or die ($mysqlerror); $query='SELECT * FROM TABLE WHERE '.$searchType.' like \''.$searchTerm'\''; echo $query; $result=mysql_query($query) or die(mysql_error()); mysql_close(); $array=array(); while($row=mysql_fetch_array($result)){ $array[]=$row; } print_r($array); foreach($array AS $rowarray){ for($i=0;$i<count($rowarray);$i++){ echo $rowarray[$i]; } } $result->free(); $db->close(); ?> Alright, so this is how I set it up in my code. Now nothing comes up on the page when I go to it... :/ Any thoughts? P.S. Don't worry; I'm not gonna pester about everything but getting this initial connection figured out is pretty big!
  5. So, I'm going through a tutorial in my PHP book and we're using the code below. The page shows up and connects to the database (no error reported), but no data comes up. I'm wondering if I'm just missing something small or what? Let me know if you can help :'( <html> <head> <title>Search Results</title> </head> <body> <h1>Book-0-Rama Search Results</h1> <?php //create short variable names $searchType=$_POST['searchType']; $searchTerm=trim($_POST['searchTerm']); if(!$searchType || !$searchTerm){ echo 'You have not entered enough information to process the search'; exit; } if(!get_magic_quotes_gpc()){ $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } echo $searchType; echo $searchTerm; @ $db = new mysqli('localhost','root','root'); if(mysqli_connect_errno()){ echo 'Error: Could not connect to the database man...'; exit; } $query = "SELECT * FROM books WHERE ".$searchType." LIKE '%".searchTerm."%'"; $result = mysqli_query($query); $num_results = mysqli_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0;$i<$num_results;$i++){ $row = mysqli_fetch_assoc($result); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br/>Author: "; echo stripslashes($row['author']); echo "<br/>ISBN: "; echo stripslashes($row['isbn']); echo "<br/>Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); ?> </body> </html>
×
×
  • 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.