|
In the PHP documentation[^] it actually quotes:
php.net wrote: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Two solutions:
- Have it (the header) at the top of the page before you output anything to the browser.
- Use Output Buffering[^] to hold the output before it is sent to the browser.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
One other option is to echo a document.write to add a javascript redirect..its a bit of a hack, but works....provided someone does not turn off js in their browser.
|
|
|
|
|
You can run stuffs before that but make sure you dont echo anything else before giving this redirect. For e.g. validation of usernames, or anything which should be done before any HTML tags or echo is done..
- Jay.
|
|
|
|
|
Hello !
I want to hire a coder for my site. I am making a site of family trees for everyone. For that I need a coder. Anyone interested in please leave a message.
Thank you!
|
|
|
|
|
Don't give up do you?
Re-read what you have previously been told in other threads in this forum and the Collaboration forum. And stop asking the same question as the answer will not change.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
I know what I got ; no one will make it for you better to hire.
RIGHT ?
And I am paying for that not getting free .....
modified on Sunday, November 7, 2010 6:05 PM
|
|
|
|
|
Try Freelancer websites please.
The best I know is vworker.com. You will surely find many coders looking for such opportunities. Its not that we dont welcome being paid, but just this website is not meant for that.
Thanks.
- Jay.
|
|
|
|
|
what's your budget mate ?
|
|
|
|
|
I'm trying to create a php file that always returns a json as response. The problem is, it looks like it's returning a valid JSON, but jquery.ajax always says "invalid json." I copied and pasted the response and stuck it in jsonlint.com and it says it's valid json.
Can anyone point out what I'm doing wrong here? Why can't jquery (and other json parser) parse this even it's a valid json?
header('Content-type: application/json');
include("database.php");
require_once "../lib/JSON.php";
$json = new Services_JSON();
$method = strtolower($_SERVER['REQUEST_METHOD']);
$value = array();
$DB = new DBConnect();
$DB->NewConnection("localhost", "db_name", "db_role", "db_pw" );
if ($method == "get"){
$value = getEmployees();
}
else if ($method == "post"){
}
else if ($method == "put"){
}
else {
echo "Error - unknown http request method";
}
echo $_GET['callback'] . '(' . $json->encode($value) . ');';
|
|
|
|
|
It seems that everything is fine. Probably, the code segment is going on the last else statement, and so, it prints an invalid Json line there.
Try debugging that particular location, and you probably would be able to find it.
|
|
|
|
|
what is the response?
what does firebug say?
|
|
|
|
|
Hi all,
Is there any script for converting a PDF file to HTML in php ?
Thanks in advance.
|
|
|
|
|
|
You have posted the same question on 4 different forums; please, don't do it!
The best when asking something is to choose the forum that better matches your subject, and post a unique question explaining as better as possible what is your problem.
Thank you!
|
|
|
|
|
You'd better put your fireproof overalls on right now. Posting the same question in multiple forums (where the question doesn't fit in any of them) is only going to get you flamed out of here.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I think it's time they started a Powershell forum
|
|
|
|
|
Hi
Thanks in advance for helping me. I have this mySQL query that fails i have no idea why i. Below is the code I left some space for readability
$lines=file("somefile5640.001");
$headerTable=explodeX(Array(",","\n"),$lines[0]);
$table ="HeaderRecord";
WriteArrayToHeaderDatabase($headerTable,$table);
function WriteArrayToHeaderDatabase($headerTable,$table)//Pass which table am i writing to
{
//I do the connecting to database here which is fine the problem is below
$query = "INSERT INTO ".$table."(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES";
for($i = 0, $c = count($headerTable); $i < $c; $i += 6) {
// Add the next batch of values to the query string
$query.= "('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
//$query .= "(".$headerTable[$i].",".$headerTable[$i+1].",".$headerTable[$i+2].",".$headerTable[$i+3].",".$headerTable[$i+4].",".$headerTable[$i+5].")";
echo "Query is failing";
// Add a comma is this is not the last batch
if($i + 1 < $c) {
//$query .= "";
$query .=",";
}
echo $query;
$result = mysql_query($query);
if (!$result) {
die('Query failed: ' . mysql_error());
}
}
return true;
// When i echo the query and run the code i get what shown below
Query is failingINSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 '),Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
|
|
|
|
|
Firstly, let me state that I'm no MYSQL expert. However, assuming the the INSERT INTO query works in the same way as it does in SQL Server, your problem is that you are trying to create multiple records using a single INSERT INTO query. You can only add one record at a time.
|
|
|
|
|
Yes and no, MySql supports multiple inserts in one query just like was coded in the example.
That being said PHP does not support multiple queries in one mysql_query call, as is documented on PHP documentation.
|
|
|
|
|
Thanks for the response. I am trying to create one record but the query is repeated more than once. I don't know where in my code do i repeat the query.
|
|
|
|
|
The problem is in your for loop. You start building up your insert just above it and then append the values in the loop. This might not seem like a problem, but when you look at what it does it is something like this:
q="insert into blaat(col1, col2) values"
Run 1:
q="insert into blaat(col1, col2) values('1','2'),"
mysql_query($q)
Run 2:
q="insert into blaat(col1, col2) values('1','2'),('3','4'),"
mysql_query($q)
Run 3:
q="insert into blaat(col1, col2) values('1','2'),('3','4'),('5','6'),"
mysql_query($q)
So the problem is probably two things. First you are appending to the q variable every time you loop through the for. This type of insert will work in a console MySQL client app, but I doubt that PHP supports it. Then there is a second issue with this, inside the loop you are running the mysql_query. So every single time you loop you are running the query over and over again.
The second issue is that you instantly add the ',' in the for loop. Since $i + 1 < $c is valid as soon as there is even one row to be inserted.
|
|
|
|
|
I honestly do not understand why it has to run(iterate) more than once as $i += 6 will make $i < $c false just after a single iteration. I'm pulling my hair here, i really need this sorted as in yersterday.
|
|
|
|
|
First of you don't know (or at least I don't know) how many sets of 6 are in the array. But lets presume one set of 6, so 6 entries.
The loop will only run once, so your statement is true. However inside the loop (before the loop increments) you have that check to append the ','. Since the for loop only increases $i by 6 as it reaches its closing bracket the if statement inside the loop will always be true, don't forget that $i is stil 0 at this point.
|
|
|
|
|
It's not easy to read, but it looks like the problem is a trailing comma in your query. Your loop adds 6 to $i with each iteration, but the test for adding a comma checks if $i + 1 < $c . This should be a 6 instead of a 1.
|
|
|
|
|
I have used used loops to make a multiple insert query like above but form a tad different. I suspect the issue is in the query contruction itself.
Also why are you reassigning the $c variable with every loop of the for? This will slow down your code.
I guess the $headerTable is an single diminsional array? Currious why you did not use a multi-diminsional array...?
It looks like you are skipping 6 rows at a time...so looking at your error message if the values are all of the correct type (they are all varchar or similar?) then it looks like there maybe a second row starting
...
VALUES('SOF','1','1500','19970519','112904','1 '),
...
note the comma on the end there.
also
...
MySQL server version for the right syntax to use near ''
...
I suspect you may have a extra line of data in the array with an empty row sent to your function
Can you post the $query when you echo it? You should be able to copy and past it into the mysql admin tool, phpmyadmin, or other system that will let you run the query inside the tool. although I suspect you will see the same error.
btw I would write this function like this...
<?php
WriteArrayToHeaderDatabase($headerTable,$table);
function WriteArrayToHeaderDatabase($headerTable,$table)
{
$query = "INSERT INTO ".$table."(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES";
$c = count($headerTable);
echo "headerTable Count = ".$c;
for($i = 0; $i < $c; $i += 6)
{
if($i==0)
{
$query.= "('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
}
else
{
$query.= ", ('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
}
echo $query;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
}
return true;
}
?>
this will run faster and is easier to read. It will also tell you how many rows are in the array sent to your variable.
|
|
|
|
|