mysqli_real_escape_string expects 2 parameters [duplicate]

This question already has an answer here:

Good day programmers I have a problem with my code, some closure would be very satisfying. I get the errors:

Undefined index: id in C:wampwwwforumtopic2.php on line 12

and

mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:wampwwwforumtopic2.php on line 12

This problem persists in all the files I use the mysqli_real_escape_string function in.

If anyone knows how to explain what I need to resolve this that would be awesome.

<?php
//create_cat.php
include 'connect.php';
include 'header.php';

$sql = "SELECT
        topic_id,
        topic_subject
    FROM
        topics
    WHERE
        topics.topic_id = '" . mysqli_real_escape_string($_GET['id']) ."'";

 $result = mysqli_query($link, $sql);

if(!$result)
{
echo 'The topic could not be displayed, please try again later.';
}
else
{
if(mysqli_num_rows($result) == 0)
{
    echo 'This topic doesn&prime;t exist.';
}
else
{
    while($row = mysqli_fetch_assoc($result))
    {
        //display post data
        echo '<table class="topic" border="1">
                <tr>
                    <th colspan="2">' . $row['topic_subject'] . '</th>
                </tr>';

        //fetch the posts from the database
        $posts_sql = "SELECT
                    posts.post_topic,
                    posts.post_linktent,
                    posts.post_date,
                    posts.post_by,
                    users.user_id,
                    users.user_name
                FROM
                    posts
                LEFT JOIN
                    users
                ON
                    posts.post_by = users.user_id
                WHERE
                posts.post_topic=mysqli_real_escape_string($_GET['id'])."'";

        $posts_result = mysqli_query($sql, $posts_sql);

        if(!$posts_result)
        {
        echo '<tr><td>The posts could not be displayed, please try again.
</tr>
</td></table>';
        }
        else
        {

            while($posts_row = mysqli_fetch_assoc($posts_result))
            {
                echo '<tr class="topic-post">
    <td class="user-post">' . $posts_row['user_name'] . '<br/>' . 
date('d-m-Y H:i', 
strtotime($posts_row['post_date'])) . '</td>
<td class="post-linktent">'.htmlentities(stripslashes
($posts_row
['post_linktent'])) . '</td>
                      </tr>';
            }
        }

        if(!$_SESSION['signed_in'])
        {
echo '<tr><td colspan=2>You must be <a href="signin.php">signed in</a> 
to reply. You can also 
<a href="signup.php">sign up</a> for an account.';
        }
        else
        {
            //show reply box
            echo '<tr><td colspan="2"><h2>Reply:</h2><br />
<form method="post" action="reply.php?id=' . $row['topic_id'] . '">
                    <textarea name="reply-linktent"></textarea><br /><br />
                    <input type="submit" value="Submit reply" />
                </form></td></tr>';
        }

        //finish the table
        echo '</table>';
    }
}
}

include 'footer.php';
?>


Source: wampserver

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.