Renlok Posted September 29, 2006 Share Posted September 29, 2006 [code]<?php$searchtype=$_POST['searchtype'];$searchterm=$_POST['searchterm'];$searchterm= trim($searchterm);if (!$searchtype || !$searchterm){echo 'You have not entered search details. Please go back and try again.';exit;}if (!get_magic_quotes_gpc()){$searchtype = addslashes($searchtype);$searchterm = addslashes($searchterm);}@ $db = mysqli_connect('*', '*', '*', '*');if (mysqli_connect_errno()){echo 'Error: Could not connect to database. Please try again later.';exit;}$query = "select * from link where ".$searchtype." like '%".$searchterm."@'";$result = $db->query($query);$num_results = $$result->num_rows;echo '<p>Numbers of Links found '.$num_results.'</p>';for ($i=0; $i <$num_results; $i++){$row = $result->fetch_assoc();echo '<p><b>'.($i+1).'. Site Name: ';echo htmlspecialchars(stripslashes($row['siteName']));echo '</b><br>URL: ';echo stripslashes($row['url']);echo '<br>Discription: ';echo stripslashes($row['discription']);echo '<br>Keywords: ';echo stripslashes($row['keywords']);echo '<br>Date Added: ';echo stripslashes($row['dateAdded']);}mysqli_free_result($result);$db->close();?>[/code]Is there any errors in this page anyone can see because when i run it, it comes up with a blank pagethe code is in a html template if that makes any difference i dunno well thanks for any feedback. Quote Link to comment Share on other sites More sharing options...
yonta Posted September 29, 2006 Share Posted September 29, 2006 You have a typo here (notice the double $$ in result)$num_results = $$result->num_rows; Quote Link to comment Share on other sites More sharing options...
Renlok Posted September 29, 2006 Author Share Posted September 29, 2006 thanks for that but it now retrives nothing from the database it will just show 'Numbers of Links found 0' even if you enter an exact entery from the database.i dont know what im doing wrong. Quote Link to comment Share on other sites More sharing options...
yonta Posted September 29, 2006 Share Posted September 29, 2006 Well, maybe it's the @ - shouldn't it be % ?$query = "select * from link where ".$searchtype." like '%".$searchterm."@'";Or maybe try this$num_results = mysqli_num_rows($result);Other than that i don't see anything wrong. Check this page http://www.php.net/manual/en/function.mysqli-num-rows.php Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 29, 2006 Share Posted September 29, 2006 Why not give this a try? I removed the '@' sign from the query, but if it was meant to be there (if you're searcing for a string followed by an @ sign) then just add it in before the last % in the query.I've changed the query too, there's no need to escape normal variables when using double quotes " " as php translates them.[code]<?php$searchtype=$_POST['searchtype'];$searchterm=$_POST['searchterm'];$searchterm= trim($searchterm);if (!$searchtype || !$searchterm){echo 'You have not entered search details. Please go back and try again.';exit;}if (!get_magic_quotes_gpc()){$searchtype = addslashes($searchtype);$searchterm = addslashes($searchterm);}$db = mysqli_connect('*', '*', '*', '*');if (mysqli_connect_errno()){echo 'Error: Could not connect to database. Please try again later.';exit;}$query = "select * from link where "$searchtype" like '%$searchterm%'";$result = $db->query($query);$num_results = $result->num_rows;echo "<p>Numbers of Links found $num_results</p>";for ($i=0; $i <$num_results; $i++){$row = $result->fetch_assoc();echo '<p><b>'.($i+1).'. Site Name: ';echo htmlspecialchars(stripslashes($row['siteName']));echo '</b><br>URL: ';echo stripslashes($row['url']);echo '<br>Discription: ';echo stripslashes($row['discription']);echo '<br>Keywords: ';echo stripslashes($row['keywords']);echo '<br>Date Added: ';echo stripslashes($row['dateAdded']);}mysqli_free_result($result);$db->close();?>[/code]If it doesn't work then post the errors back here.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Renlok Posted September 29, 2006 Author Share Posted September 29, 2006 thanks for the help it was just the error with the @ not being a %now i have one last question. In the part of the code where it echos the data:[code]{$row = $result->fetch_assoc();echo '<p><b>'.($i+1).'. Site Name: ';echo htmlspecialchars(stripslashes($row['siteName']));echo '</b><br>URL: ';echo stripslashes($row['url']);echo '<br>Discription: ';echo stripslashes($row['discription']);echo '<br>Keywords: ';echo stripslashes($row['keywords']);echo '<br>Date Added: ';echo stripslashes($row['dateAdded']);}[/code]how could i make it so echo stripslashes($row['url']); will show up as a link i have tried with[code]echo '</b><br>URL: ';echo '<a href="'echo stripslashes($row['url']);echo '">'echo stripslashes($row['url'])echo '</a>'[/code]but it will show as an error Quote Link to comment Share on other sites More sharing options...
Renlok Posted September 30, 2006 Author Share Posted September 30, 2006 anyone? ??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 30, 2006 Share Posted September 30, 2006 [quote author=Renlok link=topic=109904.msg443881#msg443881 date=1159555356]how could i make it so echo stripslashes($row['url']); will show up as a link i have tried with[code]echo '</b><br>URL: ';echo '<a href="'; // <- added ; as the most likely omissionecho stripslashes($row['url']);echo '">'; // <- added ; as the most likely omissionecho stripslashes($row['url']); // <- added ; as the most likely omissionecho '</a>'; // <- added ; as the most likely omission[/code]but it will show as an error[/quote]The error that appears is always useful, often helpful, and allows anyone here to understand what might be the problem. Always post the precise error message(s) you get, please.As to a solution, my guess is that you've omitted the final [b];[/b] on several lines. Quote Link to comment 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.