Jump to content

Crap! I've been asked to change my PHP ! Its been working for years!


JTapp

Recommended Posts

Unfortunately, I have been asked to stop importing CSV data into phpMyAdmin and instead call on a file that sits on another IP address.  My head hurts thinking about it.  

 

I have the IP address and I think the name of the file.

But I really need to be pointed to API 101 or something.

 

I'm at a complete loss..

Anybody able to give advice?
 

<?php
$username = "username";
$password = "password";
$hostname = "hostname"; 

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("DB",$dbhandle)
or die("Could not select DB");

$metode = mysql_real_escape_string($_POST['metode']);
$search = mysql_real_escape_string($_POST['search']);

$query = mysql_query("SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeLocationCity, strLodgeMailingPostCode FROM tblLodges WHERE TRIM(LEADING '0' FROM $metode) = '$search' GROUP BY strLodgeName LIMIT 50");
while ($row = @mysql_fetch_array($query))

{
      echo "<tr bgcolor=\"#dddddd\"><td><center>";
 echo $row["intLodgeNumber"];
      echo "</center></td><td><center>";
 echo ltrim($row["strLodgeName"], '0');
      echo "</center></td><td><center><span class=\"style2\">";
      echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='http://www.customer.com/lodgelocator/3view.php?id=";
      echo $row["intLodgeNumber"];
      echo "'\" /></center></td>";
      echo "</center></td><td><center>";
 echo ltrim($row["strLodgeLocationCity"], '0');
 echo $row["strLodgeLocationCity"];

      echo "</center></td><td><center>";
      echo ltrim($row["intDistrictID"], '0');
    }?>
        
Link to comment
Share on other sites

Thanks Kevin, I'm trying to access an existing API.

 

Currently sitting through an online course in REST.. (actually.. I'm also installing Chrome [REALLY DIDN'T WANT TO] so I can install something called the REST CONSOLE)…  cURL came up in my research as well..

I just need to get data from an ip address and post it on my existing page above.

I anticipate lots of formatting issues..

But right now I'm just trying to figure out how to get it as I'm only knowledgeable about signing into the local sql

 

thx again

Link to comment
Share on other sites

whichever api you are trying to access will be documented as to the format and type of parameters it accepts and what format the data will be returned as and since it's likely you are not the first person to ever try to access whatever api you are trying to use, there's likely php examples posted on the api's web site, or just on the web somewhere, showing how you can send commands from and receive the data back into your script.

Link to comment
Share on other sites

No, its brand spankin' new.

Somebody I work with just created it yesterday.

 

He has given me two sets of sample body formats that I can cut and paste:

 

application/xml, text/xml

 

the other is

 

application/json, text/json

 

I can't imagine there was a need to lock it so I'm not surprised there is no information about authorization and access privs.

But I'm just trying to figure out what I'm looking at..

In the body of the sample code there is a URL that i was assuming was a document that included the actual data..

 

 

This REST Console isn't helping that much b/c I don't understand what I'm looking at.

I'm now checking out "RequestBin" to see if that is a bit more intuitive..

thanks

Link to comment
Share on other sites


$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);
Link to comment
Share on other sites

I have no idea what API you are trying to access.  I'm sure if you posted all applicable information we could get you sorted real quick.

A list of things that is needed.

1. API name, or link, or list of methods.

2. Exactly what you wish to accomplish.

 

Right now, the only thing I can give you is cURL being the proper way of doing this.

<?php
        //data to send to API
        $data = "var1=what&var2=ever";


        // create curl resource

        $ch = curl_init();



        // set url

        curl_setopt($ch, CURLOPT_URL, "example.com");



        //return the transfer as a string

        curl_setopt_array($ch,array(
                                    CURLOPT_RETURNTRANSFER => 1,
                                    CURLOPT_POST           => 1,
                                       CURLOPT_POSTFIELDS  => $data
                                   ));

       

        // $output contains the output string

        $output = curl_exec($ch);



        // close curl resource to free up system resources

        curl_close($ch);
 
        //Now we can use the $output in our application however we wish.

?>
Link to comment
Share on other sites

 

$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);

 

You could have mentioned the source: http://stackoverflow.com/a/2445332

 

Clearly homework, or do you really think we believe you work with somebody who is capable to create an API while you fail to write a line of PHP code that actually works.. Not to mention he would probably have given you some sample code. Even your OP uses code from your post you made last year: http://forums.phpfreaks.com/topic/280829-search-using-metode-cant-trim-help-please/ which according to you should suffice in making us believe this has somehow something to do with the API.

 

Also the code in your OP is full of contradictions because programmers are one thing above all: consistent. They don't use the hungarian notation in one instance and then do something else entirely in another. And since the hungarian notation is quite popular among teachers and not so much among developers further increases the likelihood this is a course assignment.

 

Another thing, EVERYONE here has Chrome installed, and Firefox, and Safari, and Opera, and has VM's of WinXP, WinVista, Win7 to test IE6 through IE10. It's part of being a webdeveloper which if you were employed as one would have known.

 

Don't lie, simply state you have trouble completing your homework and someone on here might actually help you/do it for you.

 

Sorry for the rant but I REALLY don't like being lied to.

Edited by ignace
Link to comment
Share on other sites

Geez Ignace.. Hijack threads much?

Does the fact that I'm NOT a "Guru" or "Advanced Member" mean anything?

 

Para 1.) I would have no idea how to find that or what it is.  After I pick myself off the ground from your post, I'll go check it out.

 

Para 2.) You are 100% incorrect and the comment provokes a major topic jump and irrelevant discussion

 

Para 3.) I will try to decipher what you are talking about with this: I found that code on another website and pasted it in to see if that was the right road to travel.  I'm nearly 50 years old and owe $30k in student loans.  My school days are over.  BUT as I mentioned earlier in this thread.. I recently joined lydna.com to try to find an answer prior to my post.. I can't remember if that's where I got that code from as it is not the only place I had been scouring. 

 

Para 4.) See opening sentance.

 

Para 5.) I don't lie and have no real need to lie. 

 

Para 6.) Apology accepted.  I have been working nonstop on trying to get this resolved before a trade show.. I'm hoping there is no need to continue this discussion.

 

 

So - Unless you guys want to kick me off the site, I would like to go back to my problem and skip further investigation into background speculations.

 

I was actually getting somewhere with jcbones

 

Yours,

 Less than a newbie.. please don't be hatin

Link to comment
Share on other sites

Currently playing with this

- For ignace -  the source is: https://garethpoole.com/sending-post-api-php/

 

I'm pretty sure my last comment about the file type is exactly the problem.

$url = 'http://webservice.local/data.json';
$data = array("name" => "Gareth", "email" => "gareth@mail.com");
$response = sendPostData($url, $data);

function sendPostData($url, $post){
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
 return curl_exec($ch);
}
Link to comment
Share on other sites

So basically what you guys are all seemingly upset about is not having access to the actual API.

Which is my client's product.

 

The site rules don't state I have to provide actual code to get assistance.

In fact, just the opposite.. the rules state content will never be deleted and cautions about posting information for all to see.

 

Sounds like I'm in a catch 22.

 

I'm pretty close to figuring it out based on the information I received before all of the hijacks.

 

I'll keep trying to be self-sufficient for other 'students' to potentially benefit from.

 

Hopefully, my immature and painful path to get to where I need to be, will end in a solution that someone else can use.

Based on what I'm seeing, odds are that path will likely result in me finding some sort of less organized, and much younger php forum and I can cut and paste the resolution here.   :(

 

Then again, maybe somebody who is well rested will read this.. with a desire to help teach.. instead of a desire to do it themselves and mark the post as solved..

Edited by JTapp
Link to comment
Share on other sites

::)

 

The fact remains that we can't adequately help you process an API if we don't know the API.  If you can't divulge that information because of a NDA (whether explicit or not), so be it.

 

But, really, the API should have documentation that you can follow, or, barring that, a real life person you can ask.

 

Until you're able to provide relevant information, we cannot help you.  It's not a matter of intent, but rather a lack of sufficient information.  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.