Thread: Tech Dumb SQL question
View Single Post
Old 09-06-2015, 02:47 AM  
AdultKing
Raise Your Weapon
 
AdultKing's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,605
Quote:
Originally Posted by lezinterracial View Post
looks way better. SQLI isn't deprecated, right?
Code:
//SQL Connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT url, title FROM fappageinfo WHERE title LIKE '%{$searchstring}%' OR title LIKE '{$searchstring}%' ORDER BY dateadded DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
      echo "<div>";
      echo "<a href=\"http://www.faprush.com/";
      echo $row['url'];
      echo "\"";
      echo " target=\"_blank\"";
      echo ">";
      echo $row['title'];
      echo "</a>";
      echo "</div>"; 
}
}

// Closing connection
$conn->close();
It isn't necessarily your use of mysql_query that is your problem in getting the right results from your SQL query , but it's good practice to set up the query first and make sure you escape all input and then submit the query.

Are you getting the output you want now ? I checked your website and it's still not returning matches for any word in the query.
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote