I keep getting this error and I cannot figure it out. My curly brackets are closed, and I am using the correct tags for <?php to open and ?> to close my code. Can someone please help me!
Here is my code: -
<?php
-
//Connect To Database
-
$hostname='mideasthonors2.db.4381361.hostedresource.com';
-
$username='**************';
-
$password='***********';
-
$dbname='mideasthonors2';
-
$usertable='admin_tasks';
-
$yourfield = 'Name';
-
-
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
-
mysql_select_db($dbname);
-
-
$query = 'SELECT * FROM $usertable';
-
$result = mysql_query($query);
-
if($result) {
-
while($row = mysql_fetch_array($result)){
-
$name = $row['$yourfield'];
-
echo 'Name: '.$name;
-
-
mysql_select_db("mideasthonors2");
-
-
$sql="INSERT INTO $usertable (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)
-
-
VALUES
-
-
{$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']};
-
-
if (!mysql_query($sql,$con))
-
-
{
-
-
die('Error: ' . mysql_error());
-
-
}
-
-
echo '1 record added';
-
-
mysql_close($con);
-
}
-
}
-
?>
Jun 23 '09
68 10746
There must be some trailing spaces or output before. Make sure you dont have a blank line at the top ie:
It has to be: You cannot have any spaces or any output before you use a header() call.
Please paste the entire contents of your code. ALso admin-dbcon.php but remove any sensitive information like passwords, etc.
In fact attach the files so we can see where the output is being generated.
Code from adminloginprocess.php: -
<?php
-
include("admin-dbcon.php");
-
-
// you need this to be able to use sessions
-
session_start();
-
-
//sanitize the user input to ensure random usernames cannot be used
-
$sUsername= mysql_real_escape_string($_POST['Username']);
-
$sPassword = mysql_real_escape_string($_POST['Password']);
-
-
//ensure username and password are valide
-
$qry = mysql_query("
-
SELECT * from admin_login
-
WHERE = username = '$sUsername'
-
AND password = '$sPassword'
-
");
-
-
// check the number of rows returned
-
if(mysql_num_rows($qry) == 1)
-
{
-
// not a valid login redirect to fail
-
header("Location: login-error.php");
-
exit;
-
}
-
-
// if you get here then you have made a match
-
// store data in session variables
-
$row = mysql_fetch_array($qry);
-
$_SESSION['username'] = $row['username'];
-
$_SESSION['userid'] = $row['ID'];
-
-
// redirect user onto admintasks.php
-
header("Location: admintasks.php");
-
?>
-
**No spaces are shown
admin-dbcon.php: -
<?php
-
$dbHost = 'mideasthonors.db.4381361.hostedresource.com';
-
$dbName = 'xxx';
-
$dbUser = 'xxx;
-
$dbPass = 'xxx';
-
-
mysql_connect("$dbHost","$dbUser","$dbPass") or die("Error: Unable to connect to database! Please try again later.");
-
-
//Select the database we want to use
-
mysql_select_db($dbName) or die("Error: Could not select database");
-
?>
-
make sure that "admin-dbcon.php" does not have any echo or print statements in it. Then delete the closing php bracket (the ?> at the bottom.
if this file does need to output something, then session_start() should come before that include line.
Dan
Make sure there are no spaces at the bottom. Seems like you have an extra line underneath where you close PHP ie. ?> on both scripts.
Atli 5,058
Expert 4TB
If you can't spot where the output is being sent, try adding ob_start() at the very top of your script (before any includes), and ob_end_flush() at the very bottom (or at least after you header calls).
Those should buffer any output until you are ready to send it.
You can use them to narrow down exactly where the problem is.
Thank you all for your suggestions. I have applied all of them and here is my code for adminloginprocess.php: -
<?php
-
ob_start()
-
include("admin-dbcon.php");
-
-
// you need this to be able to use sessions
-
session_start();
-
-
//sanitize the user input to ensure random usernames cannot be used
-
$sUsername= mysql_real_escape_string($_POST['Username']);
-
$sPassword = mysql_real_escape_string($_POST['Password']);
-
-
//ensure username and password are valide
-
$qry = mysql_query("
-
SELECT * from admin_login
-
WHERE = username = '$sUsername'
-
AND password = '$sPassword'
-
");
-
-
// check the number of rows returned
-
if(mysql_num_rows($qry) == 0)
-
{
-
-
// not a valid login redirect to fail
-
header("Location: login-error.php");
-
exit;
-
}
-
-
// if you get here then you have made a match
-
// store data in session variables
-
$row = mysql_fetch_array($qry);
-
$_SESSION['username'] = $row['username'];
-
$_SESSION['userid'] = $row['ID'];
-
// redirect user onto admintasks.php
-
header("Location: admintasks.php");
-
ob_end_flush()
-
?>
-
And my code for admin-db.com.php: -
<?php
-
$dbHost = 'mideasthonors.db.4381361.hostedresource.com';
-
$dbName = 'xxx';
-
$dbUser = 'xxx';
-
$dbPass = 'xxx';
-
-
mysql_connect("$dbHost","$dbUser","$dbPass") or die("Error: Unable to connect to database! Please try again later.");
-
-
//Select the database we want to use
-
mysql_select_db($dbName) or die("Error: Could not select database");
-
***Although it appears on here that I have spaces after my last line...it is not true. My ?> on adminloginprocess.php is the very LAST line of my scripting, no other lines appear after it. I am using SharePoint Designer, not sure if that has anything to do with it.
After all of the suggestions from yesterday this is now the error I am receiving:
Parse error: syntax error, unexpected T_INCLUDE in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 3
which has to do with the db-con.php file. However one can see that the db-con.php file has been set up properly, except that I deleted the ?> as suggested by one of you yesterday. I am assuming that if I replaced that I would still be taken to a blank page. I am not really sure what steps to follow next:(
Your missing semi-colons after:
ob_start() and ob_end_flush()
Make sure they are: - ob_end_flush(); and ob_start();
@hoopy: cheater ;)
.......
Sorry guys,
but that is not the problem. I added the semi-colons and I am still getting this error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 6
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 20
Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginprocess.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginprocess.php on line 24
This is my code: -
<?php
-
ob_start();
-
include("admin-dbcon.php");
-
-
// you need this to be able to use sessions
-
session_start();
-
-
//sanitize the user input to ensure random usernames cannot be used
-
$sUsername= mysql_real_escape_string($_POST['Username']);
-
$sPassword = mysql_real_escape_string($_POST['Password']);
-
-
//ensure username and password are valide
-
$qry = mysql_query("
-
SELECT * from admin_login
-
WHERE = username = '$sUsername'
-
AND password = '$sPassword'
-
");
-
-
// check the number of rows returned
-
if(mysql_num_rows($qry) == 0)
-
{
-
-
// not a valid login redirect to fail
-
header("Location: login-error.php");
-
exit;
-
}
-
-
// if you get here then you have made a match
-
// store data in session variables
-
$row = mysql_fetch_array($qry);
-
$_SESSION['username'] = $row['username'];
-
$_SESSION['userid'] = $row['ID'];
-
// redirect user onto admintasks.php
-
header("Location: admintasks.php");
-
ob_end_flush();
-
?>
-
@mideastgirl
mysql_query() returns false if there was an error, which then obviously is not a resource.
remember: always test values that can have different data types and where the data type matters in the next usage.
refer also to mysql_query().
typical example (very basic): - $qry = mysql_query($sql) or die(mysql_error());
Atli 5,058
Expert 4TB @mideastgirl
Since you now have ob_start() on your second line, before the include, it is clear that the output that is preventing you from setting the headers is being added before the <?php on line #1.
There simply is no other explanation for this error. There is something being sent before the <?php on line #1. To fix this, you need to find out what it is and remove it.
A white-space, some hidden unicode marker... something.
P.S.
SharePoint Designer... isn't that just FrontPage for Vista? Does it even support PHP? (Meaning, color highlighting, syntax error highlighter, and such.)
In any case, if you are having a hard time finding the problem in that, try opening your file in Notepad++. It's very good at spotting trash characters and such.
Atli,
I have opened the document in Notepad ++ and some of the characters are in color, like semi-colons and such. However I do not know how to identify which characters are trash. Are the one's in color trash? Not really sure. I am going to mess with it more and hopefully figure it out.
Dormilich,
Are you suggesting, as is the link you sent me, that I need to use mysql_query() to see if the resource (variable/password?) I am using is a variable at all? Little confused on what that means. I kind of gathered that I need to go into my database and ensure that the password is entered as VARCHAR as opposed to anything else???? Let me know if I am on the right track.
@mideastgirl
first, every variable in PHP conforms to a data type (this type is not necessarily always the same—PHP is a so-called dynamically typed lanuage [ref.]) (that's got nothing to do with password, etc.). further, every (strictly speaking) function in PHP returns a value (this can be any of the alredy mentioned data types or "void" (no return value)). since even we experts do not know this stuff from all the 2,000+ PHP function we can look them up in the manual, where in the beginning a description is given what variables you must provide (minimum parameter number along with their type) and what the function returns (in which case).
example (how to read the manual*)
Description - resource mysql_query ( string $query [, resource $link_identifier ] )
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .
Parameters
this means, you must provide a SQL sting as input and optionally the connection (resource) variable. you'll get a resultset (a resource type) return value (except otherwise stated in the "return values" section). optional parameters are set in square brackets ( [ ] )
query
A SQL query
The query string should not end with a semicolon.
link_identifier
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.
the description what each of the input parameters is.
Return Values
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.
Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
as you can see, the mysql_query() function usually returns a ressource type (variable). but when reading under "return values" you'll see that this is not the only option, mysql_query() in general returns FALSE if there was an error (that is common for many functions) and sometimes it may return TRUE (both are boolean data types. and if your next function expects a resource input data type, it won't let you away if you provide a boolean (or any other)
* this is important as most errors can be explained at/tracked down to this level
will show you the content AND data type of the variable of interest (this is one of the #1 debugging functions)
you should also cross-read at wikipedia about programming languages, there are some basic termini (like "data type" or "return value") that make discussing bugs and programmes much easier.
Atli 5,058
Expert 4TB @mideastgirl
No, Notepad++ highlights the syntax in color so it is easier to read.
Junk characters usually show up as black squares. They are hidden, so this is just how Notepad++ (and a lot of other editors) represent them.
Pay close attention to the starting <?php tag. The rest isn't really important.
There must be something before it. A space, a piece of HTML, a junk char... anything.
If there is not, check the Format menu. If the Encode as UTF8 is selected, change it to the one above it: Encode as UTF8 without BOM.
Normal UTF8 documents have leading identifier chars that cause the problem you are seeing.
Thanks so much for sharing the post.
<link removed: no unnecessary links, thanks>
I think she may have finally figured it out :D
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Janwillem Borleffs |
last post by:
Q: I'm getting an unexpected $ or $end parse/syntax error, what's causing
this?
A: This is caused when an expression is started with an opening...
|
by: Wescotte |
last post by:
The error message Parse error: syntax error, unexpected $end in FILE on
line X is one I run into frequently and I know the cause is I missed an...
|
by: mikeinspain |
last post by:
Keep getting this error!
Parse error: syntax error, unexpected $end in /home/9144/domains/cbweb.co.uk/html/faq_finance.php on line 139
PHP...
|
by: kestrel |
last post by:
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is...
|
by: praclarush |
last post by:
I've just started php, and this is a class assignment, but my question is I’m getting this error PHP Parse error: syntax error, unexpected T_IF,...
|
by: ajd335 |
last post by:
Hi all...
I am getting an error Parse error: syntax error, unexpected $end in http:/..... on line 117...(117 is the EOF)..
can you plz help me...
|
by: Lawrence Krubner |
last post by:
Imagine a template system that works by getting a file, as a string, and
then putting it through eval(), something like this:
$formAsString...
|
by: fburn |
last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux.
I receive an error:
Parse error: syntax error, unexpected...
|
by: akohistani |
last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below
Parse error: syntax...
|
by: benicio |
last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19
I got this error and...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| | |