I have been trying to follow the API Documentation to update a photo using PHP.

 

I went through the sample code blocks provide, but I really don't understand. May be its missing the detailed explanation. Its doing like

- creating $parts

- creating $newphoto

- changing $parts

 

What I am doing is like:

When the user clicks on a photo, I get the "id" of the clicked photo. This gives information, that this particular photo needs to be updated. Then I redirect the user to the page for uploading a new photo and set the obtained "id" for photo in hidden field.

 

Then I don't know what to do exactly to update the photo.

 

Is my approach wrong? Can anybody suggest me a solution with some sample code.

 

Thanks.

Views: 3000

Reply to This

Replies to This Discussion

You are on the right track! You just need to add form fields for each of the photo's fields you want members to be able to update. Here is a sketch of the flow of information:

  1. Member clicks a photo
  2. The photo's ID is passed into an HTML form as a hidden field
  3. Member inputs fills in the fields they want to update such as title and description
  4. Member clicks the submit button
  5. Web browser sends the data to your server
  6. Server receives the request and translates it into a Ning API request
  7. Member visits the network and see their changes
Hello Devin,

Thank you for your reply. Glad to know that my approach was correct.

Following is the code which I used to udpate the Photo of the user:

$ningApi = new NingApi($subdomain, $consumer_key, $consumer_secret);
$email = $_POST["email"];
$password = $_POST["password"];

$loginMessage = "";
try
{
$result = $ningApi->login($email, $password);
$loginMessage = "success";
}
catch(Exception $e)
{
$loginMessage = $e->getMessage();
}


$parts = array(
"title" => $_POST["title"],
"description" => $_POST["description"],
"id" => $_POST["photoIdToUpdate"]
);

$result = NingApi::instance()->photo->updateById($parts);
print_r($result);

print "Ning Update complete";


It is giving me the following error:

Fatal error: Uncaught Invalid or missing content id. (400) 5-7 thrown in C:\wamp\www\ning\NingException.php on line 56

Can you please tell me why this is not working?

Thanks,
Mahendra.

Hello Devin,

 

You seem to be the only person answer the questions here. Can you please spare some time to answer my question.

 

Thanks,

Mahendra.

The PHP code you posted looks good, I'd check your HTML form and make sure that you are passing in the photoIdToUpdate properly. I'd add in a debug print_r($parts) before you make the request to Ning to verify your PHP code is receiving what you are expecting.

Hey Devin,

 

Thank you for taking time to reply back. Here is my HTML Code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Photo</title>
</head>

<body>
    <div id="logoDiv" style='padding-top: 20px; padding-bottom: 20px;'>
            <img src='logodrk.png' alt='logo' />
</div>
<form action="upload.php" method="post" enctype="multipart/form-data">
        <p style='padding: 20px'>
           
            <span> Title : </span>
            <br />
            <input type="text" name="title" id="title" /> <br />
            <span> Description :  </span>
            <br />
            <textarea name="description" id="description" cols="50" rows="5"> </textarea>
            <br />

            <input type="hidden" id="photoIdToUpdate" name="photoIdToUpdate" value="<?php if(isset($_REQUEST["photoId"])) echo $_REQUEST["photoId"]; ?>" />
            <input type="hidden" id="email" name="email" value="<?php if(isset($_REQUEST["email"])) echo $_REQUEST["email"]; ?>" />
            <input type="hidden" id="password" name="password" value="<?php if(isset($_REQUEST["password"])) echo $_REQUEST["password"]; ?>" />


        <?php
            if(!isset($_REQUEST["photoId"]))
            {
        ?>
               <span> Picture to upload: </span>
                <br />

              <input type="file" name="file" id="file" />            
            <br />
                <input type='submit' value='Upload' style='width: 100px; text-align: center; padding: 0px;' />   
        <?php

            }
            else
            {
        ?>
            <br />
            <input type='submit' value='Update' style='width: 100px; text-align: center; padding: 0px;' />   
        <?php

            }
        ?>

                   
       
        </p>
        </form>
</body>
</html>



Please let me know why is it not updating the photo?

Thanks in advance.

Dear Mahendra,

I'm trying to create a Photo Competition app/section for my network.

My question to you is where are you posting the above photo code ? Is it on your own server or on new Ning pages

on your Ning Network ?

Thanks

- Belal 

Belal - the code is posted on Mahendra's own server.  It requires PHP, so won't work if you just post it on a Ning page.

Mahendra - as Devin suggested, you should check that you are passing in the photoIdToUpdate parameter correctly.  Looking at this part:

<input type="hidden" id="photoIdToUpdate" name="photoIdToUpdate" value="<?php if(isset($_REQUEST["photoId"])) echo $_REQUEST["photoId"]; ?>" />

It seems that the photo ID will only be passed in if $_REQUEST["photoId"] is set.  Can you double-check that in the PHP code, by adding in the code in bold?

$parts = array(
"title" => $_POST["title"],
"description" => $_POST["description"],
"id" => $_POST["photoIdToUpdate"]
);

echo '$parts: '; print_r($parts); echo '<hr>';

$result = NingApi::instance()->photo->updateById($parts);
print_r($result);

Try editing the photo, and if it doesn't work, paste the info this prints out into this discussion and let me know the URL of the network you're working against, and I'll check things out.

Reply to Discussion

RSS

Blog Posts

Getting Started

Posted by Kyle Ford on October 13, 2010 at 8:00am 3 Comments

A Note on API Pricing

Posted by Phil McCluskey on October 1, 2010 at 8:55am 0 Comments

Welcome to Build!

Posted by Kyle Ford on September 30, 2010 at 8:30pm 1 Comment

Ning Status

© 2019   Created by Build Team.   Powered by

Badges  |  Report an Issue  |  Terms of Service