I am trying to fetch text from a specific column of a database (column is called "paste") relative to an url ID. Every column has an ID associated with it in a column called "id". As an example, I have a a data entry for the letter B in column "paste" with an ID of 7 in column "id".
So when the url is extended with "?id=7" the website is supposed to echo out the letter B in my textarea.
I've tried using mysql_fetch_array and echoing $row. Specifically I tried following the code from the "Getting a Row of Data using mysql_fetch_array" example on this link.
The sql query statement works, as I've tried it directly on my database via PHPMyAdmin. I've also verified that the ID in the url is able to be read by echoing $id.
<textarea type="text" name="paste" required autofocus rows="35" cols="150" wrap="off" maxlength="20000">
<?php
// Login information and database
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id = ($_GET['id']);
if(isset($_GET['id']))
{
$query = "SELECT paste FROM pastebin WHERE id = $id";
$result = $mysql_query($query) or die(mysql_eror());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['paste'];
$conn->close();
}
?>
</textarea><br>