i have a script which i took from this link
http://tareq.wedevs.com/2009/05/playing-with-twitter-json-using-php/
the script is below
<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/SaswatRoutroy.json?count=10", true);
$decode = json_decode($json, true);
echo "<pre>";
$count = count($decode); //counting the number of status
for($i=0;$i<$count;$i++)
{
echo $decode[$i]."<br>";
}
echo "</pre>";
?>
it throws me the error
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(http://twitter.com/status/user_timeline/SaswatRoutroy.json?count=10) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
Filename: views/recipy_detail.php
Line Number: 116
can anybody solve this for me
It looks to me like that URL is throwing a 404, and file_get_contents is accurately throwing an error.
Could you try replacing the URL with one that returns a successful JSON request.
You can see response to in your browser to URL http://twitter.com/status/user_timeline/SaswatRoutroy.json?count=10
{"errors":[{"message":"Sorry, that page does not exist","code":34}]}
User with username SaswatRoutroy is suspended now.
Twitter API was changed. You can get new documentation by URL
Related
I am using Symfony 3.0.4. I have the error
[2016-05-20 08:50:26] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occured in driver: SQLSTATE[HY000] [2002] No route to host" at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 103 {"exception":"[object] (Doctrine\\DBAL\\Exception\\ConnectionException(code: 0): An exception occured in driver: SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103, Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []
[2016-05-20 08:50:26] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
This is strange because the indexAction is working perfectly, only the Edit Action is NOTWorking, on all of my edit routes. There have been no changes in the code to cause this to happen.
What have I inadvertantly changed in my MySQL configuration that allows Doctrine to find everything on the indexAction but then error out on the editAction?
EDIT
Forgive me.... The code is below. It works in my local environment. It does not work in prod. The error above comes from the prod.log.
In addition the indexAction controller works as well.
/**
* Displays a form to edit an existing AOD Technical Analysis page entity.
*
* #Route("/{id}/edit", name="aod_technical_analysis_edit")
* #Method({"GET", "POST"})
*/
public function editAction(Request $request, AodTechnicalAnalysis $aod_tech)
{
$deleteForm = $this->createDeleteForm($aod_tech);
$editForm = $this->createForm('AppBundle\Form\AodTechnicalAnalysisType', $aod_tech);
$editForm->remove('currencypair');
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($aod_tech);
$em->flush();
$session = $request->getSession();
$message = 'The change was succesfully saved for ' . $aod_tech->getCurrencypair();
$session->getFlashBag()->add('success', $message);
return $this->redirectToRoute('aod_technical_analysis_index');
}
return $this->render('aod_tech/edit.html.twig', array(
'aod_tech' => $aod_tech,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
Have you tried appending "app_dev.php" on your URL to get the debug web toolbar? I have found this to be more helpful compared to logs. You might need to edit the "web/app_dev.php" to add your browser's IP address.
Warning: mysql_connect(): (HY000/2002): Connection refused in
/home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line
7
Warning: mysql_select_db(): No such file or directory in
/home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line
8
Warning: mysql_select_db(): A link to the server could not be
established in
/home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line
8
I have the below code
<?php
$localhost="localhost";
$username=b31_16461744;
$pass=test123;
$dbname=b31_16461744_user;
$a= mysqli_connect($localhost,$user,$pass);
mysql_select_db($dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!";
}
?>
Sidenote: Assuming the credentials are correct, given to you by your web host.
There are several problems with this code (taken from a comment you left).
Firstly, three of your declarations are not quoted and are being treated as constants.
PHP error reporting would have thrown notices of undefined constants.
These are treated as constants:
$username=b31_16461744;
$pass=test123;
$dbname=b31_16461744_user;
You are also referencing the wrong variable for the username being $user which should be $username. Error reporting would have signabled an undefined variable notice.
Then you're mixing mysql_ with mysqli_ syntax. Those different MySQL APIs do NOT intermix. You must use the same one throughout your code.
Sidenote: The other question you posted Access denied for user 'test123'#'192.168.0.38' (using password: NO) you are using sql306.byethost31.com for the host. Make sure that is correct. I have no idea what settings that host wants you to use.
<?php
$localhost="localhost";
$username="b31_16461744";
$pass="test123";
$dbname="b31_16461744_user";
$a= mysqli_connect($localhost, $username, $pass);
mysqli_select_db($a, $dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!";
}
?>
or just use all four parameters:
<?php
$localhost="localhost";
$username="b31_16461744";
$pass="test123";
$dbname="b31_16461744_user";
$a= mysqli_connect($localhost, $username, $pass, $dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!" . mysqli_error($a);
}
?>
However, your else with the echo does not help you. Use mysqli_error() to get the real error.
I.e.: or die("Error " . mysqli_error($a));
Example from the manual
$link = mysqli_connect("myhost","myuser","mypassw","mydb")
or die("Error " . mysqli_error($link));
References:
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/mysqli.error.php
http://php.net/manual/en/function.mysqli-connect.php
http://php.net/manual/en/language.constants.php
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Displaying errors should only be done in staging, and never production
I Think Credentials are not correctly set. See Your connection statement.
For Reference :
While Working On Localhost, We write connection statement as :
$con=mysql_connect("localhost","root","");
$db1=mysql_select_db("DatabaseName",$con);
But, While working on server, we need to change the following credential.
Username and password values are must.
$con=mysql_connect("localhost","Username","password");
$db1=mysql_select_db("DatabaseName",$con);
I am using phpMailer for sending bulk email, Some of emails are bouncing, How I get Hard Bounced email ids.
I am new in PHP, I found in some websites i will get responses like
500 - The server could not recognize the command due to a syntax error.
501 - A syntax error was encountered in command arguments.
502 - This command is not implemented.
503 - The server has encountered a bad sequence of commands.
504 - A command parameter is not implemented.
550 - The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).
551 - The recipient is not local to the server. The server then gives a forward address to try.
552 - The action was aborted due to exceeded storage allocation.
553 - The command was aborted because the mailbox name is invalid.
554 - The transaction failed. Blame it on the weather.
but I didnt fount any where how I get this response?
When you run "Send()" method you may check "ErrorInfo" property:
$mail = new PHPMailer();
...
if(!$mail->Send())
{
echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
or
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
...
try
{
...
$mail->Send();
}
catch (phpmailerException $e)
{
echo $e->errorMessage(); // Error messages from PHPMailer
}
catch (Exception $e)
{
echo $e->getMessage(); // Something else
}
I'm using tastypie with django. I have one line of code:
data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))
I use this code from the command line to send a post request to my webserver:
curl -X post -d "{ 'username' : 'user', 'password' : 'password' }" http://127.0.0.1:8000/api/employee/login/ --header "Content-Type:application/json"
When I run this, it results in a json response of
{"error": ""}
Looking at my server logs I see:
[15/Feb/2014 20:39:49] "post /api/user/login/ HTTP/1.1" 400 13
A log message logged immediately before the deserialize line will be logged successfully, but a log message logged immediately after the deserialize line will not be logged, so I am pretty sure the deserialize is wrong. Does anyone know what could be wrong or if I should consider something else as the problem?
Your JSON is not valid. Please check it here. The 400 (bad request) status should give you clue about that. It should be: {"username": "user", "password": "password"}. Here you have some solutions how to escape " char in CURL command. Tastypie unfortunately raises exception without message here but we can easily fix that for future to save time for other people which will use your API.
from tastypie.exceptions import BadRequest
from tastypie.serializers import Serializer
class VerboseSerializer(Serializer):
"""
Gives message when loading JSON fails.
"""
# Tastypie>=0.9.6,<=0.11.0
def from_json(self, content):
"""
Override method of `Serializer.from_json`. Adds exception message when loading JSON fails.
"""
try:
return json.loads(content)
except ValueError as e:
raise BadRequest(u"Incorrect JSON format: Reason: \"{}\" (See www.json.org for more info.)".format(e.message))
class MyResource(BaseModelResource):
class Meta:
serializer = VerboseSerializer(formats=['json'])
I have a problem, I'm using this project to use of base on my project. I tryied to get the same result of the guys project, and used the same project to test in my SQL.
I done the "index.php" works, and when I click "Save Route" it send a mensage "Updated", so, when I open "loady.htm" it give that error : "SintaxError: Unexpected Token < "
I used the same code, but changed the local host on process.php and the account and password.
But this is the unique change.
What's wrong on load.htm ? Or its an error on teste.php, I cant load the waypoints in "loady.htm"
Links for test:
www.inventoresdegaragem.com/dbteste/index.htm
and
www.inventoresdegaragem.com/dbteste/loady.htm
Edit 2: This is my process.php
<? ob_start(); header('Cache-Control: no-store, no-cache, must-revalidate');
#$data = $_REQUEST['*******'];
$host = 'localhost';
$usuario = '******';
$banco = '******';
$senha = '******';
$db = mysql_connect($host, $usuario, $senha);
mysql_select_db($banco, $db);
if($_REQUEST['command']=='save')
{
$query = "update mapdir set value='$data'";
if(mysql_query($query))die('bien');
//die(mysql_error());
}
if($_REQUEST['command']=='fetch')
{
$query = "select value from mapdir";
if(!($res = mysql_query($query)));
$rs = mysql_fetch_array($res,1);
die($rs['value']);
}
?>
Your process.php cannot connect to your database.
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'http' (1) in /home/i/inventoresdegara/www/dbteste/process.php on line 10
It would appear that your current live version of process.php does not have localhost specified as the server. Note that it should be just a server name and should not include the protocol:
$host = 'localhost';
$host = 'www.mydomainnamehere.com';
(or whatever domain name you want to use) and not
$host = 'http://www.mydomainnamehere.com';
I believe the error is occurring because the database error message I've reproduced above is formatted as HTML and starts with <:
<br />
<b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Unknown MySQL server host 'http' (1) in <b>/home/i/inventoresdegara/www/dbteste/process.php</b> on line <b>10</b><br />
The html on your "after" page is not valid
looks like jax.responseText is empty.