.chester Posted April 24, 2012 Share Posted April 24, 2012 Hello everyone, I'm just starting out with PHP as I need to create an online bookstore for a school project. I'm working by a magazine which should teach you exactly how to do this using PHP, but I've had a bunch of problems with the code they use and I don't really know what's going on. Anyway, this looks really simple and basically what it does is allows you to post a comment on a book, then returns you to the book's page. Problem is, I'm getting the Header may not contain more than a single header, new line detected. error and I can't figure out why. I've tried researching into the matter but all the cases I found had to do with returning to an url, which is not my case. Anyway, here's the snippet of code: The form: <div style="width:400px; border:1px solid #ffffff; background-color:#F9F1E7; padding:5px"> <b>Adauga opinia ta:</b> <hr size="1"> <form action="adauga_comentariu.php" method="POST"> Nume: <input type="text" name="nume_utilizator"><br><br> Email: <input type="text" name="adresa_email"><br><br> Comentariu: <br> <textarea name="comentariu" cols="45"></textarea><br><br> <input type="hidden" name="id_carte" value="<?=id_carte?>"> <center><input type="submit" value="Adauga"</center> </form> </div> The script adaugare_comentariu.php: <?php ob_start(); include("conectare.php"); $numeFaraTags=strip_tags($_POST['nume_utilizator']); $emailFaraTags=strip_tags($_POST['adresa_email']); $comentariuFaraTags=strip_tags($_POST['comentariu']); $sql="insert into comentarii (id_carte, nume_utilizator, adresa_email, comentariu) values(".$_POST['id_carte'].", '".$numeFaraTags."','".$emailFaraTags."','".$comentariuFaraTags."')"; mysql_query($sql); $inapoi="carte.php?id_carte=".$_POST['id_carte']; header("location:urldecode($inapoi)"); ob_end_flush(); ?> conectare.php connects to the mysql database. $inapoi is the variable which returns the user to carte.php (the book he posted a comment on), where id_carte is the book's unique id. I'm getting Header may not contain more than a single header, new line detected on line ten, which is the header line. Can anyone help me? I've been stumped on this for a few days now and I've just let it pass and started working on other bits, but it's bugging me too much and I'd like to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/261537-header-may-not-contain-more-than-a-single-header-new-line-detected/ Share on other sites More sharing options...
trq Posted April 24, 2012 Share Posted April 24, 2012 The variable $inapoi likely contains a newline char, you cannot put a newline in a header via php. Also, I'm not sure what your trying to do with urldecode within your header call. A location header should be a complete and absolute url. This includes the hostname. eg; header("Location: http://somedomain.com/foo/bar"); Quote Link to comment https://forums.phpfreaks.com/topic/261537-header-may-not-contain-more-than-a-single-header-new-line-detected/#findComment-1340146 Share on other sites More sharing options...
.chester Posted April 24, 2012 Author Share Posted April 24, 2012 Is the newline char inside the carte.php file which is referred to in the $inapoi variable? Should I post carte.php too? And if that doesn't work, is there any other way around this? Could I perhaps return the user to the book they just commented on in some other way? Quote Link to comment https://forums.phpfreaks.com/topic/261537-header-may-not-contain-more-than-a-single-header-new-line-detected/#findComment-1340150 Share on other sites More sharing options...
trq Posted April 24, 2012 Share Posted April 24, 2012 The new line is within the string within $inapoi. Quote Link to comment https://forums.phpfreaks.com/topic/261537-header-may-not-contain-more-than-a-single-header-new-line-detected/#findComment-1340221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.