sql php conect返回值

时间:2015-05-02 23:26:02

标签: php sql

mpost.php正常工作当checklogin.php未连接时,OK将数据作为新成员发送给MySQL。我根据自己的知识尝试了一切,但是我被卡住了 还有其他想法吗?

我的db_namepasswordtable_name其成员,您可以在mpost.php上看到。



<?php
//this its members post mpost . php
define('DB_NAME', 'abcd');
define('DB_USER', 'abcd');
define('DB_PASSWORD', '******');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

 if (!$link)
{
die('Could NOT Connect: rong pass ' . mysql_error(rong_pass));
}
$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) 
{
die ('Cant\'t use' . DB_NAME. 'abcd' . mysql_error());
}
echo 'log in succes';
$com_name = $_POST["com_name"]; 
$com_ger_nr = $_POST["com_reg_nr"];
$password = $_POST["password"];



$sql = "INSERT INTO members (com_name, com_reg_nr, password) VALUES                   
('$_POST[com_name]','$_POST[com_reg_nr]','$_POST[password]')";

$result = mysql_query($sql) or die (" could not save record sorry ");

mysql_close();
?>
</ p><a href="demo.html">hey hey</a>

//tot odata ai fost adaugat in baza noastra de date
&#13;
<?php
// this its checklogin . php
$host="localhost"; // Host name 
$username="abcd"; // Mysql username 
$password="********"; // Mysql password 
$db_name="abcd"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("ups pula conectie"); 
mysql_select_db("$db_name")or die("pula DB");

// username and password sent from, the form 
$com_name = $_POST["com_name"]; 
$com_reg_nr = $_POST["com_reg_nr"];
$password = $_POST["password"];

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("com_name");
session_register("com_reg_nr");
session_register("password"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 

您忘记选择数据库了。

mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);