drdawt9210 2012-11-14 23:38
浏览 38

使用php连接数据并将数据插入mysql表

I am a PHP newbie and have been trying for sometime now to connect to MySQL database using PHP so I can insert data into a table I have created but I am unable to do this.

I suspect the problem is coming from my PHP .ini file,but that's just me.
Would be grateful if anyone can help me configure my PHP .ini file so I can connect to MySQL and insert data into my table. Here is my PHP script in case you are wondering.
Any help will be gratefully appreciated.

<?php

$host ="localhost";
$username = "username";
$password = "password";
$database = "database1";
$table ="users";
$con = mysql_connect("localhost","username","password");

if (!$con)
{
die('Could not connect:'.mysql_error());
}
mysql_select_db("database1",$con);


$mysql = "INSERT INTO $table(name,email,password)
VALUES('$_POST[name]','$_POST[email]','$_POST[password]";

if(mysql_query($mysql)) die(mysql_error()); 
echo"Data inserted";
mysql_close();
?> 
  • 写回答

2条回答 默认 最新

  • dongqu2863 2012-11-14 23:41
    关注

    First, why do you have <br/> in your PHP statements? Remove all those. Also, you have to use PDO or mysqli_ instead of the mysql_ library, mysql_ is deprecated.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?