This question already has an answer here:
it's me again. I tried to make comments to my website and apparently it is working :/, like in the database it shows inserted values, but every time I refresh the page or go to the page, I get this error:
Notice: Undefined index: user_comment_name in /home/kall0467/public_html/svale_rejser/comments.php on line 38 Notice: Undefined index: user_comment_message in /home/kall0467/public_html/svale_rejser/comments.php on line 39 1 record added
I've been trying to figure it out for 2 days. Here's the code:
<?php
$con = mysql_connect("URL","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$result = mysql_query("SELECT * FROM comments");
echo "<table border='1'>
<tr>
<th>Username</th>
<th>Comment</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
$con1=mysqli_connect("url","username","password","db-name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$user_comment_name = $_POST['user_comment_name'];
$user_comment_message = $_POST['user_comment_message'];
$sql1="INSERT INTO user_comment (user_comment_name, user_comment_message)
VALUES
('$user_comment_name','$user_comment_message')";
if (!mysqli_query($con1,$sql1))
{
die('Error: ' . mysqli_error($con1));
}
echo "1 record added";
mysqli_close($con1);
?>
<form action="" method="post">
Name <input type="text" name="user_comment_name">
Message <input type="text" name="user_comment_message">
<input type="submit">
</form>
The weird thing is that when I put the second the mysqli connection into another file called insert.php (for example) and put into the then it works, but it directs me to a white page which I dont want. All help appreciated guys! Cheers :)
</div>