<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$installcontent=mysql_query("INSERT INTO `wordpressnewsbie`.`wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '0', '".$_POST["time"]."', '".$_POST["time"]."', '".$_POST["title"]."', '".$_POST["content"]."', '', 'publish', 'open', 'open', '', '', '', '', '".$_POST["time"]."','".$_POST["time"]."', '', '0', '', '0', 'post', '', '0');");
$linshi='".$_POST["title"]."';
echo $linshi;
$sql_post_id = "SELECT ID from wp_posts WHERE post_title='".$linshi."'";
$post_id = mysql_query($sql_post_id,$con
print_r(mysql_fetch_array($post_id)););//我的想法是title添加进数据库后在获取个title对应的ID,结果怎么数据成功添加进去了,print_r出来都是空白呢mysql_close($con);
?>
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$installcontent=mysql_query("INSERT INTO `wordpressnewsbie`.`wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '0', '".$_POST["time"]."', '".$_POST["time"]."', '".$_POST["title"]."', '".$_POST["content"]."', '', 'publish', 'open', 'open', '', '', '', '', '".$_POST["time"]."','".$_POST["time"]."', '', '0', '', '0', 'post', '', '0');");
$linshi='".$_POST["title"]."';
echo $linshi;
$sql_post_id = "SELECT ID from wp_posts WHERE post_title='".$linshi."'";
$post_id = mysql_query($sql_post_id,$con
print_r(mysql_fetch_array($post_id)););//我的想法是title添加进数据库后在获取个title对应的ID,结果怎么数据成功添加进去了,print_r出来都是空白呢mysql_close($con);
?>
print_r(mysql_fetch_array($post_id)););
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$installcontent=mysql_query("INSERT INTO `wordpressnewsbie`.`wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '0', '".$_POST["time"]."', '".$_POST["time"]."', '".$_POST["title"]."', '".$_POST["content"]."', '', 'publish', 'open', 'open', '', '', '', '', '".$_POST["time"]."','".$_POST["time"]."', '', '0', '', '0', 'post', '', '0');");
$linshi=$_POST["title"];
echo $linshi;
$sql_post_id = "SELECT ID FROM wp_posts WHERE post_title='$linshi'";
$post_id = mysql_query($sql_post_id, $con);
print_r(mysql_fetch_array($post_id));echo '<br/>';
echo "sql:".$sql_post_id;
echo "error".mysql_error();mysql_close($con);
?>
sql:SELECT ID FROM wp_posts WHERE post_title='sdfsdf'error //$sql_post_id = "SELECT ID from wp_posts WHERE post_title='$linshi'"; //$post_id = mysql_query($sql_post_id,$con); //print_r(mysql_fetch_array($post_id)); //echo '
'; //echo "sql:".$sql_post_id; //echo "error".mysql_error(); //echo $post_id; //$installcontent=mysql_query("INSERT INTO `wordpressnewsbie`.`wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '0', '".$_POST["time"]."', '".$_POST["time"]."', '".$post_id1."', '".$post_id1."', '', 'publish', 'open', 'open', '', '', '', '', '".$_POST["time"]."','".$_POST["time"]."', '', '0', '', '0', 'post', '', '0');"); mysql_close($con); //$result = mysql_query("SELECT * FROM wp_terms"); //while($row = mysql_fetch_array($result)) // { // echo $row['name'] . " " . $row['slug']; // echo "
"; // } // //mysql_close($con); ?>
echo $linshi;
这段换成
$linshi=‘HELLO WORLD!’
echo $linshi;
就有返回ID的哦,(数据库里有HELLO WORLD!这个字段)
谢谢,再帮我解决下哈
$linshi='HELLO WORLD!';
echo $linshi;
$sql_post_id = "SELECT ID FROM wp_posts WHERE post_title='$linshi'";
$post_id = mysql_query($sql_post_id, $con);
print_r(mysql_fetch_array($post_id));
echo '<br/>';
echo "sql:".$sql_post_id;
echo "error".mysql_error();
mysql_close($con);
?>
服务器返回的就是
HELLO WORLD!Array ( [0] => 1 [ID] => 1 )
sql:SELECT ID FROM wp_posts WHERE post_title='HELLO WORLD!'error //$sql_post_id = "SELECT ID from wp_posts WHERE post_title='$linshi'"; //$post_id = mysql_query($sql_post_id,$con); //print_r(mysql_fetch_array($post_id)); //echo '
'; //echo "sql:".$sql_post_id; //echo "error".mysql_error(); //echo $post_id; //$installcontent=mysql_query("INSERT INTO `wordpressnewsbie`.`wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '0', '".$_POST["time"]."', '".$_POST["time"]."', '".$post_id1."', '".$post_id1."', '', 'publish', 'open', 'open', '', '', '', '', '".$_POST["time"]."','".$_POST["time"]."', '', '0', '', '0', 'post', '', '0');"); mysql_close($con); //$result = mysql_query("SELECT * FROM wp_terms"); //while($row = mysql_fetch_array($result)) // { // echo $row['name'] . " " . $row['slug']; // echo "
"; // } // //mysql_close($con); ?>
我需要的就是下面这个啊,返回过来的ID号1
Array ( [0] => 1 [ID] => 1 )
不知道为什么用了$_POST[title]之后就不行了
1, 2, 3, 4, 5, 6
NULL, '0', '".$_POST["time"]."', '".$_POST["time"]."', '".$_POST["title"]."',
1, 2, 3, 4, 5
post_title和$_POST['title']没在同一位置
也就是说 post_title写入的数据其实是 $_POST["content"]
所以没有结果返回也正常
先换成
$linshi=$_POST['content'];
echo $linshi;
再看看,如果有返回数组,那我就猜对了