PHP - Simple Expression Problem
Ok I decided to brush up on some functions and this one was giving me a hard time. Basically the if condition is printing the statement even though its not what the expression was asking for.
I'm positive I am just missing something small, but I can't figure it out. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xm1ns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Counting Words...</title> </head> <body> <?php function count_words() { $totalwords = str_word_count($_POST['total']); $amountneeded = $_POST['amount']; $wordsneeded = $amountneeded - $totalwords; $extrawords = $totalwords - $amountneeded; if (isset($_POST['submitted'])) { if(str_word_count($_POST['totalwords']) <= $_POST['amountneeded']) { print "\nYou need $wordsneeded more words"; } else { print "\nYou wrote an extra $extrawords words"; } if(str_word_count($_POST['totalwords']) == $_POST['amountneeded']) { print "You hit the jackpot and got just as much words as you needed"; } } } ?> <form action="wordcount.php" method="post"> <p>Words Needed: <input type="text" name="amount" value="" /></p> <p>Copy and Paste your words:</p> <textarea name="total" rows="5" cols="30"></textarea> <input type="submit" name="submit" value="Count My Words" /> <input type="hidden" name="submitted" value="true" /> </form> <?php count_words(); ?> </body> </html> Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=334308.0 I am just new to relational algebra probably a pre-step before learning SQL queries. Can you help me make the expressions of relational algebra expression for each of the following queries. This is the table contained inside a bus driver database.
driver ( driver_id, driver_name, age, rating ); bus ( bus_id, bus_name, color); reserves ( driver_id, bus_id, date);a. Find the names of drivers who have reserved at least three busses. b. Find the names of drivers who have reserved all busses. c. Find the names of drivers who have reserved all busses called Shuttle. d. Find the IDs of drivers whose rating is better than some driver called Paul. I would be grateful if somebody can help me here. SOLVED, sorry. ... but i can't work it out. all i want to do is; if ( $this_item exists within the table ) { do a } else { do b } for example, $this_item = 'john', and i want the script to do (a) if he's in the table, or (b) if he isn't. thank you! This is my website: www.wearenip.com/home.html This is the menu that should appear on the left hand side, but doesn't: www.wearenip.com/menu.php This is my server's output saying that php is running just fine: http://wearenip.com/phpinfo.php I'm using this code in the left side bar div: Code: [Select] <?php include("menu.php"); ?> The PHP file will not display from the HTML file no matter what I do. I've tried using every possible combination of file linking including /menu.php ./menu.php and even the full http://www.wearenip.com/menu.php etc etc etc I'm genuinely upset about this. Any help would be greatly appreciated. PS: I can't get any PHP file to properly include in any HTML file on any computer I have. Nothing displays whatsoever regardless of what is in the PHP file, even if it's just a text word. Doesn't matter if it's hosted on a PHP compatible internet server or just on a local server or just on the local machine itself. Nothing. It shouldn't be that difficult I just don't know how to do it myself. I'm using the following code for a simple navigation, i has been placed in the content of my home page, it works fine however i don't know how to set the home page. <div id="content"> <?php $page = $_GET['page']; $file = $page.".php"; if(file_exists($file)) { include($file); } else { include "error.php"; } ?> </div> so I have an xml string the following expression $xpath = $response->xpath('/atom:feed/atom:entry/atom:content'); returns the following array SimpleXMLElement Object ( [@attributes] => Array ( [type] => application/vnd.google-earth.kml+xml ) [Placemark] => SimpleXMLElement Object ( [name] => M1 [description] => SimpleXMLElement Object ( ) [Style] => SimpleXMLElement Object ( [IconStyle] => SimpleXMLElement Object ( [Icon] => SimpleXMLElement Object ( [href] => http://maps.gstatic.com/intl/en_ALL/mapfiles/ms/micons/blue-dot.png ) ) ) [Point] => SimpleXMLElement Object ( [coordinates] => -79.395018,43.645423,0.0 ) ) ) However what I'm trying to get are the coordinates, but neither $xpath = $response->xpath('/atom:feed/atom:entry/atom:content/Placemark'); OR $xpath = $response->xpath('/atom:feed/atom:entry/atom:content/Placemark/child::*'); work I even tried just loading atom:content into an array and going from there no luck. Any ideas. Oh. BTW this might help http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html#RetrievingFeatures hi guys usename:password user1:pass1 user2:pass2 user3:pass2 i have a function fun(username,pass) and i want to run it for lots of different user names and passwords. what would the best way to do this? would i make an array and use a foreach loop or how would i do it and what could would i need?? Hi -- This query seems to be problematic because the UPDATE is not being performed. Could you please take a gander and let me know what is the problem? BTW, the table "teamy" does contain 630 records. Thanks in advance! $sql = "SELECT COUNT( * ) AS records FROM teamy" ; $result = mysql_query( $sql ) ; if ( ! $result ) { die ( __line__ . "_teamy_" . mysql_error() ) ; } $a_count = mysql_fetch_assoc($result); if ( $a_count['records'] = 0 ) { echo "No records found in teamy." ; } else { /*** Update r_rost_rma ***/ $sql = "UPDATE r_rost_rma JOIN teamy ON r_rost_rma.student_id = teamy.student_id SET r_rost_rma.teachername = teamy.team WHERE RTRIM( UPPER( r_rost_rma.localcourse ) ) = 'HOMEROOM'" ; $result = mysql_query ( $sql ) ; if ( ! $result ) { die ( __line__ . "_update_r_rost_rma_" . mysql_error() ) ; } } Hi guys,
I am trying to echo multiple calendar events from a mysql table and order them by the date column.
There are several events on each day so I am trying to echo the date once then list the associated events under that date.
Such as
2014-05-10
Event 1, event 2, event 3
2014-05-11
Event 1, event 2, event 3
instead of
2014-05-10 event 1,
2014-05-10 event 2,
2014-05-10 event 3,
2014-05-11 event 1 etc...
This is my coding so far:
while($row = mysqli_fetch_assoc($result)) { $dutydate = $row['MyDate']; if($dutydate != $previousdate) { echo $dutydate.'<br />'; } elseif(!empty($dutydate)) { echo $dutydate.'<br />'; } echo $event1.' | '.$event2.' | '.$event3.'<br />'; $previousdate = $dutydate; } ?> Im simply having a problem with structuring a directory structure for mkdir Code: [Select] mkdir("saves/".$worldname."/".$playername, 0777); The middle "/" is causing issues, if I take it out I have no problem in creating a folder name saves/worldnameplayername/ just want to add playername as a sub-dir. I have tried every combination I can think of to get it to accept the divider Any help? Hi guys.I've got a problem.I'm building my php browsergame and i'm stuck into the inventory page.I have a code that seems ok to me but it won't work.Here it is: $inventory = array(); $query = sprintf("SELECT id, item_id, quantity FROM user_items WHERE user_id = '%s'", mysql_real_escape_string($userID)); $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $item_query = sprintf("SELECT name FROM items WHERE id = '%s'", mysql_real_escape_string($row['item_id'])); $item_result = mysql_query($item_query); list($row['name']) = mysql_fetch_row($item_result); array_push($inventory,$row); } I've spotted the problem.The $inventory array is empty.I checked it with if(empty($inventory)) .Thanks in advance and keep in mind that I'm a noob yet. I'm trying to learn arrays and I have this problem: I have a variable $a which is a result from a from a database query If I echo it I get: Code: [Select] forenamesurnamedate_of_birthgenderpaypal_addresspayment_planaddress_line_1address_line_2address_cityaddress_zip_post_codeaddress_countrytelephonemobilewhere_did_you_hearreceive_newsletter If I var_dump($a) I get: Code: [Select] string(8) "forename" string(7) "surname" string(13) "date_of_birth" string(6) "gender" string(14) "paypal_address" string(12) "payment_plan" string(14) "address_line_1" string(14) "address_line_2" string(12) "address_city" string(21) "address_zip_post_code" string(15) "address_country" string(9) "telephone" string(6) "mobile" string(18) "where_did_you_hear" string(18) "receive_newsletter" My question is, how do I get each value from a? It looks like an array to me because it holds multiple strings. I need to get the first, second and third elements printed on the page and used in other areas of my program. Thanks in advance I am thining this will be pretty simple for someone to help me with, I have been hassling with it for several hours and really feel dumb that I can't get it to work. Here is the problem - I have one script wherein I have a form that passes a variable using Post method. I have previously assigned a value "A" to a variable $rtn the input is: <input name="Rtn" type="hidden" value="<?php echo $rtn; ?> /> In the script that I am calling I first get the value of the variable: $rtn = (_POST['Rtn']); then there is other stuff goin on and I come to an if stmt: if ($rtn == "A" { do some stuff } else { echo $rtn; } It will never get into the do some stuff - it always falls through to the else the output is \'A\' I have tried to use double quotes, single quotes, used stripslasches and addslashes funtions, trim, and various combination of all of these. Nothing I do seem to get me into the first part of the if stmt, to do some stuff. Hello, I have a simple issue with a code that uses includes. What I want to do is to include a bit of php code I made to my main pages so I don't have to edit each file that will contain the same included code. The problem with that included code is that contains variables that only the main files would know. Let me show you basically what I'm talking about. mainfile1.php Code: [Select] <?php $cat = "meow"; include "content.php"; ?> mainfile2.php Code: [Select] <?php $cat = "mew"; include "content.php"; ?> (mainfile3.php and so on...) content.php Code: [Select] echo '<center>My cat said '.$cat.' today!</center>'; I was expecting to see: My cat said meow today! and My cat said mew today! But when I loaded both pages it rendered like this: My cat said '.$cat.' today! HTML works properly but the variables are ignored and displayed as plain text. What I need to do so those variables don't get ignored? Thanks. Can someone explain to me whats wrong with this? <?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html> The output it gives me in the browser is this: Quote Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Program Files\xampp\xampp\htdocs\sessions.php:1) in D:\Program Files\xampp\xampp\htdocs\sessions.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Program Files\xampp\xampp\htdocs\sessions.php:1) in D:\Program Files\xampp\xampp\htdocs\sessions.php on line 2 Pageviews=1 Explanation? Hello, i am trying to create a simple funtion that i can all upon to "turn off a website" i am calling the function by <?php siteonline(n); ?> and the function is function siteonline($msg){ $offlinecheck = mysql_query("SELECT * FROM acp") or die(mysql_error()); $siteoffline = mysql_fetch_array($offlinecheck); $ifsiteoffline = $siteoffline['site_offline']; $offline = $siteoffline['offline_msg']; if ($ifsiteoffline == "y") { echo("$offline"); die();} } now this will turn off the site but it shows no message what so ever and i can not figure out why can anyone help? Cheers, heres the code... <?php mysql_connect("localhost","peter","tizer") or die("Error: ".mysqlerror()); mysql_select_db("matquant"); //replace TestTable with the name of your table //also in a real app you would get the id dynamically $idtochange=$_POST['idtochange']; $sql="select * from `quantites` where id = $idtochange"; $query=mysql_query($sql); while ($row=mysql_fetch_array($query)){ $id = $row['id']; $material = $row['material']; $quantity = $row['quantity']; $unit = $row['unit']; //we will echo these into the proper fields } mysql_free_result($query); ?> <html> <head> <title>Edit material list</title> <link href="css/quant1.css" rel="stylesheet" type="text/css"> </head> <body> <div id="leftcol"> <form "method="post"> <p><br/> <input type="text"value="1" name="idtochange" > <p> <input type="submit"value="submit changes"/> </form> <form action="changequan.php"method="post"> <p>Material Id currently active<br/> <input type="text"value="<?php echo $id;?>" name="id" disabled/> </p> <p> Enter new material name: </p> <input type="text"value="<?php echo $material;?>" name="material"/> <br/> change quantity: <input type="text"value="<?php echo $quantity;?>" name="quantity"/> <br/> unit of mesurement for quantity<br/> <input type="text"value="<?php echo $unit;?>" name="unit"/> <br/> </p> <input type="submit"value="submit changes"/> </form> </div> <div id="rightcol"><?php // make connection mysql_connect ("localhost", "peter", "tizer") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); // build query $query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); // display results while ($row = mysql_fetch_array($query)) { echo "<br /> ..... " .$row ['id']. " ....... " .$row ['material']. " ...... " .$row['quantity']. " ...... " .$row['unit']. "<br />";} echo mysql_error(); ?> <a href="index.html">Home </a> <p> <a href="quanform.php">Insert new material and quantity form</a></p></div> </body> </html> I'm struggling with php. Any help anyone can give would be appreciated. Hi, This is a image tooltip from database. but I have got the problem, Not Working! How can i fix it. <a href="index.php?MD=urundetay&resimid=<?php echo $row_uruns['resimid']; ?>"><img src="urun_resim/<?php echo $row_image['image']; ?>" width="150" border="0" /></a> So, I'm going through a tutorial in my PHP book and we're using the code below. The page shows up and connects to the database (no error reported), but no data comes up. I'm wondering if I'm just missing something small or what? Let me know if you can help <html> <head> <title>Search Results</title> </head> <body> <h1>Book-0-Rama Search Results</h1> <?php //create short variable names $searchType=$_POST['searchType']; $searchTerm=trim($_POST['searchTerm']); if(!$searchType || !$searchTerm){ echo 'You have not entered enough information to process the search'; exit; } if(!get_magic_quotes_gpc()){ $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } echo $searchType; echo $searchTerm; @ $db = new mysqli('localhost','root','root'); if(mysqli_connect_errno()){ echo 'Error: Could not connect to the database man...'; exit; } $query = "SELECT * FROM books WHERE ".$searchType." LIKE '%".searchTerm."%'"; $result = mysqli_query($query); $num_results = mysqli_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0;$i<$num_results;$i++){ $row = mysqli_fetch_assoc($result); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br/>Author: "; echo stripslashes($row['author']); echo "<br/>ISBN: "; echo stripslashes($row['isbn']); echo "<br/>Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); ?> </body> </html> Hi all, I have been working on this script for over 5 hours, the script used to work but I have recreated some html code in the html form and I think it may have something to do with why the script does not work but I can not see it. Hopefully an extra pair of eyes can help. The I have tested what the $_POST['title'] below echos in the php script and it does carry the value to the php page, but the IF statement does not work. Here it is: html form in a php page: Code: [Select] <form action="testform.php" method="post"> <fieldset style="border:none"> <ul class="controls"> <li> <label for="label">Title</label> <input name="title" id="title" type="text" class="text" maxlength="" value="grumman aa4" /> </li> <li> <label for="label">Aircraft Registration</label> <input name="reg" id="label" type="text" class="text" maxlength="6" value="G-qwea" style="text-transform:uppercase;" /> </li> <li> <input name="Button" type="submit" class="button centered" /> </li> </ul> </fieldset></form> The part of the PHP page that does not work is below. If the php below just says if ($_POST['reg'] == "")... it works but as soon as I put || $_POST['title'] it does not work. I have also tried if ($_POST['reg'] && $_POST['title'] == "")... which DOES work? testform.php <?php if ($_POST['reg'] || $_POST['title'] == "") { $fillinform = "Please fill in all the form to add a listing."; include("saleform.php"); exit(); } ?> |