JTapp Posted February 1, 2014 Share Posted February 1, 2014 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'); }?> Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/ Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 I guess I need to rename the topic header. Apologies Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467397 Share on other sites More sharing options...
mac_gyver Posted February 2, 2014 Share Posted February 2, 2014 not only that, we can only help you with code problems AFTER you have attempted to do something and you provide a statement of the symptom or error you got from that code. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467398 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 This wasn't my first choice. Been here before and know that. I joined Lynda.com and sat through 3 courses trying to find an answer on how to attempt this. At this point in time, all I'm asking for is a resource. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467400 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 Searching for a needle in a haystack… currently chasing down: $apiParamsUrl= any guidance would be greatly appreciated thx Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467403 Share on other sites More sharing options...
KevinM1 Posted February 2, 2014 Share Posted February 2, 2014 Maybe you should give us more detail, since we're not sitting in the room with you, like: Are you trying to build your own API? Access an existing API? Have you looked into cURL? Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467404 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467407 Share on other sites More sharing options...
mac_gyver Posted February 2, 2014 Share Posted February 2, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467409 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467412 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 I found in the notes that I have to define a parameter in the URI…. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467413 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 I pasted in the following and it is hanging up in a major way <?php $result = file_get_contents('what I think is the file name'); echo $result; ?> Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467414 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 $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); Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467415 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 nope that didn't work either Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467418 Share on other sites More sharing options...
jcbones Posted February 2, 2014 Share Posted February 2, 2014 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467421 Share on other sites More sharing options...
ignace Posted February 2, 2014 Share Posted February 2, 2014 (edited) $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 February 2, 2014 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467427 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 ignace - I have no idea what you are talking about when you say you've been lied to. You are extremely off base. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467438 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467441 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 Is there any chance that since the file type I am trying to access is a .MODE file that it is rejecting the connection? Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467442 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 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); } Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467443 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 OK I ditched the last post and I think I'm onto something with $file = fopen I'm now in search of how to add parameters to it Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467446 Share on other sites More sharing options...
Ch0cu3r Posted February 2, 2014 Share Posted February 2, 2014 We cannot help you if you do not provide information on the API you are trying to use. Maybe you should ask your work colleage for this information. Spamming this thread with random bits of code which you obviously have no idea what they do is not helping your situation. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467447 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 The data contains proprietary code. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467448 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 oops - the code contains proprietary data Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467449 Share on other sites More sharing options...
JTapp Posted February 2, 2014 Author Share Posted February 2, 2014 (edited) 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 February 2, 2014 by JTapp Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467451 Share on other sites More sharing options...
KevinM1 Posted February 2, 2014 Share Posted February 2, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/285873-crap-ive-been-asked-to-change-my-php-its-been-working-for-years/#findComment-1467455 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.