Jump to content

Archived

This topic is now archived and is closed to further replies.

Renlok

stuck again

Recommended Posts

[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 page

the code is in a html template if that makes any difference i dunno well thanks for any feedback.

Share this post


Link to post
Share on other sites
You have a typo here (notice the double $$ in result)

$num_results = $$result->num_rows;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Regards
Huggie

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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 omission
echo stripslashes($row['url']);
echo '">'; // <- added ; as the most likely omission
echo stripslashes($row['url']); // <- added ; as the most likely omission
echo '</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.

Share this post


Link to post
Share on other sites

×

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.