PHP - Need To Use Query String Variable In New If/else Statement
Hi,
My issue here is that I cant get my query string variables to ONLY feed into if/else statement on my secondary page. I include my secondary page (fine.php) from my index page. My query string variables keep being fed back into my original if/ese statement on index.php. here is the if/else on index.php (these links work fine): <?php if($_SERVER['QUERY_STRING']=='/index.php' || $_SERVER['QUERY_STRING']=='') { include 'port.php'; } elseif (isset($_GET['pos'])){ include 'pos.php'; } elseif (isset($_GET['web'])){ include 'web.php'; } elseif (isset($_GET['fine'])){ include 'fine.php'; } else {include '404.php';} here is the if/else on my secondary page (fine.php). These links are supposed to alert the if/else in the next table cell. However, they instead alert the if/else in index.php. <td><br/> <a href="?backset"><img src="fine/thumbs/x-backset.jpg" border="0"></a><br/><br/> <a href="?backside"><img src="fine/thumbs/x-backside.jpg" border="0"></a><br/><br/> <a href="?bannerprint"><img src="fine/thumbs/x-bannerprint.jpg" border="0"></a><br/><br/> <a href="?chopu"><img src="fine/thumbs/x-chopu.jpg" border="0"></a><br/><br/> </td> <td><br/> <div id="DivPiece" align="left"> <?PHP if (isset($_GET['backset'])){ include 'fine/backset.php'; } elseif (isset($_GET['backside'])){ include 'fine/backside.php'; } elseif (isset($_GET['bannerprint'])){ include 'fine/bannerprint.php'; } elseif (isset($_GET['chopu'])){ include 'fine/chopu.php'; } ?> </div> </td> How can I get the links on the secondary page to only alert the if/else statement on that page, and BLOCK the if/else statement on index.php from seeing them? I still want to use the query string though. Thanks! [/quote] Similar TutorialsHi there, im trying to have a form show up when user clicks "add joke". I need the variable to be retrieved from the url query string. I cant get the form to show up. I think its either an issue with the GET function at the top or the link down at the bottom. Please help! <?php // If the user wants to add a joke $_GET['addjoke'] = $addjoke; if (isset($addjoke)): ?> <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST> <P>Type your joke he <BR> <TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP> </TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT"> </FORM> <?php else: // Connect to the database server $dbcnx = @mysql_connect("servername", "username", "password"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } // Select the jokes database if (! @mysql_select_db("jhodara2") ) { echo( "<P>Unable to locate the joke " . "database at this time.</P>" ); exit(); } // If a joke has been submitted, // add it to the database. $joketext = $_POST['joketext']; $submitjoke = $_POST['submitjoke']; if ("SUBMIT" == $submitjoke) { $sql = "INSERT INTO jokes SET " . "JokeText='$joketext', " . "JokeDate=CURDATE()"; if (mysql_query($sql)) { echo("<P>Your joke has been added.</P>"); } else { echo("<P>Error adding submitted joke: " . mysql_error() . "</P>"); } } echo("<P> Here are all the jokes " . "in our database: </P>"); // Request the text of all the jokes $result = mysql_query( "SELECT JokeText FROM jokes"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } // Display the text of each joke in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("<P>" . $row["JokeText"] . "</P>"); } // When clicked, this link will load this page // with the joke submission form displayed. echo("<P><A HREF='$PHP_SELF?addjoke=1'>Add a Joke!</A></P>"); endif; ?> see the problem live at http://www.freewaycreative.com/insert2.php I am trying to pass in a $string variable into my query like so but it is returning a warning: Code: [Select] $string = "clientName == '$input'"; $input = "Sam"; $table_id = 'booking'; $query ="SELECT * FROM booking WHERE. '$string' "; $test = mysql_query($query); echo $test; Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick I need an if statement, but i have no idea how or if it can be done. If a text string is greater than 10 characters, {echo $string} else{ print $error } <?php $string = '1900800008'; $error = 'String isn't long enough'; if( ????????? ){echo $string} else{ print $error } ?> Hello again. I run a sports league website and registrations received after a certain date need to have their league fees calculated to add 10%. someone wrote this for me a couple of years ago, but I have since then lost the full code. Need to know how to add a date to the follow statement that would automatically add the 10%. Can someone look at this for me and fill me in on what's missing? Thanks! Code: [Select] /* * Calculate fees */ $intSize = intval($arrLeagueSearch['size']); switch($intSize) { case 2: $dblBase = 150.00; $intBSize = 3; break; case 4: $dblBase = 330.00; $intBSize = 6; break; case 6: $dblBase = 550.00; $intBSize = 10; break; default: die("Invalid league size"); }; $dblEarlyTeam = $dblBase; $dblEach = $dblEarlyTeam / $intPlayers; /* $dblLateTeam = $dblEarlyTeam * 1.10; $dblLateEach = $dblLateTeam / $intPlayers; */ I am trying to figure out how to have an if statement in the middle of strings I am trying to concatenate. I have a from that has a address1 and address2, where address2 often does not exist. So I want to only add that line if there is actually content. I was trying something like the following, but that is giving me an error. I am pretty new to php, so I can't seem figure it out. Any help would be greatly appreciated. Code: [Select] "<p><strong>Address 1: </strong><br>" . $address1 . "<br>" if ( isset($address2) ) { echo . $address2 . "<br>" } . $city . ", " . $state . " " . $zip . "</p>" Hi All, I'm working on PHP scripts to interact with a web hosted MySQL DB for an Android Application. Simply what I am trying to do is in the PHP script is run a SELECT statement which will return the value of a column, UserType, and compare the result of this to a string, which will then execute code depending on it's value. This user type can only be either 'student' or 'lecturer'. Any help with this would be much appreciated. <?php require "init.php"; $user = $_GET["userID"]; #Selects column account type where the idNum equals $user which is passed from my app. $sql1 = "select accountType from user_info where idNum = '$user'"; $result1 = mysqli_query($con,$sql1); $row1 = mysqli_fetch_assoc($result1); #This is where I am stuck. Simply, I am trying to run the code in the loop where the result of $sql1 equals 'Student'. The else will run if it is not #student and therefore is 'Lecturer'. I'm also not sure if my code inside the IF is fully correct either as it's not running that far. if($row1['accountType'] == 'Student') { $sql2 = "select courseCode from user_info where idNum = '$user'"; $result2 = mysqli_query($con,$sql2); $row2 = mysqli_fetch_assoc($result2); $sql3 = "select * from module_details where classListCourseCode = '".$row2['courseCode']."'"; $result3 = mysqli_query($con,$sql3); $response = array(); while($row = mysqli_fetch_array($result3)) { array_push($response,array("moduleID"=>$row[0],"lecturerID"=>$row[1],"moduleName"=>$row[2],"classListCourseCode"=>$row[3])); } echo json_encode(array("server_response"=>$response)); } Thanks in advance. So I have this snippet of code: Code: [Select] $row['ratings'] = ""; $ratingsSQL = $this->ipsclass->DB->query( "SELECT `pid` , `rating` , COUNT(`rating`) as ratings FROM `ibf_ratings` WHERE `pid` = '" . $row['pid'] . "' GROUP BY `rating` "); $i = 0; $ratingshtml = ""; if( $this->ipsclass->DB->get_num_rows( $ratingsSQL ) ) { while( $rrow = $this->ipsclass->DB->fetch_row( $ratingsSQL ) ) { $ratingshtml .= "<div class=\"rate_it_display\" style=\"background-image: url( 'style_images/rate/" . str_replace( ' ' , '' , strtolower( $this->ratings[$rrow['rating']] ) ) . ".png' ) \"> " . $rrow['ratings']. " x " . $this->ratings[$rrow['rating']] . "!</div>"; $i++; } $ratingshtml .= "<a href=\"#\" onclick=\"return RateItExpand( {$row['pid']} );\" style=\"color: #999;\">(list)</a>"; } $row['ratings'] = $this->ipsclass->compiled_templates['skin_topic']->ratings( $row['pid'] , $row['author_id'] , $ratingshtml ); I want to add an if statement to the code so that the ratings won't load unless a user clicks a button at the top of the screen. Can anyone help me with this? I'd be very appreciative. Thanks in advance. I am just wanting to know what the other forms of this type of conditonal would be, the type of if statement is as follows: if ($_POST) {print_r($_POST);} Just seen it a few times now, I know this means if $_POST exists. use the print_r() function to display the entire post array suber global variable. But what are the other combinations other than just if true? Like how are they used like this, like if I wanted to see if a random variable is not identical to another etc. Any helps appreciated, Jez. Hi and thank you for reading my topic.
I'm building a search engine from a tutorial and I'm getting the famous "Warning: mysql_num_rows() expects parameter 1" boolean etc..
I know mysql_num_rows() is depricated and I promise not to use it in the future but for now I'm using it in other projects on the same server and all's ok.
I'm quite sure it's a problem with the SQL syntax because when I paste SELECT * FROM searchengine WHERE keywords LIKE 'any_keyword_from_the_column' -into Phpmyadmin it won't return results, however a simple SELECT * FROM searchengine returns results.
So, without using mysql_error() I get: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\research2\search.php on line 42
But after I applyin mysql_error() to everything I narrowed it down to this: $query = mysql_query($query) or die (mysql_error());:
I get the error msg:
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 'OR keywords LIKE 'search' OR keywords LIKE 'term'' at line 1
I've checked multiple times to see if I've left out any columns in the db or mismatched them in while loop.
Below I have included the code which you can paste into a file called search.php along with the mysql dump file to pase into phpmyadmin query box. I'm using xampp.
In the code the WHERE clause is extended into the if statement and concatenated into the $query variable. This is done to break the words in the text box so they can be searched as an array.
As I said, I really think it is the SQL syntax and not the mysql_* functions but I could be wrong.
I'd really like to get this code working and mess with it. It looks like it could be very useful as a private website search engine.
Thanks for your time and mental energy.
<html> <head> <title></title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> </head> <body> <h2>Search Engine</h2> <form action = './search.php ' method = 'get'> <input type = 'text' name = 'k' size = '50' value = '<?php echo $_GET['k']; ?>' /> <input type = 'submit' value = 'Search'> </form> <hr /> results <br> <?php $k = $_GET['k']; $terms = explode(" ", $k); $query = "SELECT * FROM searchengine WHERE "; foreach ($terms as $each) { $i = 0; if ($i == 1) $query .= "keywords LIKE '$each' "; else $query .= "OR keywords LIKE '$each' "; } mysql_connect("localhost", "root", "") or die (mysql_error()); mysql_select_db("search2") or die (mysql_error()); $query = mysql_query($query) or die (mysql_error()); $numrows = mysql_num_rows($query) ; if ($numrows > 0) { while ($row = mysql_fetch_assoc($query)) { $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2> $description<br /><br />"; } } else echo $k ; ?> </body> </html>and here is the SQL dump (I called my db search2 and my table searchengine -- phpMyAdmin SQL Dump -- version 4.2.7.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Nov 27, 2014 at 11:54 AM -- Server version: 5.6.20 -- PHP Version: 5.5.15 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `search2` -- CREATE DATABASE IF NOT EXISTS `search2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `search2`; -- -------------------------------------------------------- -- -- Table structure for table `searchengine` -- CREATE TABLE IF NOT EXISTS `searchengine` ( `id` int(11) NOT NULL, `title` varchar(250) NOT NULL, `description` varchar(250) NOT NULL, `keywords` text NOT NULL, `link` varchar(250) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `searchengine` -- INSERT INTO `searchengine` (`id`, `title`, `description`, `keywords`, `link`) VALUES (1, 'Nick Frosty''s Official Web Site', 'Welcome to Nick''s', 'Nickfrosty Website tutorials videos web design', 'http://www.nickfrosty.com'), (2, 'Google search engine', 'The best search engine', 'google web site search ', 'http://www.google.oom'), (3, 'The Yahoo Search Engine', 'Not as good as Google', 'Yahoo search engine website', 'http://www.google.com'), (4, 'This is a test', 'This is a test website', 'Google', 'http://www.google.com'); -- -- Indexes for dumped tables -- -- -- Indexes for table `searchengine` -- ALTER TABLE `searchengine` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `searchengine` -- ALTER TABLE `searchengine` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;If you have any questions about any details of this code please ask me. Thanks for your time I need to convert the following select statement to a pdo->query but have no idea how to get it working: SELECT t.id FROM ( SELECT g.* FROM location AS g WHERE g.start <= 16785408 ORDER BY g.start DESC, g.end DESC LIMIT 1 ) AS t WHERE t.end >= 16785408; Here's the code I'm trying: <?php $php_scripts = '../../php/'; require $php_scripts . 'PDO_Connection_Select.php'; require $php_scripts . 'GetUserIpAddr.php'; function mydloader($l_filename=NULL) { $ip = GetUserIpAddr(); if (!$pdo = PDOConnect("foxclone_data")) { exit; } if( isset( $l_filename ) ) { $ext = pathinfo($l_filename, PATHINFO_EXTENSION); $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))"); $stmt->execute([$ip, $ext]) ; $test = $pdo->prepare("SELECT t.id FROM ( SELECT g.id FROM lookup AS g WHERE g.start <= inet_aton($ip) ORDER BY g.start DESC, g.end DESC ) AS t WHERE t.end >=inet_aton($ip)"); $test ->execute() ; $ref = $test->fetchColumn(); $ref = intval($ref); $stmt = $pdo->prepare("UPDATE download SET ref = '$ref' WHERE address = '$ip'"); $stmt->execute() ; header('Content-Type: octet-stream'); header("Content-Disposition: attachment; filename={$l_filename}"); header('Pragma: no-cache'); header('Expires: 0'); readfile($l_filename); } else { echo "isset failed"; } } mydloader($_GET["f"]); exit; It gives the following error: QuoteFatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.144.181) ORDER BY g.start DESC, g.end DESC ) AS t WHERE t.end >=inet_aton(7' at line 1 in /home/foxclone/test.foxclone.com/download/mydloader.php:19 Stack trace: #0 /home/foxclone/test.foxclone.com/download/mydloader.php(19): PDO->prepare('SELECT t.id FRO...') #1 /home/foxclone/test.foxclone.com/download/mydloader.php(38): mydloader('foxclone40a_amd...') #2 {main} thrown in /home/foxclone/test.foxclone.com/download/mydloader.php on line 19 How do I fix this? This isn't the entire code just enough to see what I'm trying to do. Everything was working until I added the mysql update query in the if statement. Is this possible or am I doing something wrong? When I run the script it just echos "No results found" twice as $num_results = 2. Code: [Select] <?php include("../includes/connect.php"); $query = "SELECT ........ "; $result = $db->query($query); $num_results = $result->num_rows; if ($num_results == 0) { exit; } else { $i=0; while ($i < $num_results) { $row = $result->fetch_assoc(); $id = $row['id']; if ($expiration_date > $today) { ### EMAIL CODE HERE ### $update = "UPDATE model SET reminder_sent = '1' WHERE id = '$id' "; $result_2 = $db->query($update); $i++; } else { echo "No results found."; $i++; } } } ?> Okay so after echoing awardType it says Match which would mean it would go to the else part of the statement but it doesn't. It still shows the dropdown for the characters and don't know why? Code: [Select] <?php require ('php/awardsshowNom.php'); ?> <script type="text/javascript" src="forms/edit/js/awardsshowNom.js"></script> <!-- Form --> <form action="#" id="awardsshowNomForm" > <fieldset> <legend>Edit Award Nominations</legend> <?php echo $awardType; ?> <?php if ($awardType = 'Singular') { ?> <div class="field required"> <label for="nominees">Nominees</label> <select class="dropdown" name="charactersDrop" id="charactersDrop" title="Characters Drop"> <option value="">- Select -</option> <?php while ( $row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r"; } ?> </select> <input type="button" value="Add Character" class="" onclick="HandlerCharacters()"/> <ul id="characterList"> </ul> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <? } else { ?> <div class="field required"> <label for="nominees">Nominees</label> <select class="dropdown" name="events" id="events" title="Events for <?php echo date("Y") ?>"> <option value="">- Select -</option> <?php while ( $row = mysqli_fetch_array ( $matchResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['segmentTitle']."</option>\r"; } ?> </select> <input type="button" value="Add Match" class="" onclick="AddMatch()"/> <ul id="matchList"> </ul> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <?php } ?> <input type="hidden" name="awardID" id="awardID" value="<?php echo $awardID; ?>" /> <input type="hidden" name="awardShowID" id="awardShowID" value="<?php echo $awardShowID; ?>" /> <input type="hidden" name="awardName" id="awardName" value="<?php echo $awardName; ?>" /> <input type="submit" class="submit" name="editAwardNom" id="editAwardNom" title="Edit Award Nominees" value="Edit Awards Nominees"/> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Arena was added to the database.</p> </div> <!-- /Messages --> Hi guys, I have an interesting situation and I was hoping someone could explain what is going on to me. I have an enquiry form on a site that sends an e-mail. All the code is on one page with the form submitting back to the same page. I have a variable, msg, which at the top of the page is set to nothing and then an if statement to see if the form was submitted. If the form was submitted then msg will have one of three messages in it by the end (regardless of anything else). However when I check the msg variable after the if statement it is empty. To test if it was being affected I changed the initial value from nothing to TEST. After the IF statement the variable still held the value TEST, thus confirming it wasn't being affected by the IF statement. Now onto my code (the whole page is over 600 lines long so I'm only posting the relevant code): Code: [Select] <?php session_start(); $msg = ''; $input = array( 24 variables from form here... ); if(isset($_POST['form-submitted'])) { $missing_info = FALSE; $array = array( variables along with their filter validation/sanitize types... ); $input = filter_input_array(INPUT_POST, $array); /* PHP validation code checking appropriate fields were not empty. If they were set $missing_info = TRUE */ if(!$missing_info) { /* Construct e-mail, this sends successfully. */ if(mail($to, $subject, $content, $headers)) { $msg = '<div class="message"><h1>Form Sent</h1><br />Your form has been sent to us. We endevour to respond to all booking requests with 2 working days. If you have not heard from us in that time please contact us on 01462 893620. If you chose to confirm by post please allow 5 working days before contacting us.</div>'; $_SESSION['msg'] = $msg; } else { $msg = '<div class="message"><h1>Technical Issues</h1><br />We appologise but the website is currently experiencing technical difficulties. Please try again later or print this form out and post / fax it to us. Alternatively you can call us on 01462 893620.</div>'; $_SESSION['msg'] = $msg; } } else { $msg = '<div class="message"><h1>Incomplete Form<h1><br />Please make sure to complete all fields of the form before submitting your booking request.</div>'; $_SESSION['msg'] = $msg; } } if(isset($_SESSION['msg'])) { $msg = $_SESSION['msg']; unset($_SESSION['msg']); } ?> If I don't load the message into session and then back out of session after the if statement then $msg will still hold whatever it was initially set to (in this case an empty string). Why isn't it set in the if statement? I'm having an issue with holding a session variable in the statement below $Color is losing its value in the if statement. For example int the ( ) $Color is a zero while in the echo part $Color is being displayed correctly as Blue. OK, I think I have confused this code and it is not calculating correctly. $ckifdue = mysql_query("SELECT * FROM accounting WHERE ClientID = '$clientid'") or die(mysql_error()); while($ckdue =mysql_fetch_array($ckifdue)){ if($ckdue['AmountDue'] == "0"){ $_SESSION['MONEYOWED'] = "0.00"; } else { $_SESSION['MONEYOWED'] = $_SESSION['MONEYOWED'] + $ckdue['AmountDue']; } if($ckdue['Amount1RS'] == "Balance Due"){ $totcol = $ckdue['TotalCollected']; echo " total collected:" . $totcol; $monpaid = $_SESSION['MONEYPAID']; echo "money paid in:" . $monpaid; $_SESSION['MONEYPAID'] = $totcol + $monpaid; echo "session money paid:" . $_SESSION['MONEYPAID']; } } $moneypaid = $_SESSION['MONEYPAID']; $moneyowed = $_SESSION['MONEYOWED']; echo "money paid:" . $moneypaid; echo " money owed:" . $moneyowed; $moneyowed = $moneyowed - $moneypaid; unset($_SESSION['MONEYOWED']); unset($_SESSION['MONEYPAID']); The echos look like: total collected:100.00money paid in:200session money paid:300 total collected:100.00money paid in:300session money paid:400money paid:400 money owed:0.00 There should be $100 due, $200 paid, so a balance of -100. There is 2 balance due reciepts, this is just not calclating right in the sessions. Hello all, I am a beginner at PHP and trying to form an IF statement, I'm running into a problem which I cannot seem to solve. Due to my lack of syntax knowledge I would appreciate if someone could point me in the right direction. The combo variables are sent to this page through a form and defined as these variables at the top of the page. e.g $combo0 = $_POST["combo0"]; When the results are displayed any form field which was left blank or empty I want to show "N/A" if data is detected in being sent through the form I then want the "Else" statement to take affect. Currently when I run the below statement N/A is echoed despite if data was sent through the form fields or not.... if (empty($scrap)) { echo "<h3>Submitted Scrap Results</h3> No scrap parts were booked off"; } elseif (empty($combo0) || empty($combo1) || empty($combo2) || empty($combo3) || empty($combo4)) { echo "N/A"; } else { echo "<h3>Submitted Scrap Results</h3> <b>Reason:</b> " .$combo0." - ".$combo1." - ".$combo2." - ".$combo3." - ".$combo4." <br /> <b>on machine</b> " .$mid. " - <b>No. Scrap</b> " .$noscrap. ""; } Anyone any ideas? I want to display some specific data from my database (just data from a given date). I first created a page where the user picks the date. After the date is defined it is passed to the next page where the data from that date is displayed. That page includes a form where users can edit the data. The form data is then passed to a third page for processing. All of this works fine. Now I want the user to be taken back to the previous page with the assigned date. On the processing page I am using this statement: Code: [Select] header("Location: /teetimes/adminteetimes.php?teetimedate=$dateID");and on the display page I'm using Code: [Select] $dateID = $_REQUEST[teetimedate];The display page is using a SELECT...WHERE Date='$dateID' statement and $dateID is defined in the processing page. Problem is: I'm redirected from the processing page back to the display page but the date isn't passed, so the correct data isn't being displayed. Can anyone help me pass a variable using a header?? Or show me where my logic is lacking?? Thanks! Code: [Select] echo("<p class=\"commentboxContainer\"><table width=100% border=0> <tr> <td bgcolor=\"#EEE\"><strong><p class=fltlft>$name </strong>says:</p></td> </tr> </table> <table width=100% border=0 bgcolor=\"#EEE\"> <tr> <td width=40%><img src=../images/Icons/People/Anonymous.png width=64 height=64 border=1 /></td> <td width=60%>$comment',0,6</td> </tr> </table> <table width=100% border=0> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft><em>$email</em></p></td> </tr> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft>added on $time</p></td> </tr> </table></p><br>"); Here's my echo statement for displaying comments by users. I want to add a substr (); function to limit the amount of characters of the $comment field. That way if a user makes a long comment it doesn't push the page down. I tried putting it after the echo (); but that didn't work. I also tried putting it before $comment and that didn't even work. I know that if I make two separate echo statements, this can be done, but the field "$comment" is displayed within a table that is part of the original echo statement, so what do I do? basically, I have one calculation that relies on the value returned by an if statement, but i can;t for the life of me figure it out correctly... Here is what i am trying to accomplish: Here is the code for the IF i need to get the value of if ($loadedMiles < 500) { (500 - $loadedMiles) * .25 * $mainRate; } And here is the reason why i need it: if ($loadSize == "Full") { $loadedmiles + thevalueoftheif; } basically i will need to have a way to get the values of the functions in the IF statements if that makes any sense... thanks in advance! |