[英]No database selected php to mysql
i'm making a customer script for some friends. 我正在为一些朋友制作客户脚本。 they have a gsm/pc service.
他们有gsm / pc服务。 i've made this so far:
到目前为止,我已经做到了:
<div id="somedialog" class="dialog">
<div class="dialog__overlay"></div>
<div class="dialog__content">
<form method="post" action="mysql.php"><p align="left"><font color="white" size="5" face="Tahoma">NUME: <textarea name="nume" style="overflow:hidden" rows="1" cols="17"></textarea> PRENUME: <textarea name="prenume" style="overflow:hidden" rows="1" cols="15"></textarea><br> TIP DEVICE: <textarea name="tipd" style="overflow:hidden" rows="0" cols="15"></textarea>BRAND: <textarea name="brand" style="overflow:hidden" rows="1" cols="15"></textarea> MODEL: <textarea name="model" style="overflow:hidden" rows="1" cols="15"></textarea><br>PROBLEMA: <textarea name="problema" style="overflow:hidden" rows="1" cols="15"></textarea> DETALII: <textarea name="detalii" style="overflow:hidden" rows="1" cols="15"></textarea></p><div><button class="action" data-dialog-close>Inchide</button><button class="action" data-dialog-close>Creaza</button></div></font><input type="submit" value="Submit"></form>
</div>
</div>
</div><!-- /content -->
my mysql.php page: 我的mysql.php页面:
<?php
$dbhandle = mysql_connect("localhost", "root", "", "client");
if (!$dbhandle) {
die("Connection failed: " . mysql_connect_error());
}
echo "Connected successfully";
$nume=$_POST['nume'];
$prenume=$_POST['prenume'];
$tipd=$_POST['tipd'];
$brand=$_POST['brand'];
$model=$_POST['model'];
$problema=$_POST['problema'];
$detalii=$_POST['detalii'];
mysql_query("INSERT INTO client (Nume, Prenume) VALUES ('$nume', '$prenume')");
?>
When i run the script it gives me No database selected. 当我运行脚本时,它没有选择数据库。
This is a screenshot of my database: screenshot 这是我的数据库的屏幕截图 : 屏幕截图
could you help me please? 请问你能帮帮我吗?
Use mysql_select_db : 使用mysql_select_db :
$dbhandle = mysql_connect("localhost", "root", "");
if (!$dbhandle) {
die("Connection failed: " . mysql_connect_error());
}
mysql_select_db('my_database_name', $dbhandle);
....
The best option here change to mysqli_* functions
, and create a specific user for your table, with some grants: 最好的选择是更改为
mysqli_* functions
,并为表创建一个特定用户,并提供一些授权:
$dbhandle = mysqli_connect("localhost", "client_db_user", "client_db_password", "client");
...
After you get connected to the database, change your mysql_query into variable to make it easier to identify. 连接到数据库后,将mysql_query更改为变量以使其易于识别。
$query = mysql_query("your query");
if ($query) { echo "Insertion success"; } else { echo "Failed"; echo mysql_error(); };
And also add var_dump($_POST); 还要添加var_dump($ _ POST); to identify which variable did you send from the previous file.
以确定您是从前一个文件发送的变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.