PHP - Nginx Return Empty Data, While Header Is 200 Ok
I have a problem with my rest service as below:
Similar TutorialsHere's the code that deals with the client side:
<?php session_start(); if(!isset($_SESSION['Logged_in'])){ header("Location: /page.php?page=login"); } ?> <!DOCTYPE Html> <html> <head> <!--Connections made and head included--> <?php require_once("../INC/head.php"); ?> <?php require_once("../Scripts/DB/connect.php"); ?> <!--Asynchronously Return User Names--> <script> $(document).ready(function(){ function search(){ var textboxvalue = $('input[name=search]').val(); $.ajax( { type: "GET", url: 'search.php', data: {Search: textboxvalue}, success: function(result) { $("#results").html(result); } }); }; </script> </head> <body> <div id="header-wrapper"> <?php include_once("../INC/nav2.php"); ?> </div> <div id="content"> <h1 style="color: red; text-align: center;">Member Directory</h1> <form onsubmit="search()"> <label for="search">Search for User:</label> <input type="text" size="70px" id="search" name="search"> </form> <a href="index.php?do=">Show All Users</a>|<a href="index.php?do=ONLINE">Show All Online Users</a> <div id="results"> <!--Results will be returned HERE!--> </div>search.php <?php //testing if data is sent ok echo "<h1>Hello</h1><br>" . $_GET['search']; ?>This is the link I get after sending foo. http://www.family-li...php?&search=foo Is that mean it was sent, but I'm not processing it correctly? I'm new to the whole AJAX thing. I have this working script below. I never managed to turn it into a function... I think it's because there's classes in it.
I stopped that investigation and instead I choose to:- keep it on another page, trigger it with the a <form> button, then return to the form page using header location. This is probably much more elaborate than it needs to be... but it seems to be working fine.
I'd like to print out "email sent" if successful. The collection of confusion at the end of this script, is me trying to get it to return the - "email sent" message <index.php> <?php require 'includes/PHPMailer.php'; require 'includes/SMTP.php'; require 'includes/Exception.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = "true"; $mail->SMTPSecure = "tls"; $mail->Port = "587"; $mail->Username = "email@gmail.com"; $mail->Password = "pass"; $mail->Subject = "Test email using PhPmailer"; $mail->setFrom("email@gmail.com"); $mail->isHTML(true); //$mail->addAttachment('img/movie.mp4'); $mail->Body = "<h1>This is a HTML heading</h1></br><p>This is a html title</p>"; $mail->addAddress("email@gmail.com"); if ($mail->Send() ) { echo "Email sent..!"; } else{ echo "Error..!"; } $mail->smtpClose(); ob_start(); $Message = urlencode("Email Sent"); header("Location:EmailBut.html?Message=".$Message); die; ob_flush(); ?> The stuff at the beginning of this next script is me trying to get it to print out email sent. I can get it to return the message in the URL but it won't print out. <EmailBut.html> <?php ob_start(); if(isset($_GET['Message'])){ echo $_GET['Message']; } echo $_GET['Message']; ob_flush(); ?> <html> <body> <form action="index.php" method="POST"> <button type="submit">Send</button> </form> </body> </html> Can you please give me a push in the right direct here? Edited January 30, 2020 by JonnyDrillerI have a while loop in a script that is running for a very long time due to the large values that are passing through it. Below is the link to the pastebin code and code embedded in this forum. Loop Statement Snipet if (!$user_class->invincible) { if (!$defender->invincible) { while ($yourhp > 0 && $theirhp > 0) { $damage = round($defender->moddedstrength) - $user_class->moddeddefense; $damage = ($damage < 1) ? 1 : $damage; if (!$wait) { $yourhp = $yourhp - $damage; ++$number; $log[] = $number . ": " . $defender->formattedname . " hit you for " . prettynum($damage) . " damage using their " . $defender->weaponname . ". <br />"; } else $wait = 0; if ($yourhp > 0) { $damage = round($user_class->moddedstrength) - $defender->moddeddefense; $damage = ($damage < 1) ? 1 : $damage; $theirhp = $theirhp - $damage; ++$number; $log[] = $number . ": " . "You hit " . $defender->formattedname . " for " . prettynum($damage) . " damage using your " . $user_class->weaponname . ". <br />"; } } $log = array_slice($log, -10, 10, true); foreach($log as $text) echo $text; } else $yourhp = 0; } else $theirhp = 0;
My issue is that $yourhp and $theirhp can be in the 100's of thousands causing this to loop half a million plus times. I was curious if there was a way to only show the first few lines and last few lines of this but still retain the increment value that's created? Thanks so much in advance. NICON Hi guys, im trying to connect to a database and get the value for the user in the row called 'user_credit', if it equals 1 or more then i want to show the ''You have £ ....'' bit in the script. Problem is nothing shows at all, even without the if statement. I have changed the value for me in the database so in user_credit the value is 100, which is more than 1 so it should appear. I have probably done something wrong. Any ideas? Code: [Select] <? include '../admin/database/membership_dbc.php'; $r = mysql_query("SELECT * FROM users WHERE user_name='".safe($_SESSION['user_name'])."'") or die ("Cannot find table"); while( $cred = mysql_fetch_array($r) ) { if ($cred >= '1' ) { ?> <p>You have £<? echo $cred['user_credit']; ?> available on you account, would you like to use it on this order?<br> <label for="credit"></label> <select name="credit" id="credit"> <option value="Y" selected>Yes, use credit</option> <option value="N">No, save credit</option> </select> </p> <? } } ?> Hello, Curious to know if someone could point me in the right direction, been struggling with this for a bit now. I have a HTML page with a search field, I can enter a search term and hit the submit button and I am directed to my search.php page with the appropriate results. What I am looking to accomplish is having the search results from the search.php page displayed in a text area below my search field in my HTML page. I have included an image to better describe what I am looking to accomplish: Additionally below is the source from my HTML page and search.php page: page.html <form name="search" action='search.php' method="post"> <input type="text" class="myinputstyle" name="search" value="search" onClick="this.value=''"/><br> <input type="submit" value="submit" class="myinputstyle"> </form> search.php <?php $search = "%" . $_POST["search"] . "%"; mysql_connect ("localhost", "game_over", "Ge7Ooc9uPiedee3oos9xoh4th"); mysql_select_db ("game_over"); $query = "SELECT * FROM game_over WHERE first_name LIKE '$search'"; $result = mysql_query ($query); if ($result) { while ($row = mysql_fetch_array ($result)) { echo "Name: {$row['name']} " . "{$row['lname']} <br>" . "Email: {$row['email]} <br>" . } } ?> Any insight would be most appreciated. Thank you. Here is something i dreamt up, i know there is a way for this to work, but i'm not having any great ideas at this point. I want to be able to auto increment through the $_POST[] array data sent from a PayPal IPN. Sample return data looks like item_number1=val item_name1=val so on and so forth. The idea is: While there are $_POST item_numbers, do something with it. The loop continues until there are no more item_numbers. I don't want to use the static methods eg: explicitly defining item_number1, item_number2, ect. This is what i thought would work, but keeps failing -> the script doesn't enter the first condition: $x = 1; // set the initial item number while(isset($_POST['item_number$x'])){ $qty = $_POST['quantity$x']; while($qty > 0){ // step through each item response result, setting each item to paid $package_id = $_POST['item_number$x']; update_paid_status($transaction_id, $package_id); $qty--; } $x++; } Any Ideas? Hi, For about a month, I have been trying to figure out why my code will not return anything after posting a wwwForm (I have also tried the newer equivalent of this function but I had no luck with that either.) The nameField and passwordField are taken from text boxes within the game and the code used in my login script is copied and pasted from a Register script but I have changed the file location to the login.php file. The register script works fine and I can add new users to my database but the login script only outputs "Form Sent." and not the "present" that should return when the form is returned and it never gets any further than that point meaning that it lets the user through with no consequence if they use an invalid name because the script never returns an answer. What should I do to fix this? Thanks, Unity Code: using System.Collections; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; public class Login : MonoBehaviour { public InputField nameField; public InputField passwordField; public Button acceptSubmissionButton; public void CallLogInCoroutine() { StartCoroutine(LogIn()); } IEnumerator LogIn() { WWWForm form = new WWWForm(); form.AddField("username", nameField.text); form.AddField("password", passwordField.text); WWW www = new WWW("http://localhost/sqlconnect/login.php", form); Debug.Log("Form Sent."); yield return www; Debug.Log("Present"); if (www.text[0] == '0') { Debug.Log("Present2"); DatabaseManager.username = nameField.text; DatabaseManager.score = int.Parse(www.text.Split('\t')[1]); Debug.Log("Log In Success."); } else { Debug.Log("User Login Failed. Error #" + www.text); } } public void Validation() { acceptSubmissionButton.interactable = nameField.text.Length >= 7 && passwordField.text.Length >= 8; } } login.php: <?php echo "Test String2"; $con = mysqli_connect('localhost', 'root', 'root', 'computer science coursework'); // check for successful connection. if (mysqli_connect_errno()) { echo "1: Connection failed"; // Error code #1 - connection failed. exit(); } $username = mysqli_escape_string($con, $_POST["username"]); $usernameClean = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); $password = $_POST["password"]; if($username != $usernameClean) { echo "7: Illegal Username, Potential SQL Injection Query. Access Denied."; exit(); } // check for if the name already exists. $namecheckquery = "SELECT username, salt, hash, score FROM players WHERE username='" . $usernameClean . "';"; $namecheck = mysqli_query($con, $namecheckquery) or die("2: Name check query failed"); // Error code # 2 - name check query failed. if (mysqli_num_rows($namecheck) != 1) { echo "5: No User With Your Log In Details Were Found Or More Than One User With Your Log In Details Were Found"; // Error code #5 - other than 1 user found with login details exit(); } // get login info from query $existinginfo = mysqli_fetch_assoc($namecheck); $salt = $existinginfo["salt"]; $hash = $existinginfo["hash"]; $loginhash = crypt($password, $salt); if ($hash != $loginhash) { echo "6: Incorrect Password"; // error code #6 - password does not hash to match table exit; } echo "Test String2"; echo"0\t" . $existinginfo["score"]; ?>
Ok so i'm not a programmer of any kind however I'm trying to enter what I believe is HTML generated metadata into the header.php of my wordpress theme here is how the wordpress header reads ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head profile="http://gmpg.org/xfn/11"> <title><?php if ( is_single() ) { single_post_title(); } elseif ( is_home() || is_front_page() ) { bloginfo('name'); print ' | '; bloginfo('description'); get_page_number(); } elseif ( is_page() ) { single_post_title(''); } elseif ( is_search() ) { bloginfo('name'); print ' | Search results for ' . wp_specialchars($s); get_page_number(); } elseif ( is_404() ) { bloginfo('name'); print ' | Not Found'; } else { bloginfo('name'); wp_title('|'); get_page_number(); } ?></title> <meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> AND HERE IS WHAT I WANT TO PLACE I just don't know where I put it. It gives me Syntax errors when I paste just above the last title tag....does it need to be in php form and if so how do i change it? thanks for anyones help, sorry if this is a lame question but I've been slapping my head against a wall for 4 hours now Page: http://www.dylanpatrickarts.com/ <title>NYC Headshots, Lifestyle Portraits, Corporate, PR, Live Music</title> <meta name="description" content="Providing quality affordable NYC Headshots to the working actor, as well as Lifestyle Photography, Corporate Photography, Public Relations Photography, and much more! I strive to push my creative potential at all times, while having fun doing it!"> <meta name="keywords" content="photography,wedding photography,headshots,headshot,actors headshot,headshots nyc,nyc headshots,new york city headshot photography,headshot photographers in new york city,portraits,portrait,portrait photographer,hospitality photography,live music photography,public relations photography"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/headshots/ <title>NYC Headshots</title> <meta name="description" content="A collection of NYC Headshots for actors, dancers, and models"> <meta name="keywords" content="headshots,headshot,good headshots examples,actors headshots,actors headshot,headshots nyc,nyc headshots,new york city headshot photography,headshot photographers in new york city,new york headshots,actors,headshot photography,headshot photography in nyc,affordable headshots,affordable headshots nyc"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/ <title>Portfolio</title> <meta name="description" content="A collection of NYC Headshots, People Photography, Live Music Photography, Scenic Photography, and Public Relations Photography, as well as a gallery for you to buy prints!"> <meta name="keywords" content="headshots,actors headshots,actors headshot,headshots nyc,headshot photographers in nyc,portrait photography,abstract photography,scenic stock photography,live music photography,music photography,hospitality photography,hotel photography,public relations,cocktail photography,buy print photography"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/people/ <title>People</title> <meta name="description" content="A collection of Portraits, Candids, and Outtakes"> <meta name="keywords" content="people photography,people stock photography,black white photography of people,portrait photography,family portrait photography,headshots,headshot,actors headshot,actors headshots,photographers in new york city,new york city corporate photographer,headshot photographers in new york city,dylan,candids"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/live-music/ <title>Live Music</title> <meta name="description" content="A collection of Live Music work in NYC"> <meta name="keywords" content="music photography,photography,live music photography,live music nyc,new york city live rock music,bleecker street"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/pr-work/ <title>PR Work</title> <meta name="description" content="A collection of public relations and hospitality work. "> <meta name="keywords" content="public relations,public relations photography,hospitality,hospitality photography,cocktails,cocktail,dylan,bentley,clients,empire"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/tear-sheets/ <title>Tear Sheets</title> <meta name="description" content="A collection of published work"> <meta name="keywords" content="tear sheets,photography,actors headshots,actors headshot,headshot,headshots,headshots nyc,nyc headshots"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/scenic-artistic/ <title>Scenic & Artistic</title> <meta name="description" content="A collection of scenic and artistic work. Certain photos also available for purchase!"> <meta name="keywords" content="scenic stock photography,scenic photography,scenic photography for sale,abstract photography,artistic photography,hdr photography,hdr photography galleries,examples of hdr photography,scenic,new york city,new york city skyline,san francisco,idaho"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/galleries/buy-prints/ <title>Buy Prints</title> <meta name="description" content="A collection of available prints for purchase."> <meta name="keywords" content="web site shopping cart,shopping cart,buy photography,buy scenic photography"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/your-shoot/ <title>Your Shoot</title> <meta name="description" content="Details about your headshot session."> <meta name="keywords" content="headshots nyc,nyc headshots,headshots,headshot,actors headshots,actors headshot,information,clients,consultation,dylan,people,portfolio,testimonials"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/pricing/ <title>Pricing</title> <meta name="description" content="Pricing information for headshot sessions"> <meta name="keywords" content="headshot pricing,pricing information,nyc headshots,headshots,headshot,actors headshot,photography prices,digital photography prices,prices for photography,headshot photography prices,nyc headshot photography prices,wardrobe,session"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/testimonials/ <title>Testimonials</title> <meta name="description" content="Testimonials from some of my wonderful clients!"> <meta name="keywords" content="testimonials,testimonial,photographer testimonials,headshots,headshot,actors headshots,actors headshot,headshot photographers in nyc,headshot photography in nyc,nyc headshot photographers,headshots nyc,nyc headshots,photographer,dylan,amazing"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/resources/ <title>Resources</title> <meta name="description" content="A few links to photographers, and some cool places"> <meta name="keywords" content="photography links,headshots,headshot,actors headshot,actors headshots,headshot photographers in nyc,nyc headshot photographers,acting schools links,the empire hotel,the empire hotel new york"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/blog/ <title>Blog</title> <meta name="description" content="Official Blog for Dylan Patrick Photography"> <meta name="keywords" content="blog,photography blogs,blogs on photography,photography,portraits,portrait,portrait photographer,portrait photographers,headshot photographers in nyc,headshot photographers in new york city,nyc headshot photographers,headshots nyc,nyc headshots,headshots,headshot"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/about/ <title>About Dylan</title> <meta name="description" content="A short bio about Dylan Patrick"> <meta name="keywords" content="nyc headshots,dylan patrick arts,dylan patrick photography,headshot photographers in nyc,headshot photographers in new york city,nyc headshot photographers,headshot,headshots,actors headshot,actors headshots"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/contact/ <title>Contact</title> <meta name="description" content="Contact information for Dylan Patrick"> <meta name="keywords" content="contact info,headshot photographers in nyc,headshot photographers in new york city,nyc headshot photographers,portraits,portrait,portrait photographers"> ==================================================================================================================== Page: http://www.dylanpatrickarts.com/shopping-cart/ <title>Shopping Cart</title> <meta name="description" content="Your Shopping Cart"> <meta name="keywords" content="web site shopping cart,shopping cart,buy photography,buy scenic photography"> Hello all. Here is my script... Code: [Select] if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "<br></h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); echo "<br>"; echo $headers; } $handle = fopen($_FILES['filename']['tmp_name'], "r"); $header = fgetcsv($handle); while(! feof($handle)){ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into CSVtest($header[0],$header[1],$header[2],$header[3],$header[4]) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')"; mysql_query($import) or die(mysql_error()); } } fclose($handle); echo "Done"; } This is the way how I insert data into database according to header even it's not arranged same as the table column. If the csv has only "cell,firstname,lastname,," (and my table has only these 3 columns as well) then it still working...but if there are "cell,address,company,firstname,lastname" then it will show me unknown column error. Actually I wish to have a function that even there are many columns in csv that not exist in the table it still can just pick the right column and insert into table. Can anyone give me hints on how to change my script?I know there are many errors...it's really embarrassed to show my low standard script... Thanks in advance. Hi.. I have query for insert then I just want to add condition that after it save it will locate on the previous page: here is my code: Code: [Select] $sql = "INSERT INTO receiving_materials (sr_date, sr_number, si_num, s_name, po_num, qty, mat_code, mat_desc, wh_code, bin_loc) VALUES ('$sr_date', '$sr_number', '$si_num', '$s_name', '$po_num', '$qty', '$mat_code', '$mat_desc', '$wh_code', '$bin_loc') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', si_num = '$si_num', s_name = '$s_name', po_num = '$po_num', qty = '$qty', mat_code = '$mat_code', mat_desc = '$mat_desc', wh_code = 'wh_code', bin_loc = '$bin_loc'"; $res_receiving = mysql_query($sql, $con) or die(mysql_error()); Thank you Greetings... I have been staring at my whiteboard pondering a new architecture for processing data in an application. New for me anyways. I want to create a more centralized and modular method of handling data. For ease of explanation I will put it into the context of a login system which is where I first started thinking about this. I know there are a lot of login systems out there but I wanted to create one from scratch which utilizes PDO although that specific thing is not germane to my main question. Here we go... Lets say that for my Registration, Login and Forgot Password pages the forms on each page were directed to "Process.php" The idea is that process.php will provide the centralized platform to deal with data, acting as a choke point in the application making it easier to secure. This will also provide the means to quickly develop new parts of an application knowing that my methods of dealing with data area already well defined and secure. There is one hole in the idea that I can see though. If the user data being submitted to the process.php page does not meet the security requirements then the user must be sent back to the previous page. I dont' want to lose the data they have already entered into the forms. ie. I want to have it appear in the form fields... makes sense right. Now here comes my question... is there a way to pass POST data when using header("location: http://mySite/previousPage.php") It seems from my experiments that the data is lost. I do not use header(); often. In previous designs I have usually created each part of a login system as seperate and self contained entities apart from using a common db object. I know there are other ways around this, using session data for instance but this idea has been eating away at me for a little while and I feel its time to ask around for some advice. It has become a matter of curiosity. I have found some info on sending POST data using header but it did not seem to meet the requirement that the user and the POST data be sent to another page synchronously. At first I thought that maybe I would just do validation on the frontend / view pages (not to be taken as clientside) and if it was valid, then submit it to process.php, validate it again the let it be handled appropriately to its particular end but then I run into the same problem plus there is the extra overhead of validating the data twice. I guess thats it for now. Sorry if that was a little long-winded... its part of my process, helps me to better understand what I really want to know. Using header() on a receiving page from a form page... the redirecting header() with POST data, sending the user to a new/previous page. Possible? Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. Code: [Select] // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; } What I am looking for is that if any field in a database is empty, the form comes back and puts in the word "empty" into the web page, but not the database. I got this right now, it shows the first part fine, but the second part it doesn't show the "Empty" comment... I don't understand why... as far as I can tell the code is fine... Code: [Select] <?php //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box3">'; if (!empty($row['Nonconformity']) || !empty($row['Disposition']) || !empty($row['Comments']) || !empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />' . $row['Nonconformity'] . '</div>'; echo '<div id="dis"><span class="b">Disposition: </span><br />' . $row['Disposition'] . '</div>'; echo '<div id="comm"><span class="b">Comments: </span><br />' . $row['Comments'] . '</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />' . $row['CommentsAdditional_Details'] . '</div>';} else if (empty($row['Nonconformity']) || empty($row['Disposition']) || empty($row['Comments']) || empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />Empty</div>'; echo '<div id="dis"><span class="b">Disposition: <br /></span>Empty</div>'; echo '<div id="comm"><span class="b">Comments: <br /></span>Empty</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />Empty</div>';} echo '</div>'; ?> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=350027.0 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: Code: [Select] <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: Code: [Select] <?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. I don't get the logic behind the construct. I can't ever see myself using this because it doesn't make sense when I code it. I understand isset($var) and why I should use it sometimes to avoid undefined messages. But with empty() it makes more sense to always test the variable directly because if the value is NULL, 0, '', or false then it evaluates as TRUE. Is there any situation where empty should be used always? Hi everyone! I'm new to PHP and needed from you. I have the following code that I can't figure out why it doesn't work on the last elseif. If I comment out the first elseif (line 19-39), it does go through the last elseif. Can someone here help? Thank you!!! The content of Instructors.txt as follow: ID#|fName lName|email_address|course1:course2:course3 ID#|fName lName|email_address|course1:course3 ID#|fName lName|email_address|course1:course2:course4 ID#|fName lName|email_address|course2:course3:course5:course6 <?php //If we submitted the form if(empty($_POST['Location'])) { $FH = fopen("Locations.txt", "rb"); print "<FORM name=\"myForm\" action=\"test4.php\" method=\"POST\">\n"; print "<P> Location:\n"; print "<select name=\"Location\">\n"; print "<option value=\"\">-- Select --\n"; while (!feof($FH)){ $line_of_text = fgets($FH); $line = explode('|', $line_of_text); print "<option value=$line[1]>$line[1]"; } fclose($FH); print "<input type=\"submit\" value=\" Next 1 \">\n"; exit(); } elseif(empty($_POST['Instructor'])) { $location = ($_POST['Location']); $FH = fopen("Instructors.txt", "rb"); print "<FORM name=\"myForm\" action=\"test4.php\" method=\"POST\">\n"; print "<P> Location: <input type=text value=$location>\n"; print "<P> Instructor: \n"; print "<select name=\"Instructor\">\n"; print "<option value=\"\">-- Select --\n"; while (!feof($FH)){ $line_of_text = fgets($FH); $line = explode('|', $line_of_text); if ($line[0] == "$location") { print "<option value=\"$line[1]\">$line[1]\n"; } } fclose($FH); print "<input type=\"submit\" value=\" Next 2 \">\n"; exit(); } elseif(empty($_POST['Course'])) { $location = ($_POST['Location']); $instructor = ($_POST['Instructor']); $FH = fopen("Instructors.txt", "rb"); print "<FORM name=\"myForm\" action=\"test4.php\" method=\"POST\">\n"; print "<P> Location: <input type=text value=$location>\n"; print "<P> Instructor: <input type=text value=\"$instructor\">\n"; print "<P> Course: \n"; print "<select name=\"Course\">\n"; print "<option value=\"\">-- Select --\n"; while (!feof($FH)){ $line_of_text = fgets($FH); $line = explode('|', $line_of_text); if ($line[1] == "Bert Vandenber") { $course = explode(':', $line[3]); for ($i=0; $i<count($course); $i++) { print "<option value=\"$course[$i]\">$course[$i]\n"; } } } fclose($FH); print "<input type=\"submit\" value=\" Next 3 \">\n"; exit(); } ?> I have search page in the form of search.php?q=query, as the php script calls for other files and a long process. When visiting search.php directly, the value of q is indeed null, and it makes a long loop and use lots of cpu. How to kill the script or redirect to the main page when visiting search.php? i have made query and i want replace with no data N/A i have tryed with swich but no luck Code: [Select] if (($row['name']) = empty) { echo('n/a'); } I'm not sure what i have done wrong here... all it says is "Query was empty" <?php SESSION_START(); ?> //some html <?php if($_SESSION['email']){ $mysql = "SELECT id,firstname FROM users WHERE 'id'='".$_SESSION['email']."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ session_destroy(); echo"Please <a href=\"/index.html\">Login</a> or <a href=\"/register.php\">Join Us.</a>"; }else{ $row = mysql_fetch_assoc($res); echo "welcome back, <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['firstname']."</a>\n"; } }else { echo"Please <a href=\"/index.html\">Login</a> or <a href=\"/register.php\">Join Us.</a>"; } ?> |