私は Web 開発の初心者です。PHPを使用して、フォームからサーバーのデータベースにデータを更新する方法を確認していました。データベースには接続できているようですが、データを更新できません。
フォームの html:
<html>
<head>
<title>Experiment with php and db</title>
</head>
<body>
<form name="form1" id="form1" method="post" action="formact.php">
<p><input type="text" name="fname" placeholder="first name"/></p>
<p><input type="text" name="lname" placeholder="last name"/></p>
<p><textarea name="words" placeholder="Enter what you think"></textarea></p>
<p><button type="submit"></button></p>
</form>
</body>
そして、ここにformact.phpがあります
<?php
$name=$_POST['fname']." ".$_POST['lname'];
$ta=$_POST['words'];
$con = mysql_connect();
$msg="status 0";
if (!$con)
{
$msg="db connect failed";
die('Could not connect: ' . mysql_error());
}
if ($con)
$msg="db connected";
mysql_select_db("php_test",$con);
$success=mysql_query("INSERT INTO news (title, blog_entry) VALUES ('$name','$ta')");
mysql_close($con);
?>
<html>
<head>
<title>Form with php</title>
</head>
<body>
<?php
echo $name."<br/>";
echo $ta."<br/>";
echo $msg."<br/>";
if(!$success)
echo "DB update failed..";
?>
</body>
</html>
エコーで$msg=="db connected"
andを取得しています。!success==true
どこが間違っているのか教えてください。