gpt4 book ai didi

php - 使用 XAMPP 时没有选择数据库错误

转载 作者:行者123 更新时间:2023-11-29 05:32:45 26 4
gpt4 key购买 nike

我一直收到 No database selected 错误。我不确定是否有办法检查是否有东西被阻止。

这是我的 PHP 代码:

<?php
if(isset($_POST['submit']))
{
$fname = $_FILES['sel_file']['name'];

$chk_ext = explode(".",$fname);

if(strtolower($chk_ext[1]) == "csv")
{
$filename = $_FILES['sel_file']['tmp_name'];
$handle = fopen($filename, "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$sql = "INSERT into thingy(thingr,thing1,thing2) " .
"values('$data[0]','$data[1]','$data[2]')";
mysql_query($sql) or die(mysql_error());
}
fclose($handle);
echo "Successfully Imported";
}
else
{
echo "Invalid File";
}
}
?>
<form action='' method='post' enctype='multipart/form-data' >

Import File : <input type='file' name='sel_file' size='20'>
<input type='submit' name='submit' value='submit'>

</form>

最佳答案

试试这个,

<?php
$conn_str = mysql_connect('localhost', 'yout_user_id', 'your_user_password');
if (!$conn_str) {
die('Not connected to the database: ' . mysql_error());
}

$db_selected = mysql_select_db('your_database_name', $conn_str);
if (!$db_selected) {
die ("Can\'t use your_database_name : " . mysql_error());
}
if(isset($_POST['submit']))
{
$fname = $_FILES['sel_file']['name'];

$chk_ext = explode(".",$fname);

if(strtolower($chk_ext[1]) == "csv")
{

$filename = $_FILES['sel_file']['tmp_name'];
$handle = fopen($filename, "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$sql = "INSERT into thingy(thingr,thing1,thing2) " .
"values(\"$data[0]\",\"$data[1]\",\"$data[2]\")";
mysql_query($sql) or die(mysql_error());
}
fclose($handle);
echo "Successfully Imported";
}
else
{
echo "Invalid File";
}
}
?>

<form action='' method='post' enctype='multipart/form-data' >

Import File : <input type='file' name='sel_file' size='20'>
<input type='submit' name='submit' value='submit'>
</form>

关于php - 使用 XAMPP 时没有选择数据库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13355200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com