我想将选定的单选按钮值插入数据库。只是"是"或"不"。如果有人能给我一个想法,那将是一个很大的帮助。我正在使用PHP脚本lampp(linux ubuntu 14.04)。提前致谢。 这是php脚本 这是localhost的结果。 我使用数据库mysql:-database_name:projet -table_name:action,谁是两列:温度,湿度
所以..任何帮助和感谢
答案 0 :(得分:0)
您可以创建一个名为DB.php的文件并添加以下内容,并在需要时将其包含在文件中,或者您只需调用该文件即可。尽量不要重复练习。
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('project');
获取温度值并将其重新指定为是或否:
if($temperature == "ON_1"){
$temperature == "Yes";
}
else{
$temperature == "No";
}
获取湿度值并将其重新指定为是或否:
if($humidity == "ON_2"){
$humidity == "Yes";
}
else{
$humidity == "No";
}
在SQL连接中添加详细信息:
$sql = "INSERT INTO actions ".
"(humidity,temperature) ".
"VALUES ".
"('$humidity','$temperature')";
$results = mysql_query( $sql, $conn );
if(! $results )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
上述方法可以帮助您检查数据输入是否正确。