Jump to content

stuck again


Renlok

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.