Parse error , unexpected ';'

Hi cp well really I’m just following the tutorial, it says:

“The script can be placed on any PHP enabled server, so long as it is given a PHP file extension (so the server knows to run it as PHP). The URL must point to your Wordpress installation’s proper path, as explained in the article. The username and password fields must be changed to match your Wordpress username and password. The include path must point to a version of the Wordpress class-IXR.php file, so if not on the same server/account as the Wordpress installation, then you may need to download a copy of that file to include it.”

So I thought it came out of the box as such, but obviously I’ll have to provide those details in a form or something I imagine

Well, it depends on how you want to post to your wordpress site. Do you have a thought in mind? What is the overall plan for using this?

Hi, I just want a page where I can enter the title etc and hit send and post to my site

Okay, so yes, you will want to create a HTML page that has a form with a field named title, and a field named description. That form should post to your php script. Once you have your form built, post the HTML and your PHP here again and we can help you tie them together.

Thanks cpradio, here’s the form:

<style>
#form {width: 360px; background-color: #ccc;
border: 1px dotted #333; padding: 5px;
margin: 0px auto;}
div.row {
clear: both;
padding-top: 5px;
}

div.row span.label {
float: left;
width: 100px;
text-align: right;
}

div.row span.formw {
float: right;
width: 235px;
text-align: left;
}
</style>

<div id=“form”>
<form name=“wordressposter” action=“” method=“post”>
<div class=“row”>
<span class=“label”>Title: </span><span
class=“formw”><input name=“title” type=“text” size=“25” /></span>
</div>
<div class=“row”>
<span class=“label”>Comments: </span><span class=“formw”>
<textarea cols=“25” rows=“8” name=“article”></textarea>
</span>
</div>
<div class=“row”>
<span class=“label”>Tags: </span><span
class=“formw”><input name=“title” type=“text” size=“25” name=“keywords”/></span>
</div>
<div class=“row”>
<span class=“label”>Categories: </span><span
class=“formw”><input name=“title” type=“text” size=“25” name=“categories”/></span>
</div>

<div class=“spacer”>
</div>
</form>
</div>

Okay, to get you started, you need to put the filename of your php script in the action=“” of your HTML form (like so, I also removed the duplicate name attributes you had on several fields)

<style>
#form {width: 360px; background-color: #ccc;
border: 1px dotted #333; padding: 5px;
margin: 0px auto;}
div.row {
clear: both;
padding-top: 5px;
}

div.row span.label {
float: left;
width: 100px;
text-align: right;
}

div.row span.formw {
float: right;
width: 235px;
text-align: left;
}
</style>

<div id="form">
<form name="wordressposter" action="myphpscript.php" method="post">
<div class="row">
<span class="label">Title: </span><span
class="formw"><input name="title" type="text" size="25" /></span>
</div>
<div class="row">
<span class="label">Comments: </span><span class="formw">
<textarea cols="25" rows="8" name="article"></textarea>
</span>
</div>
<div class="row">
<span class="label">Tags: </span><span
class="formw"><input type="text" size="25" name="keywords"/></span>
</div>
<div class="row">
<span class="label">Categories: (separate with commas)</span><span
class="formw"><input type="text" size="25" name="categories"/></span>
</div>

<div class="spacer">
</div>
</form>
</div>

Then you need to update your PHP script to use the form elements

<?php
include("./wp-includes/class-IXR.php");
$client = new IXR_Client('http://MYSITE.org/xmlrpc.php');

if (!$client->query('wp.getCategories','', 'WHERE-I-PUT-MY-WORDPRESS-USERNAME','WHERE-I-PUT-MY-WORDPRESS-PASSWORD')) {
echo('An error occurred calling wp.getCategories - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$response = $client->getResponse();




$content = array(
'title'=>$_POST['title'],
'description'=>$_POST['article'],
'mt_allow_comments'=>'1',
'mt_allow_pings'=>'1',
'post_type'=>'post',
'mt_keywords'=>$_POST['keywords'],
'categories'=>split(',', $_POST['categories'])
);

var_dump($content); // paste the output of this back to the forum for us to review.

if (!$client->query('metaWeblog.newPost','', 'WHERE-I-PUT-MY-WORDPRESS-USERNAME','WHERE-I-PUT-MY-WORDPRESS-PASSWORD', $content, false)) {
echo('An error occurred calling metaWeblog.newPost - '.$client->getErrorCode().":".$client->getErrorMessage());
}
echo $client->getResponse(); //with Wordpress, will report the ID of the new post
?>

Now I am making a few assumptions, 1) I am assuming the WordPress API will sanitize the data because the examples found on http://life.mysiteonline.org/archives/161-Automatic-Post-Creation-with-Wordpress,-PHP,-and-XML-RPC.html do not tell me that I need to sanitize the data. 2) I am assuming allow_comments and allow_pings are a true/false field and since the form doesn’t specifically ask, I hard coded them to true.

Hi cpradio, thanks I get this array:

array(7) {
[“title”]=>
string(3) “new”
[“description”]=>
string(3) “new”
[“mt_allow_comments”]=>
string(1) “1”
[“mt_allow_pings”]=>
string(1) “1”
[“post_type”]=>
string(4) “post”
[“mt_keywords”]=>
string(3) “new”
[“categories”]=>
array(1) {
[0]=>
string(10) “category name”
}
}
548

And no error? So it seems you should have a new post in your WordPress installation with a title of new and a article/description of new.

With that said, you can remove the var_dump line, and you can remove your echo $client->getResponse(); (unless you want to know the post ID that was created)

I couldn’t see it published so I just checked the wp admin, and it’s there but as a draft not a published post. I’ll check out the wordpress documentation and see why it isn’t being published. Thanks for all the help cpradio really appreciated :slight_smile:

http://codex.wordpress.org/XML-RPC_MetaWeblog_API

You can set a publish indicator to 1 to force it to publish when you call newPost like so:

$content = array(   
'title'=>$_POST['title'],   
'description'=>$_POST['article'],   
'mt_allow_comments'=>'1',   
'mt_allow_pings'=>'1',   
'post_type'=>'post',    
'publish'=>'1',   
'mt_keywords'=>$_POST['keywords'],   
'categories'=>split(',', $_POST['categories']) 
);

I do want to point out 1 more thing, that you should take very seriously.

Since your PHP script contains your WordPress username and password, anyone that posts information to that script with title, article, keywords, and categories will be able to post an entry to your blog.

One way to protect against this is to have your username and password as fields on your form that must be filled out. If this concerns you, I’ll be glad to help you sort that out, or if you rather take a different approach, I can help provide those as well.

Hi doesn’t work, it maybe something to do with my other plugins, I’m going to do some tests, cheers

Yes that is a concern, that is exactly what is needed, that the username and passoword are forms that must be filled out please

Form that has username and password

<style>
#form {width: 360px; background-color: #ccc;
border: 1px dotted #333; padding: 5px;
margin: 0px auto;}
div.row {
clear: both;
padding-top: 5px;
}

div.row span.label {
float: left;
width: 100px;
text-align: right;
}

div.row span.formw {
float: right;
width: 235px;
text-align: left;
} 
</style>

<div id="form">
<form name="wordressposter" action="myphpscript.php" method="post">
<div class="row">
<span class="label">Username: </span><span
class="formw"><input name="username" type="text" size="25" /></span>
</div>
<div class="row">
<span class="label">Password: </span><span
class="formw"><input name="password" type="password" size="25" /></span>
</div>
<div class="row">
<span class="label">Title: </span><span
class="formw"><input name="title" type="text" size="25" /></span>
</div>
<div class="row">
<span class="label">Comments: </span><span class="formw">
<textarea cols="25" rows="8" name="article"></textarea>
</span>
</div>
<div class="row">
<span class="label">Tags: </span><span
class="formw"><input type="text" size="25" name="keywords"/></span>
</div>
<div class="row">
<span class="label">Categories: (separate with commas)</span><span
class="formw"><input type="text" size="25" name="categories"/></span>
</div>

<div class="spacer">
</div>
</form>
</div>

New set of code that accepts username and password from the form

<?php   
include("./wp-includes/class-IXR.php");   
$client = new IXR_Client('http://MYSITE.org/xmlrpc.php');   

if (!$client->query('wp.getCategories','', $_POST['username'],$_POST['password'])) {   
echo('An error occurred calling wp.getCategories - '.$client->getErrorCode().":".$client->getErrorMessage());   
}   
$response = $client->getResponse();   




$content = array(   
'title'=>$_POST['title'],   
'description'=>$_POST['article'],   
'mt_allow_comments'=>'1',   
'mt_allow_pings'=>'1',   
'publish'=>true,   // try true instead of '1'
'post_type'=>'post',   
'mt_keywords'=>$_POST['keywords'],   
'categories'=>split(',', $_POST['categories']) 
);   

//var_dump($content); // paste the output of this back to the forum for us to review. 

if (!$client->query('metaWeblog.newPost','', $_POST['username'],$_POST['password'], $content, false)) {   
echo('An error occurred calling metaWeblog.newPost - '.$client->getErrorCode().":".$client->getErrorMessage());   
}   
echo $client->getResponse(); //with Wordpress, will report the ID of the new post   
?>

I also changed the ‘publish’ line to use true instead of ‘1’, maybe that will make a difference.

From the http://codex.wordpress.org/XML-RPC_MetaWeblog_API

You can also try setting ‘post_status’ => ‘publish’ like so

$content = array(   
'title'=>$_POST['title'],   
'description'=>$_POST['article'],   
'mt_allow_comments'=>'1',   
'mt_allow_pings'=>'1',   
'publish'=>true,   // try true instead of '1'
'post_status'=>'publish',
'post_type'=>'post',   
'mt_keywords'=>$_POST['keywords'],   
'categories'=>split(',', $_POST['categories']) 
);  

Hi cpradio I found the solution!
In class-wp-xmlrpc-server.php, find this line

Code:

‘publish’ : ‘draft’;

Replace that with

Code:

‘draft’ : ‘publish

Good to know :slight_smile: