Jump to content

micky007

Members
  • Posts

    33
  • Joined

  • Last visited

Everything posted by micky007

  1. Its ok guys, this can be marked as resolved. I've decided to re-code my work to make it better. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); $json = curl_exec( $ch ); curl_close( $ch ); $api_result = json_decode( $json, true ); $ua_type = $api_result[ 'device' ][ 'type' ]; $os_name = $api_result[ 'os' ][ 'family' ]; $os_version = $api_result[ 'os' ][ 'name' ]; $browser_name = $api_result[ 'browser' ][ 'name' ]; $browser_version = $api_result[ 'browser' ][ 'version' ]; $ua_brand = $api_result[ 'device' ][ 'brand' ]; $ua_name = $api_result[ 'device' ][ 'name' ];
  2. Hi Guys, One of my API providers has recently updated the way they output data in JSON to the following: { "ua":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko\/20100101 Firefox\/65.0", "type":"browser", "brand":null, "name":null, "url":"https:\/\/www.mozilla.org\/", "os":{ "name":"Windows 10", "code":"windows_10", "url":"https:\/\/en.wikipedia.org\/wiki\/Windows_10", "family":"Windows", "family_code":"windows", "family_vendor":"Microsoft Corporation.", "icon":"https:\/\/assets.userstack.com\/icon\/os\/windows10.png", "icon_large":"https:\/\/assets.userstack.com\/icon\/os\/windows10_big.png" }, "device":{ "is_mobile_device":false, "type":"desktop", "brand":null, "brand_code":null, "brand_url":null, "name":null }, "browser":{ "name":"Firefox", "version":"65.0", "version_major":"65", "engine":"Gecko" }, "crawler":{ "is_crawler":false, "category":null, "last_seen":null } } Previous the JSON data was not nested which means i now need to update my code to grab the values, I cant work out how to grab nested values, below is my code working off the old JSON output. How do i go about grabbing the data now with the new format? $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "URL-REMOVED"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $apiresult = json_decode($result); foreach($apiresult as $result) { $ua_type = $result->ua_type; $os_name = $result->os_name; $os_version = $result->os_version; $browser_name = $result->browser_name; $browser_version = $result->browser_version; $ua_brand = $result->ua_brand; $ua_name = $result->ua_name; }
  3. Thanks for the helps guys, much appreicated.
  4. Hi Guys, I have a question, is it possible to leave an ELSE statement open within an Include file and end the ELSE statement later in the main page? For example: <?php include 'PHP/db.php'; //include database info include 'PHP/login-top.php'; //include PHP code for Login functions info ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="CSS/login.css"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <form class="form-signin" method="POST"> <?php if(isset($fmsg)){ ?> <div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div> <?php } ?> <h2 class="form-signin-heading">Please Login</h2> <div class="input-group"> <span class="input-group-addon" id="basic-addon1">@</span> <input type="text" name="Email" class="form-control" placeholder="Email" required> </div> <label for="inputPassword" class="sr-only">Password</label> <input type="password" name="Password" id="inputPassword" class="form-control" placeholder="Password" required> <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button> <a class="btn btn-lg btn-primary btn-block" href="register.php">Register</a> </form> </body> </html> <?php } ?> At the moment I'm getting the following error: But the } on line 46 is the closing of the ELSE { part within login-top.php include file. If i take all the code out of the include file (login-top.php) and place it in the same file as login.php it all works fine. But my aim to try and make the pages less cluttered and more easy to edit the design/HTML side of things which is why im placing the important PHP code in seperate files and including them when they need to be included. Any help would be great, and thank you!
  5. Hey CPD, I'm still new to PHP and not an expert at it, so this JOINs thing is new to me & not sure what it is. I've just updated the server to the newest PHP and added MySQLi. I've now changed my code for it to work with MySQLi but now nothing is working. All its doing now is just echoing "ISP Checks completed!". <?php require("./databaseconnection.php"); //Get Database Login Information //Do ISP Check $mysqli = new mysqli(localhost,$username,$password, $database); $result = mysqli_query($link, "SELECT * FROM `leads` WHERE `IPCheck` = 'NO'"); $numberrows=mysqli_num_rows($result); echo $numberrows; while($row = mysqli_fetch_array($result)) { $ipcountry=$row['IPCountry']; $ipcc=$row['IPCC']; $ipisp=$row['IPISP']; $leadid=$row['LeadID']; $ProgramID=$row['ProgramID']; //Get Valid Consumer ISP $result2 = mysqli_query($link2, "SELECT * FROM `ValidISP` WHERE `ISP` = '$ipisp'"); echo $link2."<br/>"; $count=mysqli_num_rows($result2); echo $count."<br/>"; var_dump($result2); echo "<br />"; if($count==1){ while($row2 = mysqli_fetch_array($result2)) { $validisp=$row2['ISP']; $validispstatus=$row2['Status']; } }else { $validispstatus="MANUALCHECK"; } //End if ( $validispstatus == "PASS" ) { mysqli_query($link3, "UPDATE leads SET IPCheck='PASS' WHERE LeadID='$leadid'"); } elseif ( $validispstatus == "FAIL" ) { mysqli_query($link4, "UPDATE leads SET IPCheck='FAIL' WHERE LeadID='$leadid'"); } else { mysqli_query($link5, "UPDATE leads SET IPCheck='MANUAL' WHERE LeadID='$leadid'"); } } mysqli_close(); //End echo "ISP Checks completed!"; ?> I'm really stuck as i dont know whats wrong. What im trying to do is "SELECT * FROM `leads` WHERE `IPCheck` = 'NO'". I need it then to grab the value of the column called IPISP and also the column called LeadID of each record that matches the Query. While it grabs the data of each record i then need it do perform the following: "SELECT * FROM `ValidISP` WHERE `ISP` = '$ipisp'" - $ipisp is the data it has just got from a record from the column IPISP. I need it then to count how many rows come up from that query. If theres 1 row (there should really only be 1 or 0 rows) then i need it to grab the data from the above query from the column Status If theres 0 rows then i need $validispstatus set as MANUAL I then need the below code to be ran, im sure you can work out what im trying to do from the code: if ( $validispstatus == "PASS" ) { mysqli_query($link3, "UPDATE leads SET IPCheck='PASS' WHERE LeadID='$leadid'"); } elseif ( $validispstatus == "FAIL" ) { mysqli_query($link4, "UPDATE leads SET IPCheck='FAIL' WHERE LeadID='$leadid'"); } else { mysqli_query($link5, "UPDATE leads SET IPCheck='MANUAL' WHERE LeadID='$leadid'"); } Do you understand fully what im trying to do here? Help would be much appreciated please. Thank you!
  6. Hi Guys, My count is echoing the $count variable as 0 when it should be 1. When i run the MySQL Query myself in PHPMYADMIN it returns a row. So why when i echo $count is it showing as 0? Any help would be great. Thanks in advance! <?php require("./databaseconnection.php"); //Get Database Login Information //Do ISP Check mysql_connect(localhost,$username,$password) or die(mysql_error()); @mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified."); $query = "SELECT * FROM `leads` WHERE `IPCheck` = 'NO'"; $result=mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $ipcountry=$row['IPCountry']; $ipcc=$row['IPCC']; $ipisp=$row['IPISP']; $leadid=$row['LeadID']; $ProgramID=$row['ProgramID']; //Get Valid Consumer ISP $query2 = "SELECT * FROM `ValidISP` WHERE `ISP` = '$ipisp'"; $result2=mysql_query($query2); echo $query2."<br/>"; $count=mysql_num_rows($result2); echo $count."<br/>"; var_dump($result2); echo "<br />"; if($count==1){ while($row2 = mysql_fetch_array($result2)) { $validisp=$row2['ISP']; $validispstatus=$row2['Status']; } }else { $validispstatus="MANUALCHECK"; } //End if ( $validispstatus == "PASS" ) { $query3 = "UPDATE leads SET IPCheck='PASS' WHERE LeadID='$leadid'"; mysql_query($query3); } elseif ( $validispstatus == "FAIL" ) { $query3 = "UPDATE leads SET IPCheck='FAIL' WHERE LeadID='$leadid'"; mysql_query($query3); } else { $query3 = "UPDATE leads SET IPCheck='MANUAL' WHERE LeadID='$leadid'"; mysql_query($query3); } } mysql_close(); //End echo "ISP Checks completed!"; ?> As you can see if used var_dump($result2); and thats echoing this out "resource(4) of type (mysql result)" I've no idea why its showing that as when i run the Query in PHPMYADMIN it displays a row of data. See the images below. Example: WHEN I TRY IT IN PHPMYADMIN IT RETURNS A ROW: Any help would be great please.
  7. What im trying to do is get how many characters there are in the variable called postcode. If theres 6 characters then it will echo the code. If theres 7 characters then it will echo different code. The script also removes any spaces in the data that the variable holds. Thanks.
  8. Hi Guys, I've managed to code what i need it do to but i have an issue, below is my code: $postcode=$_GET['postcode']; function countchar ($string) { $resultpostcode = strlen ($string) - substr_count($string, ' '); echo $resultpostcode; } countchar ($postcode); if ( $resultpostcode == 6 ) { echo "Postcode1 "; echo substr($postcode, 0, 3); echo "<br>"; echo "Postcode2 "; echo substr($postcode, 3); } elseif( $resultpostcode == 7 ){ echo "Postcode1 "; echo substr($postcode, 0, 4); echo "<br>"; echo "Postcode2 "; echo substr($postcode, 4); }else { echo "error"; } If the value of postcoderesult is 6 (it even outputs 6) then it wont echo what it should be doing, the same if its 7. It just keeps echoing Error. Any help would be great please. Thank you.
×
×
  • 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.