Getting parse error in php - php

For some reasons I am getting parse error on the last line of the file even it is blank. I've used connect.php file as a connection file for putting the comment into the database. I'm using wampserver as a local server & coded all by myself

It must be some thing did not closed properly , like { or some line ending left post your php file for give proper solution

Related

PHP Syntax - Connecting to Database

I created a database through an online site and would like to connect to it from my android Activity. I believe that the core issue is my PHP file. I keep getting a syntax error from this line of code:
$con = mysqli_connect('h31.170.234.43', “markf”, “boston”, “a9208078_mydb”);
The name of my file is Register.php and the error is:
Parse error: syntax error, unexpected T_VARIABLE in /home/a9208078/public_html/Register.php on line 2
First, I'm curious if my parameters are correct, Host Name, the username that I used for that site, my password, and the database name?
Does anyone know why this error is occuring? Thanks so much!
PS: I changed the information around from my actual password and database name for obvious security reasons but the idea is the same
You're using funky quotes around three parameter values. That's what happens when you copy and paste your code from a blog post or tutorial.
$con = mysqli_connect('h31.170.234.43', 'markf', 'boston', 'a9208078_mydb');
FYI, your IP address is invalid and probably also a copy and paste error or typo.

PHP file upload error: undefined index

I'm trying to upload a file to my server or just open it and handle the contents but I get this strange error and I don't know why.
HTML form: http://pastebin.com/cSfMmvKF
php script: http://pastebin.com/fPzRVy5Y
If I try to test if the file is received I get a false response. Example:
if (isset($_FILES['epifile']))
echo 'Is set';
This evaluates as false. I'm pretty sure everything is quite correct so I have no idea where the error comes from. Can you guys help?
Edit: I'm running this with XAMPP on my own PC. Could it be some setting that I need to enable within Apache?
Your form must have an enctype="multipart/form-data" attribute.

PHP script works on one server, gives me an Internal Server Error 500 on another [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
PHP call class in class returns error:500
I have code that looks somewhat like this:
<?php
include 'payTable.php';
session_start();
...
if ($_SESSION['fieldTen'] > 30)
{
$payTable = 'payTable';
$payTable::run();
}
?>
My permissions are set to 0644, so I don't think that's the issue, but I'm getting strange behavior on the server that I'm not getting in the local directory using XAMP.
Every time I try to load the page with this code on it, I get the "Internal Server Error: 500" error.
Can anyone tell me if there's something obviously wrong here? Something I'm missing.
I tried simply removing the PHP from this file and that causes the HTML part of it to appear without problems.
This is not legal syntax on PHP < 5.3.0, so you're getting a syntax error:
$payTable = 'payTable';
$payTable::run();
PHP (< 5.3.0) thinks $payTable is a string, so you can't use ::run() on it.
The solution would be just to ditch the variable altogether and call it directly:
payTable::run();
On a related note, turn on your error reporting. This will allow you to spot and fix errors easily rather than being left in the dark with a generic error. You can do this by editing php.ini (preferred), or add this to the top of your scripts:
error_reporting(E_ALL);
ini_set("display_errors","On");
It looks like you are trying to call a function of 'payTable', but payTable is not a class with any functions.
Additionally, you could be trying to set the session after some data has been output... possibly from the included file? this will throw an error, but likely not as severe as a 500.
500 just means the server hit a problem and couldn't continue. You need to check the error log for the web server (presumably apache?) to see what the actual problem was. Looking at the code, off the cuff guess could be the case of the included filename doesn't match the actual filename.

How do I use require_once()?

I create a PHP page with the following content:
<?php session_start(); ?>
<?php require_once(./classes/MaterialUtil.class.php);
$mUtil = new MaterialUtil();
?>
I put the MaterialUtil.class.php file in D:\xampp\htdocs\drupal\sites\all\themes\zeropoint\classes, but I get the following error message:
Parse error: syntax error, unexpected '.' in D:\xampp\htdocs\drupal\modules\php\php.module(80) : eval()'d code on line 7
Could you please tell me what I do wrong?
The error is caused from the fact you didn't use a string for the filename, and PHP understood the dot as being the concatenation operator; as such, because there wasn't any value before the operator, PHP gave you an error saying it found the concatenation operator in the wrong place.
As kalabro said, the correct code is the following one:
<?php session_start(); ?>
<?php require_once('./classes/MaterialUtil.class.php');
$mUtil = new MaterialUtil();
?>
This is the part of the answer that is not strictly related to Drupal.
What you are doing is not what I would suggest to do, for two reasons:
You are putting the "classes" directory in the wrong place. Those files are not related to the theme being enabled, but they are related to the page being viewed. Even if you have a single theme, and users are not allowed to select a theme for themselves, it still wrong to put those files in a theme directory.
Putting the files in the directory containing a theme, which will needs to be updated when a new version is available, could cause you to lose the additional files you added, if you are not careful.
Executing PHP through eval() to, e.g., get content to show in a node is not something that you should do. This is because:
As you have used the PHP filter for the node, the node becomes only editable to a restricted group of users. (I would not suggest to allow untrusted users to use PHP as input format)
When you have PHP code that you need to execute, it is always better to create a custom module that is enabled for the site.
If you were trying to include a PHP file from inside a module, then you should use module_load_include(), instead of require_once(), as already suggested by marcvangend.
XAMP server does not run on windows file system format. You must write your file location like localhost/xyz/abc ..

Unbelievable PHP script won't echo out string

I have a test.php script which contains this:
<?php echo 'test'; ?>
When I point to it via my browser, it works and prints out "test" as expected.
I have another script which I am trying to test but however, it is ignoring all my echos! I thought I would put an echo right at the top as this will surely work, but when I get to this script via POST request from a form. It does not even echo out what is at the top of the line:
<?php echo 'START START START';
error_reporting(E_ALL);
I even point to from my browser and still no output?
What the hell is going on?
Update
The error log shows this :
PHP Parse error: syntax error, unexpected T_ECHO in /var/www/tester/convertor.php
But the echo is at the top of the line. I am going to set diaplay errors.
You have a parse error, so the script isn't even executed. So it's expected that it won't output anything.
The parse error can be for any echo in the script. It may be because of an "echo" statement after a line missing a semicolon, for example.
Things to try:
Check your error log
Check the headers (is it coming back 404?)
Make sure you view-source: don't just look in the browser
Delete everything except the echo. If it works, add things back a bit at a time until it breaks.
Load your script in a hex editor and make sure there aren't any weird characters in there
Are you including this file from another file? If so, check the other file too. Watch out for output buffering.
Put exit; after the echo start start start and see if that works. Look in the apache error log for clues. Comment out the rest of the PHP code in the file and see if it works then...
UPDATE
I have had this when copy pasting white space from a browser sometimes - e.g. copy/pasting some code from a web page. Sometimes weird control characters get embedded invisibly in the white space, and I find that deleting the whitespace and re-entering it fixes it. Did you copy paste anything into this file?
Are you hosting this page on a server with PHP installed?
If you just have a .php file on your hard drive somewhere and open it in a web browser, it won't work. You need to be running a web server with PHP extensions and access the file using the HTTP or HTTPS protocols.
On a similar note to this i have seen alot of scripts throw errors like this when they have come from developers on windows (i'm on linux).
I have to go to the start of the php file and hit delete a couple of times to get rid of some invisible characters before the script will run.
You're missing the ending ?>
<?php
echo 'START START START';
error_reporting(E_ALL);
?>

Categories