PHP - Reading Out Of Db Not Showing Anything?
Hi People.
Here is a form that is supposed to read from my database. My primary key is called "index" and I have about 300 records in the database. I wanted to be able to view the records but when I load this page the "php" part is empty. I simply get given a blank form. I know it is connecting to the DB OK because I changed one letter in the password and then got a "can't connect to the database error" just to test it out. Code: [Select] <?php $host = 'localhost'; $usr = "the_db_user"; $password = 'not_shared_on_forum'; $db_name = 'stranded'; function cr($string){ $clean_string = str_replace("rn","<BR>",$string); return $clean_string; } //$id = 11; if (!isset($id)) $id = $_GET['id']; mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $read_query = "select * from HelperFormData where index = '$id'"; $results = mysql_query($read_query); $rs = mysql_fetch_array($results); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- body,td,th { font-size: 12px; } --> </style></head> <body> Surname: <? echo $rs["surname"]; ?> <table width="500" border="1" bordercolor = "#2c2cf6" textcolor = "#2c2cf6"cellspacing="1" cellpadding="2"> <tr> <td colspan="5">Record number: <? echo $rs["index"]; ?></td> </tr> <tr> <td width="120" bgcolor = #E6F8EB>Surname</td> <td width="120" bgcolor = #E6F8EB>First Name</td> <td width="120" bgcolor = #E6F8EB>phone1</td> <td width="120" bgcolor = #E6F8EB>phone2</td> <td width="120" bgcolor = #E6F8EB>Location</td> </tr> <tr> <td bgcolor = #E6F8EB textcolor = #AC1636><strong><? echo $rs["surname"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["firstname"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["phone1"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["phone2"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["location"]; ?></strong></td> </tr> <tr> <td bgcolor = #dbeff8>Qualifications</td> <td bgcolor = #dbeff8>Expertise</td> <td bgcolor = #dbeff8>Assistance</td> <td bgcolor = #dbeff8>Languages</td> <td bgcolor = #dbeff8>E-Mail</td> </tr> <tr> <td bgcolor = #dbeff8><strong><? echo $rs["qualifications"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["expertise"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["assistance"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["languages"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["e_mail"]; ?></strong></td> </tr> <tr> <td bgcolor = #E6F8EB>Consent</td> <td bgcolor = #E6F8EB>Published</td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> </tr> <tr> <td bgcolor = #E6F8EB><strong><? echo $rs["consent"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["radio_callsign"]; ?></strong></td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> </tr> <tr> <td colspan="5"><p>Comments:<br /> <strong><? echo $rs["comments"]; ?></strong></td> </tr> </table> </body> </html> </html> Similar TutorialsI am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here. Thank you for any assistance I may get!! - Amy - Code: [Select] <body><font color="006600"> <div style="background-color:#f9f9dd;"> <fieldset> <h1>Asset Entry Results</h1> <?php // create short variable names $tag=$_POST['tag']; $serial=$_POST['serial']; $category=$_POST['category']; $status=$_POST['status']; $branch=$_POST['branch']; $comments=$_POST['comments']; if (!$tag || !$serial || !$category || !$status || !$branch) { echo "You have not entered all the required details.<br />" ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $tag = addslashes($tag); $serial = addslashes($serial); $category = addslashes($category); $status = addslashes($status); $branch = addslashes($branch); $comments = addslashes($comments); } //@ $db = new mysqli('localhost', 'id', 'pw', 'inventory'); $db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database"); $query = "insert into assets values ('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." asset inserted into Inventory."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> </fieldset> </div> </body> how can I read a url coming from another site by header('Location:') command Hello, I'm trying to read some XML by name this is the XML: Code: [Select] <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <imgdir name="01040000.img"> <imgdir name="info"> <canvas name="icon" width="29" height="30" basedata="iVBORw0KGgoAAAANSUhEUgAAAB0AAAAeCAYAAADQBxWhAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAMuSURBVEhLlZcBlatADEWxUAu1gAUs1AIWsIAFLGChFmphLXwL83ND3jQwlO5yTg6FmcnNSzLDbtf97io27Zv9ztOHWY3zZezKOHSl7/ud8Y6x1/IxoK+BOGwd+zIN99LfN4dnQGAVuG5zmD8Nt7I87u6D55SdU3jh2hZuwPK6lfJvKq9wmkH/nhtId+bPBvtZRgeOva219WQgZaEB++DjfqtQHArs9wjCnVkgCoZ1QIGhEuBgfvyyoJlPgKG6gn1AwKo0FjjcfisIqXOwAW83MysLqZ0MyD0r9Wy9a/6GKloBH7YYZx4plwUlqGBE70CZgVGaU4xifJ+pdZWkRw0AlGhx+JwDHmnNsN7GZahVioFLsac66ptTvKXFjNr0/bB1LvWxptqpCVUERaAC4hgo5kAbVxdL7THFNSUZiuPF1KvW+TdjlAKHgAVFicCoJtVqLvf93kZbWngxPMaqVGpwzsLcaAIKChgYUHxUxWquyCTzleK6TaZp9kUMKEJg7jwiBahtIZVZrXwo3Vp3VEobOyxDmQSw7rc4KDwjEUhOsdTiY56X6ktwZSKfED4Rk1Lvutir+XTxIy8aqnZudLHv14BmMM15PBxc6bI+a4SLPb/Mfsxstt95xhjDprCH3TGeee/1XNed2jOoR5ehcpDBGX4FPkJzyZrUCkp6z5RK7TelW9bWRm1z9qqeiupuCzF92vR505fm7MDQO5zj75jiBiqYmsj3KJ+naCR9VThVCEDj3POW4FlQ+fQT7qqRmMgiTpLnNOzA+qThmDHN4aSabe9iOnGkUh181rnevdlwxB4kZXIodfrQa85RtdQefF7+2eIKstJcP4BSmefxTor9UIk0f/0DKSb4YlSycPCvzvuPMaLXYc88zdV81fjP0FwrAcdxLJhvB4NltfzOSinHX6A7lR61qcxAg9reP1d7Udvv9VTU27e1gfaf1CrdufGimVhj294Dbq5ayw9AOx072a621FSW925AR7vb8dwBb8CeXprnuIXseTazE3BnzX7NezZ8EOQl1OsVRmRMxrLC4++r/2/wMYTCj+kl34CZICMlR5Oj4/u8ThD8NSn9D9wL1z9uxdBdAAAAAElFTkSuQmCC"> <vector name="origin" x="-2" y="30"/> </canvas> <canvas name="iconRaw" width="29" height="29" basedata="iVBORw0KGgoAAAANSUhEUgAAAB0AAAAdCAYAAABWk2cPAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAL4SURBVEhLlZYBtYMwDEVnAQuzgAUsYAELWMACFrAwC7MwC99Cf27o6wJ0sO2cHAZNc/PStHC7ffdL5nZl30X64HUIPg+3NHS31LbtxnjG2HP+mNBlIg5bhjaN3T219zVgDQisAJfVB/+xa9Lc3z0G96E6VXjit05cgenZpPQ3pmcOGkF/jxWkK/6TwV7z4MChtbk2nwqEKhzAPtjfmwIloMB+zUl4MEtEyTAPKDBUAuwsjv8safxJMKsuYB8QsCjNExxu/5WE1DnYgE1jZstCaUcDco1KvVrvNX9Dla2AvU0mmGfKz5ISVDCyd6DMwCiNJUYxsWtqXSXlUQMAJVsCPqYMz2WNsNbGZahViYFLsZc6r28s8VoWM9ambbu1c1kfa6qNmqyKpEhUQAIDxRxo4+piqd2XuJQkQgk8m3qtdfzPGEtBQMCCokRgVFNqNZfHfm+jtSw86PqhKJUagjMxNpqAggIGBpQYRbGaK1cSf5W4bJNxnHwSA8oQmAfPmQLUtpDKqFYxVG7N2yuljR0WoTgBLPstHxRekZxILLHUEmOa5hJLcFUinhDuiEmpd13eq/F08SMvN1Tp3NzFvl8zNIJpzv3h4Ern5VEynO3+afYyM2+/co8xho3Zerti3PPc13NZNmprUM8uQhUggiP8DLyHxiU7lFZQyltTKrVXSteqLQe1h7NX66ms7jYR06tNrze9aWoHhp4RnHj7Eh+ggqmJfI/yesqNpLcKpwoJaJxr3BLcC6qYfsKdNRKOTOIkeYzdBqxXGoEZkw8n1WR7F9OJI5Xq4FrnevdGIxB7kJIpoNTpRS+fvWqp3cU8/WxxBVFpXD+AUhn9eCbFfqjkMl9+IGUHn4xKJnb+1nl/jJG9Dnv85Ct/rfHP0LhWAg7DkDDfDgaLavkflbIcv0A3Kj1rUxmBqkZN7cnaXq+nsl7frXVoTa3KHRvvU9duTiatzQlQ/pu1ZZ4s7t2voGRL8+y30If6HPZr3LPfAIuCX5wryV1+1QP6B07yxunYFCcQAAAAAElFTkSuQmCC"> <vector name="origin" x="-2" y="30"/> </canvas> <string name="islot" value="Ma"/> <string name="vslot" value="Ma"/> <int name="reqJob" value="1"/> <int name="reqLevel" value="40"/> <int name="reqSTR" value="130"/> <int name="reqDEX" value="0"/> <int name="reqINT" value="0"/> <int name="reqLUK" value="0"/> <int name="incDEX" value="3"/> <int name="incMMP" value="10"/> <int name="incPDD" value="45"/> <int name="tuc" value="7"/> <int name="price" value="6700"/> <int name="cash" value="0"/> </imgdir> Say I want to get reqJob and print it onto the page. Also I would need to get the BaseData of the iconRaw canvas. [xml]<category id="SOCMENEURASTVICLEA" order="26800">Aus. Victoria League</category>[/xml] I have the above xml, I can read the category id, order but I dont no how to read the value "Aus. Victoria League" foreach($description->children() as $category) { foreach($category->attributes() as $a => $b) { echo "<br/> -------- "; echo $a,'="',$b,"\"\n"; } echo "category name" . $category->asXML(); } the asXML() i have no idea what that is but am guessing I need thats where the php function which returns the value needs to go Thank you The following script just validates some form inputs, and then puts any errors inside an array. I get this error: Fatal error: Cannot use [] for reading in C:\xampp\htdocs\Game\includes\validation.php on line 104 I've looked around, and this still does not make any sense to me. public function ValidateEmail($email, $reemail){ /* Sanatize. User filter_var to validate. Make sure both emails match. Check if email already exists or not. */ trim($email); strip_tags($email); mysql_real_escape_string($email); trim($reemail); strip_tags($reemail); mysql_real_escape_string($reemail); if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $this->valid = false; //Line 104 $this->error[] - "The E-Mail that you provided is not valid."; } else { $this->valid = true; } if($email !== $reemail){ $this->valid = false; $this->error[] = "The E-Mail's that you provided do not match."; } else { $this->valid = true; } if(filter_var($email, FILTER_VALIDATE_EMAIL) && $email == $reemail){ $checkmail = mysql_query("SELECT users.email, temp_users.email FROM users, temp_users WHERE email = '$email'"); if(mysql_mum_rows($checkmail) == 1){ // email is found, throw out error $this->valid = false; $this->error[] = "That E-Mail is already in use."; } else { $this->valid = true; } } return $this->error; } Line 104 is commented out. Thanks! PHP 5.3.8 XAMPP on Windows XP I have an XML file that manages the input to an mp3 player on this page http://www.jimslounge.com/segovia/ The structure looks like this Code: [Select] <content> <auto_play>yes</auto_play> <loop>yes</loop> <volume>60</volume> <artist> <song_title><![CDATA[Bach - Suite No. 3 - Allemande]]></song_title> <artist_name><![CDATA[Andre Segovia]]></artist_name> <image_path>load/images/segovia.jpg</image_path> <mp3_path>load/songs/Bach - Suite No. 3 (for solo cello, arr. Duarte)- Allemande.mp3</mp3_path> <url target="_blank" open="yes">http://en.wikipedia.org/wiki/Andr%C3%A9s_Segovia</url> </artist> <artist> ... with <artist> being the repeating element I want to be able to read and eventually write to If I run this Code: [Select] $xml = simplexml_load_file("load.xml"); var_dump($xml); I get this object(SimpleXMLElement)#1 (4) { ["auto_play"]=> string(3) "yes" ["loop"]=> string(3) "yes" ["volume"]=> string(2) "60" ["artist"]=> array(22) { => object(SimpleXMLElement)#2 (5) { ["song_title"]=> object(SimpleXMLElement)#24 (0) { } ["artist_name"]=> object(SimpleXMLElement)#25 (0) { } ["image_path"]=> string(23) "load/images/segovia.jpg" ["mp3_path"]=> string(74) "load/songs/Bach - Suite No. 3 (for solo cello, arr. Duarte)- Allemande.mp3" ... [/color] which is overwhelming This cleans it up but doesn't give me the artist name and song name I'm looking for. Code: [Select] $xml = simplexml_load_file("load.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } The Output: content auto_play: yes loop: yes volume: 60 artist: artist: artist: My experience with simplexml only goes back a couple of hours so I'm pretty inept at this point. Any help will be greatly appreciated. I just can't wrap my head around it, but I am trying to integrate weather into my website using NOAA. 1. Here is the NOAA page: http://forecast.weather.gov/MapClick.php?CityName=Mio&state=MI&site=APX&lat=44.663&lon=-84.1446 2. Here is the XML to that page: http://forecast.weather.gov/MapClick.php?lat=44.66300&lon=-84.14460&FcstType=dwml Now what I want to do is to have PHP on my website that reads the XML from the NOAA site and create the "Forecast At A Glance". Possible or too challenging? hi i am a making a site in which m saving a songs information in database then fetching that out for inserting song link m using readdir function that read all song in a folder then save them in database but i have problem when that read file name .mp3 also include with that which i don't want to show on page where i fetch that mean simply i want that i can insert song name separately and file separately... and i want to use readdir also for getting file name becoz that easy way instead of upload through panel ..? any idea or solution about adding separately file name Hi all, how do I read emails sent to an email account on my site such as admin@mysite.com? I am trying to go through all of the emails in an inbox with php. I saw a way to do it with imap_open, but I don't have the imap functions installed. Does anyone know of another way to do this? I would think someone would have written a 3rd party library that just uses sockets -- kind of like phpmailer but for receiving instead of sending. Hi there I am working on PHP form which has an array named: $productOptions. When I do: print_r($productOptions); it returns: Array ( [124] => Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) [114] => Array ( [optionId] => 114 [optionName] => acer fast [optionListId] => 28 [dateCreated] => 2010-11-01 02:04:53 [enabled] => 1 [optionQtyId] => 83 [productId] => 40 [quantity] => 0 ) Now from this Array, I would like to check if the quantity if greater than Zero. so I tried: if (productOptions[quantity] > 0){ echo "blah blah..." } But for getting the quantity, the part: productOptions[quantity] returns nothing. Am I doing this correctly? Please reply. Thank you I have been studying PHP for a long time. I can write a simple PHP guestbook now. But you know, it's so so so simply, even the green hand can attack on my site. I want to improve my PHP skill, so i decide to read a big php program such as a shopping cart. Finally i choose the cart Eclime. But when i read the code, i find it's so difficult for me to understand it. Maybe i am in the wrong way to study PHP. Anyone tell me what i should do now ... I am trying to use this weeklyReport1Boles.html: Code: [Select] <html> <head> <title>Weekly Report</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Weekly Report</h1> <p> <form action = "weeklyReport1Boles.php" method = "post" > <p> <input type = "submit" value = "Display the Report" /> </p> </form> </body> </html> TO PULL data from weeklyDataBoles.txt lines 1-8 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 THE RESULTING WEB PAGE SHOULD BE: Weekly Report TOTAL INCOME FROM PAINT CONTRACTS: $0.00 AVG DAILY INCOME FROM PAINT CONTRACTS: $0.00 NUMBER OF DAYS with NO INCOME: . MY PHP CODE IS: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); $total = 0; for ($count= 1; $count <=7; $count = $count +1) { $nextDay = fgets($weeklyDataBoles); $total = $total + $nextDay; } fclose($weeklyData); $avgDailyIncome = $total/7; print("<p>TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."</p>"); print("<p>AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."</p>"); print("<p>NUMBER OF DAYS with NO INCOME: $badDays.</p>"); ?> </body> </html> THE AVERAGES ARE BASED ON ONE WEEK OR SEVEN DAYS, WHY CANT I OPEN THE FILE AND GET THE PROGRAM TO READ IT, I AM A STUDENT AND VERY, VERY, VERY BAD AT THIS, MAKES ME CRAZY CAUSE I REALLY LOVE IT I've never been very good with arrays, and am totally new to them in PHP... If I have this array... Code: [Select] $concertDates = array('201105071'=>'May 7, 2011 (9:00am - 12:00pm)', '201105072'=>'May 7, 2011 (1:00pm - 4:00pm)', '201105141'=>'May 14, 2011 (9:00am - 12:00pm)'); ...and I know the key, e.g. Code: [Select] $concertDate = '201105072' Then how do I get the corresponding value, i.e. Code: [Select] May 7, 2011 (1:00pm - 4:00pm)' ...from the array?? Debbie So here is what I have going. #1 - My weather station software processes a file and enters variables and then uploads it as a php file. #2 - Currently the station also just uploads every file to the site and enters the data in the html, but I would rather have it only upload this one file and the other pages grab data from it and print it out. I have a few php scrips in there to preform certain functions (if temp <= 32 it echos that data in blue and so on) but would rather make most of it php so I have less files being uploaded every 5 minutes. This is what the station sends to the web, but I have no idea how to get the other pages to read it and input the variables from it. hi i tried to add this to my php file Code: [Select] <?php $xfile = @file('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $data = explode("::",$xfile[$random_num]); echo $data[1]; ?> i get no output i then tried just including the txt file like include 'banners.txt'; then everything in the txt file opens. and if i use fopen like this Code: [Select] <?php $xfile = fopen ('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $udata = explode("::",$xfile[$random_num]); echo $udata[1]; ?> i get this error Warning: fopen(banners.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/public_html/template/folder1/main.php on line 72 where as the txt file exist there anyone could help solve my issue? I have created code that allows a table of 'X' rows and 'Y' columns to be made (the user enters the X and Y value) with each table cell being uniquely identified through name as (X, Y). Each cell is has a value of 5 and all cells needs to be filled in before the table is submitted, which is where the problem arises. How exactly would one be able to verify that every cell has been filled and then calculate the sum of all the values entered into the cells for all those which have the same X value? The code to generate the table is as follows: echo "<td align='left'><b>$X<b></td>"; For($Y = 1; $Y <= $num; $Y++) { ?> <td align="center"><input type="text" name="<?php echo "$X,$Y";?>" value="<?php echo 5; ?>" /> </td> <?php } Thanks. I have 4 websites http://www.mercurymagazines.com/pr1/101/101395 http://www.mercurymagazines.com/pr1/169/16000 http://www.mercurymagazines.com/pr1/101/101396 http://www.mercurymagazines.com/pr1/169/16001 I am trying to write a program that will open each webpage one at a time, look for a unique word such as 'FREE' and if it is found the write the URL to a file, if not then no output and the next webpage is opened. I know this word exists only on one of the pages above (http://www.mercurymagazines.com/pr1/101/101396). When http://www.mercurymagazines.com/pr1/101/101396 appears last in the list located in source.txt the programs WORKS. When http://www.mercurymagazines.com/pr1/101/101396 appears in any other position such as first, or second, the program does NOT work. My head is sore from banging against my desk. Any assistance would be appreciated. <?php $file_source = fopen("source.txt", "r"); $file_target = fopen("targets.txt", "w"); while (!feof($file_source) ) { $url = fgets($file_source); echo '<br>'.$url; $raw_text = file_get_contents($url); mb_regex_encoding( "utf-8" ); $words = mb_split( ' +', $raw_text ); foreach ($words as $uniques) { echo $uniques; if ($uniques == 'FREE') { fwrite($file_target, $url); } } } ?> I'm trying to use PHP to read data from EDGAR, the SEC's website for company filings. Filings are in XBRL, a standard for XML. I'm having trouble pulling data using PHP. Here is a link to the data: http://www.sec.gov/Archives/edgar/da...g-20101231.xml Using PHP, I'm trying to get the data from, for example, the following tag: <us-gaap:Assets contextRef="eol_PE633170--1010-K0013_STD_0_20091231_0" unitRef="iso4217_USD" decimals="-6">40497000000</us-gaap:Assets> I've been unsuccessful thus far in getting this data - do you have any suggestions on how to do that? Thank you! |