时间:2021-07-01 10:21:17 帮助过:7人阅读
$conn=@mysql_connect("localhost","root","123456") or die(mysql_error()); // localhost是添你db的host,如果不是本地的请修改这里
@mysql_select_db('mydatabase',$conn) or die(mysql_error());
$url= $_POST["url"];
$content = $_POST["content"];
echo "url:";
echo $url;
echo "
";
echo "content:";
echo $content;
echo "
";
if($url){
if($content)
{
$sqlstr = "insert into tcontent(url,content) values('".$url."','".$content."')";
mysql_query($sqlstr) or die(mysql_error());
echo 'insert success';
}
}
mysql_close($conn);
?>
自己搞定了,只是依样画葫芦,不明白啥意思。
$dsn = 'mysql:host=localhost;dbname=mydatabase'; $db = new PDO($dsn,'root','123456'); $sql = "insert into tcontent(url,content)values(?,?)"; $pp = $db->prepare($sql); $pp->execute(array($_POST['url'],$_POST['content'])); //echo $db->lastInsertId();