使用php時出現了no database selected的問題 求大神協助

來源:互聯網
上載者:User
我在myadminphp中建立了名為flash的資料庫

下面是我的php代碼


回複討論(解決方案)

no database selected 沒有資料庫被選擇

很明顯,你在沒有指明資料庫的情況下就對錶進行了操作

可是你看 我下面的代碼 我不是指明了 是“flash”資料庫嗎

no database selected 沒有資料庫被選擇

很明顯,你在沒有指明資料庫的情況下就對錶進行了操作



可是你看 我下面的代碼 我不是指明了 是“flash”資料庫嗎

很遺憾,根本就看不見你的圖

很遺憾,根本就看不見你的圖



啊 那我發文本吧

$username=$_POST['username'];
$userage=$_POST['userage'];
$usergender=$_POST['usergender'];

echo "使用者姓名:".$username."
";
echo "使用者年齡:".$userage."
";
echo "使用者性別:".$usergender."
";

$host='127.0.0.1';
$root='root';
$pwd='';

$con=mysql_connect($host,$root,$pwd);

if($con==false){
echo "串連資料庫失敗!";
}else{
mysql_query("set name'utf8'");

mysql_select_db("flash");

$sql="INSERT INTO test(name,age,gender)
VALUES('$username','$userage','$usergender')";

if(!mysql_query($sql,$con)){
die('Error:'.mysql_error());
}
echo "添加一條記錄";
mysql_close($con);
}

mysql_select_db("flash"); 需要放在mysql_query之前,以下兩句交換一下位置就可以了。

mysql_select_db("flash"); // 先select db
mysql_query("set names 'utf8'"); // 再set names

mysql_query("set name'utf8'");

mysql_select_db("flash");

上面兩個語句調換下位置,先選擇資料庫再set names

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.