So I just put this together and have stared at it about as long as I can stand. Hoping one of you guys would be willing to take a peek at it for me and see if you point me in the right direction.
Basically what I am trying to do is pull all the zipcodes, cities, state, counties in the US from a SQL database and then auto post them to Wordpress. Problem I am having is error @ the wordpress post.
Error is
I have tried to add the "ID" and add the blank '' in the values sections of the wp_posts. As well as the post_id and also the meta_id followed by the blank '' in the wp_postsmeta section as recommended all over google as the solution. Any suggestions would much be appreciated. And a few boobs for your trouble
Basically what I am trying to do is pull all the zipcodes, cities, state, counties in the US from a SQL database and then auto post them to Wordpress. Problem I am having is error @ the wordpress post.
Error is
Invalid query dumbass: Column count doesn't match value count at row 1
I have tried to add the "ID" and add the blank '' in the values sections of the wp_posts. As well as the post_id and also the meta_id followed by the blank '' in the wp_postsmeta section as recommended all over google as the solution. Any suggestions would much be appreciated. And a few boobs for your trouble
PHP:
<?php
$link = @mysql_connect('localhost','username','password');
if (!$link) {
echo ('<p>Unable to connect to the ' .
'database server at this time.</p>' );
exit();
}
else
{
echo 'Connected successfully';
}
$db_selected = mysql_select_db('database', $link);
if (!db_selected)
{
die ('Can\'t use mysql db : ' . mysql_error());
}
$post_author = "2"; //Wordpress Author ID
//Pull Data From Database
$result = @mysql_query('SELECT Zip_Code, City, State, County FROM ZIP_CODES');
if (!$result) {
die('<p>Error getting zip: ' . mysql_error() .
'</p>');
}
//Insert data from zip code table in Wordpress
while ( $row = mysql_fetch_array($result)) {
$zip = $row['Zip_Code'];
$city = $row['City'];
$state = $row['State'];
$county = $row['County'];
}
{
$post_content = "blah blah blah $county blah blah blah? blah blah blah $city blah blah blah
blah blah blah $state $zip";
$post_title = "TITLE of POST".$city;
$post_name = "title of post".strtolower($city);
$sql = "
INSERT INTO
wp_posts
(
post_author,
post_date,
post_date_gmt,
post_content,
post_title,
post_status,
post_name,
post_modified,
post_modified_gmt,
post_type
)
VALUES
(
'$post_author',
NOW(),
NOW(),
'$post_content',
'$post_title',
'publish',
'open',
'open',
'$post_name',
NOW(),
NOW(),
'page'
)
";
echo "<PRE>";
print_r($sql);
echo "</PRE>";
$results = mysql_query($sql);
if (!$results)
{
die('Invalid query dumbass: ' . mysql_error());
}
else
{
$postid = mysql_insert_id();
$sql = "INSERT INTO
wp_postmeta
(
post_id,
meta_key,
meta_value
)
VALUES
(
'post_id',
'_wp_page_template',
'default'
)
";
$results = mysql_query($sql);
echo "<BR>
Created page for ".$city;
}
}
?>





