我初学PHP 试验一下操作数据库的数据的插入和读 ,却老提示24.28行有问题。我改了很久还是没发现怎么出错求指正
<?php
include ('config.php');
$name=$_POST['name'];
$age=$_POST['age'];
include('config.php');
$db = mysql_connect($db_url,$db_user,$db_psw);
$sql = "
INSERT INTO `".$db_base."`.`".$db_tab."` (`id`, `password`)
VALUES ('$name', '".$age."');
";
mysql_query($sql,$db);mysql_select_db("hk173");$result = mysql_query("SELECT id, name FROM yonghu"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { // 此为24行
printf("ID: %s Name: %s", $row[0], $row[1]);
}mysql_free_result($result); //此为28行
?>
hello,you are <?php echo htmlspecialchars($_POST['name']); ?>.
you are <?php echo (int)$_POST['age']; ?> years old
<?php
include ('config.php');
$name=$_POST['name'];
$age=$_POST['age'];
include('config.php');
$db = mysql_connect($db_url,$db_user,$db_psw);
$sql = "
INSERT INTO `".$db_base."`.`".$db_tab."` (`id`, `password`)
VALUES ('$name', '".$age."');
";
mysql_query($sql,$db);mysql_select_db("hk173");$result = mysql_query("SELECT id, name FROM yonghu"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { // 此为24行
printf("ID: %s Name: %s", $row[0], $row[1]);
}mysql_free_result($result); //此为28行
?>
hello,you are <?php echo htmlspecialchars($_POST['name']); ?>.
you are <?php echo (int)$_POST['age']; ?> years old
error_reporting(E_ALL);
include ('config.php');
$name=$_POST['name'];
$age=$_POST['age'];
$db = mysql_connect($db_url,$db_user,$db_psw) or die("数据库参数连接错误:".mysql_error());;
$sql = "INSERT INTO".$db_base.".".$db_tab."(id, password) VALUES ($name,$age)";
mysql_query($sql,$db) or die("SQL语句错误:".mysql_error());
mysql_select_db("hk173");
$result = mysql_query("SELECT id,name FROM yonghu") or die("SQL语句错误:".mysql_error());;
while ($row = mysql_fetch_array($result, MYSQL_NUM)) { // 此为24行
printf("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result); //此为28行
?>
hello,you are <?php echo htmlspecialchars($_POST['name']); ?>.
you are <?php echo (int)$_POST['age']; ?> years old