PHP - Read Text From Database
hi i was wondering if anyone has any idea how to read text from a database and if that text = "mytexthere" then goto header("Location: index.php"); sorry i have no code on this post reason is all the code i have tried on my own is crap
Similar TutorialsHi On my xampp server's database I get the warning that my database is read-only when I try to insert something into a table. I think I may know what cause this, because I created an export/import app that exports/import important data to the database... How can I remove the read-only from the database, because I am scared that the same thing might happen to my server's database? And is there a mysql query that test if the database is read-only? Thanks in advance I am new to PHP and currently trying to develop a website... i am stuck at one place. Lets say i'm a user(mrX) that has 4 types of car that are Ferrari, Lamborghini, Evo and BMW. So, i will register to the system about my details and all of my car info such as their cc, transmission, plat number, engine capacity. Then, i will log on into the system and after log on, there will be a drop down list. If i pick Ferrari for example, under the drop down list there will be all the information about the car. The same on the other car also. Hello PHPfreaks members, I want my PHP coding to read/fetch my database's first attribute/entry like the first number of the client in that first row and then fetch it to be shown on PHP so that it will show '1'. How would I do that? Here's the table of my example database (MySQL) I know the command to select the line via the database is this: SELECT * FROM CUSTOMER WHERE CUST_NO=1; Hello, Sorry for my english... Well, I make a smaill website. members has to login and then member can see pictures (saved in a folder). When the admin upload pictures a folder wil be created. To get the actual folders in the "album" folder I use this code. <?php //get the folders $handle = opendir(realpath('../album/Album/.')); while ($direc = readdir($handle)) { if($direc == '.' || $direc == '..') continue; else { echo "\t\t<input type='checkbox' name='map[]' id='map[]' value='" . $direc. "' />" . $direc . "<br />\n"; } } closedir($handle); ?> The admin has to assign the folders wich are allowed to see by a member. I use checkboxes for that. And now my problem: When a member can see folder 1 to 4 and the admin upload 2 new folders and want to give that member to see these 2 new folders I want the following: 6 checkboxes (checkbox 1 > album 1, checkbox 2 > album 2... etc). As is said, this member can see folder 1 to 4, so in the CMS album 1 to 4 has to be checked ans album 5 to 6 not. This is my code for that: <?php $sql2 = "SELECT url FROM url WHERE gebruiker_id =" . $_GET['id'] . " ORDER BY url ASC"; $res2 = mysql_query($sql2); while ($rij = mysql_fetch_array($res2)) { $url = $rij['url']; // mappen ophalen $handle = opendir(realpath('../album/Album/.')); while ($direc = readdir($handle)) { if($direc == '.' || $direc == '..' || $direc == $url) { continue; } echo "\t\t<input type='checkbox' name='map[]' id='map[]' value='" . $direc. "' />" . $direc . "<br />\n"; } closedir($handle); } ?> Now my output is: <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 3' />album 3<br /> <input type='checkbox' name='map[]' id='map[]' value='album 4' />album 4<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> <input type='checkbox' name='map[]' id='map[]' value='album 1' />album 1<br /> <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 4' />album 4<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> <input type='checkbox' name='map[]' id='map[]' value='album 1' />album 1<br /> <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 3' />album 3<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> What do I have to do to check the checkboxes (album 1-4) and not to check the album 5-6??? My guess it has to do with the While in While loop but... Greetings, Ferdi I have a MySQL database with each record of a person who has registered for an event, I am displaying the information on a web page for a user, but he wants to be able to print out all the records in alphabetical order by last name, first name later on so he will have a hard copy of each person who has registered at the table when they arrive. How can I write each record to a Txt file that he can print out later that will be formated with the record contents along with each fields definition (Ex. Last Name - Smith, First Name - John, etc)? This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=319147.0 I have a text box on page 1 that has a unique changing value using
$Comment_Name = dechex(time()); $_SESSION['COMMENT_NAME'] = $Comment_Name; // Lines 42/43
Comment As the name of the text box is stored in a session variable then it should be a simple mater of retrieving the value on page 2. /****************************/ $CommentID = $_SESSION['COMMENT_NAME']; if($direction == "Add record") { $Comment_Name = $_SESSION['COMMENT_NAME']; $_SESSION['DE_MyReason'] = $_POST['Reason']; // Keep the default regardless $_SESSION['DE_Money_In'] = $_POST['MoneyIn']; $_SESSION['DE_Money_Out'] = $_POST['MoneyOut']; $_SESSION["DE_DD_Entry"] = $_POST['DD_Entry']; $_SESSION["DE_MM_Entry"] = $_POST['MM_Entry'];
$_SESSION["DE_Comment"] = $_POST[$CommentID]; /* This should retreve the posted value */
Any help on this please? Edited June 24, 2019 by Paul-DHey, I'm looking for some PHP code which can read a certain text file i have. I need to get certain information from this text file. This is how the text file looks like: metadataIngester: now executing performAction with token: 9188147351 metadataIngester: result of performAction with token:9188147351 metadataIngester: runtime (ms) for token 9188147351: 9953 inferencer: now executing performAction with token:9188147351 inferencer: result of performAction with token:9188147351 inferencer: runtime (ms) for token 9188147351: 10903 transcoder: now executing performAction with token:9188147351 transcoder: result of performAction with token:9188147351 transcoder: runtime (ms) for token 9188147351: 65456 transcoder: now executing performAction with token:9188147351 transcoder: result of performAction with token:9188147351 transcoder: runtime (ms) for token 9188147351: 83128 streamingServerTransfer: now executing performAction with token:9188147351 streamingServerTransfer: result of performAction with token:9188147351 streamingServerTransfer: runtime (ms) for token 9188147351: 12187 middlewa now executing performAction with token:9188147351 middlewa result of performAction with token:9188147351 middlewa runtime (ms) for token 9188147351: 28148 Now, there are more parts like this with an other tokenID & runtimes. I need to get the runtime for each token (in this example it will be 9953 + 10903 + 65456 + 83128 + 12187 + 28148 = 209775 (ms)). I need PHP to display the tokenID + the total time per token. I am wanting to display large text blocks from a database but i would like to stop the text if its longer than 600 characters and display Read more... as a link. Can someone please help me? Hi to all!! I am still new to php.. I need help in reading my text file and inserting it to mysql database. My text file contains 5 fields and has several rows.. The format of my text file: 1 romeo 8877 2010-07-07 abc1 2 nick 7686 2010-07-07 abc2 3 mark 5456 2010-07-07 abc3 4 karm 3432 2010-07-07 abc4 The first field is an INTEGER, the second third fifth fields are VARCHAR and the fourth field is a DATE. I am having trouble with my php code.. My code is this: <?php mysql_connect("localhost","root",""); mysql_select_db("personss"); $textFileName = $_POST['textFileName']; $myFile = "$textFileName"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); $person = explode("\n", $theData); $count = 0; foreach($person as $i => $line) { $nameParts = explode(" ", $person[$count]); $q = "insert into logged (id, name, num, datess, letters) values ('" . implode("','",$nameParts) . "')"; $rw = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); } ?> This code can insert to the database but it only inserts the first row and it loops the insert according to how many rows there are in the text file..For example in my text file there are are 4 rows, it inserts the first row: 1 romeo 8877 2010-07-07 abc1 4times..If there are 6 rows, 6 times the first row will also be inserted.. What i need Sir's is that i need to be able to insert the rows line by line.. if there are 4 rows, i need to insert them all in the database.. Please help me to fix the code. I very new to php and all I am simply trying to do is read the contents of a text file and echo it out on the screen. I have tried many things to see what I am doing wrong but it just simply isnt working for me. I know the server I am using has php enabled as well because I have tried a simple echo and it works fine. This is the code I am currently using. <?php $file = fopen(file.txt", 'r'); $read = fread($file, '6') echo $read; ?> also, I have tried this. <?php $file = file_get_contents('file.txt'); echo $file; ?> I have a file.txt on the server I am using in the same directory as index.php, I feel like this should be working but I get no result! Alls I have in the text file is a statement that says "hello world". I'm trying to retrieve the text from a text area and put this in a PHP variable without submitting the form. The text is provided by a database and I want to format it for the user. How can I do this with PHP? So basically: Code: [Select] <form id="createForm" name="createForm" method="post" action=""> <textarea name="subjectTextArea" id="subjectTextArea" cols="45" rows="5"> This is the text I want to put in a PHP variable before the form is submitted. </textarea> </form> <?php $txtArea = ? ?> Thanks for the help. I need to search through a text file and output certain text. My current script doesn't work well at all. Code: [Select] <? $file = 'flist.txt'; $handle = @fopen($file, "r"); $names = array(); $func = array(); $desc = array(); $nme; $fnc; $dsc; $s = -1; $e = -1; $n = 0; if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { if($nme == 0) { if(strpos($buffer,"<a name") !== false) { $nme = 1; $s = strpos($buffer,"<a name"); } } else if($nme == 1) { if(strpos($buffer,"</span>") !== false) { $nme = 2; $e = strpos($buffer,"</span>"); $num = $e - $s; $names[$n] = strip_tags(substr($buffer,$s,$num)); } } else if($nme == 2) { if($fnc == 0) { if(strpos($buffer,"<table style") !== false) { $fnc = 1; $s = strpos($buffer,"<table style"); } } else if($fnc == 1) { if(strpos($buffer,"</td>") !== false) { $fnc = 2; $e = strpos($buffer,"</td>"); $num = $e - $s; $func[$n] = strip_tags(substr($buffer,$s,$num)); } } else if($fnc == 2) { if($dsc == 0) { if(strpos($buffer,"<p>") !== false) { $dsc = 1; $s = strpos($buffer,"<p>"); } } else if($dsc == 1) { if(strpos($buffer,"</p>") !== false) { $fnc = 0; $nme = 0; $dsc = 0; $e = strpos($buffer,"</p>"); $num = $e - $s; $desc[$n] = strip_tags(substr($buffer,$s,$num)); } } } } } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); $n = 0; while($n < 100) { echo $names[$n] . "<br>"; echo $func[$n] . "<br>"; echo $desc[$n] . "<p>"; $n ++; } } ?> 4096 gets the data for each line, right? Well some of my data uses two lines. After all the searching is done I need it to output $names, $func, and $desc in plain text. First, my goals: - The user selects a text file on their local PC (or their local network drive) to process. - I want to read the file into an array and process it. I'm having trouble with this. Here is my code so far: <?php session_start(); $title='Import File v.10a'; ?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php echo '<title>'.$title.'</title>'; ?> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php require_once('navmenu.php'); echo '<h2>'.$title.'</h2>'; ?> <!-- comment --> <?php // Connect to the database $dbc = mysqli_connect($host, $user, $password, $database); $errcnt=0; $models=array(); //Init array $bullarr=array(); $model=''; $partname=''; $partsubname=''; $image=''; $ptype=''; //Product type in {type} tag. if (isset($_POST['cmdImport'])) //Save records that were changed. { $filename=$_POST['txtFilename']; //File on user's machine. $s='You are importing '.$filename; crDebug($s); //DEBUG if (move_uploaded_file($_FILES['txtFilename']['tmp_name'], 'upload/')) { $filename=$_FILES['txtFilename']['name']; $s='Received '.$filename; crInfomsg($s); } else { $errmsg='File upload failed. Error is '.$_FILES['txtFilename']['error']; crError($_SERVER['PHP_SELF'].' line '.__LINE__,$errmsg,true); } if (!(file_exists($filename))) { $errmsg='File '.$filename.' does not exist. Cannot continue.'; crError($_SERVER['PHP_SELF'].' line '.__LINE__,$errmsg,true); } else { } } //if isset($_POST['cmdImport'] ?> <!--------------------------------------------------------> <form action="<?php echo $_SERVER['PHP_SELF'].'?'.SID; ?>" method="post"> <hr/> <label for="cbxBrand">Pick one Brand</label> <?php $oldbrandarr=array(); //Init array. //Do query and loop here. //Show brands from zzbrands. $query = "SELECT bzz ". "FROM zzb ". "ORDER BY br ". ";"; //crInfomsg($query); //DEBUG crCreateSelect($query, 'cbxBrand', 'brand') ?> <p>Input file: <input type="file" name="txtFilename" id="txtFilename" value="" size="80" /> <br/><input type="submit" value="Import" name="cmdImport" /> </form> </body> </html> My problem is I get an error each time "File upload failed" which is displayed above when I try to do move_uploaded_file(). I'm not experienced processing text files. Can someone help me or point me to a website? One more thing, the subdir "upload" is located at the same level as this php file. That is where the uploaded files will go temporarily. I have the following text file: Code: [Select] 09/16/2011 - 09/16/2011 323780048 FedEx Ground Shipment Detail Report 09/22/2011 CAFE2472 Page: 1 TRACKING # RECIPIENT CD ZIP ZN CARRIER SVC BILL WGT COD DECL VALUE C GR CHG C SRCHG C NET ---------------- --------------- ------ --- ------- - --- -------- ---------- ---------- ---------- ---------- ---------- 561895962528473 97913 440607 4 Ground , RH 2.0 0.00 99.00 6.22 2.45 8.27 561895962528480 97928 352424 5 Ground , RH 17.0 0.00 99.00 9.89 2.45 10.60 561895962528497 97943 857164 6 Ground , RH 17.0 0.00 99.00 12.38 2.45 14.75 561895962528503 97955 193825 5 Ground , RH 4.0 0.00 99.00 7.17 2.45 8.42 561895962528510 6792 491069 3 Ground , RH 3.0 0.00 99.00 5.97 2.45 8.27 561895962528527 97967 030703 5 Ground , RH 1.0 0.00 99.00 5.75 4.10 10.06 561895962528534 97978 665429 4 Ground , RH 4.0 0.00 99.00 6.86 4.10 10.06 561895962528541 97992 371844 4 Ground , RH 1.0 0.00 99.00 5.51 4.25 10.22 561895962528558 98005 386108 4 Ground , RH 18.0 0.00 99.00 9.21 4.25 12.01 GRAND TOTALS COURTESY NET CHARGE 92.66 TOTAL WEIGHT(OF LBS) 63.7 TOTAL WEIGHT(OF KGS) 0.0 CSY DECL VAL SCHG 0.00 COURTESY DISCOUNT 12.52 COURTESY SPECIAL FEES 28.95 CSY FUEL SURCHARGE 7.27 PACKAGE COUNT 9 And I'm attempting to pull ONLY the tracking number and reference number (or order #) from this file. I've been able to get rid of the empty lines, get rid of the first few lines I don't need and grab just tracking and reference numbers , but I can' t figure out how to get rid of of the last few lines....here's my code: Code: [Select] $arr=file("/home/onest4/public_html/beta/fedex.txt"); $x=1; foreach($arr as $str) { if (trim($str) != '') if ($x > 3) { list($tracking,$ordernumber)=explode(" ",$str); echo $tracking; echo "<br />"; echo $ordernumber; echo "<br /><br />"; } else { $x++; continue; } } Here's the result: Code: [Select] 561895962528473 97913 561895962528480 97928 561895962528497 97943 561895962528503 97955 561895962528510 6792 561895962528527 97967 561895962528534 97978 561895962528541 97992 561895962528558 98005 GRAND TOTALS COURTESY NET CHARGE TOTAL WEIGHT(OF LBS) TOTAL WEIGHT(OF KGS) CSY DECL VAL SCHG COURTESY DISCOUNT COURTESY SPECIAL FEES CSY FUEL SURCHARGE PACKAGE COUNT Anyone help with this? Thanks! I have a PHP file that is executed via batch file very frequently for live updating. This is a sort of "sync" file for reading/writing to a MySQL database. I am able to get it functioning absolutely fine when executed manually via a web browser (and my echo debug lines output the expected information), yet when I run the same PHP file via the command line, it seems to just not be capable of opening any file for reading, so the equivalent variables that are correct when executed on a web browser are blank when echoed through the command line. Is there a different way of handling reading of files when running a php script via the command line, or should it function exactly the same as when run via a browser? For instance: $k = "0"; $line = file("examplefile.log")[$k]; echo $line; Hello,
I try to get website speed of some website, but i can read only ''domain.com'' i can't read website files like css , js ... why ? i use proxies for this job.
here is the php code:
$options = array( 'useragent' => "Firefox (+http://www.firefox.org)", // who am i 'connecttimeout' => 120, // timeout on connect 'timeout' => 120, // timeout on response 'redirect' => 10, // stop after 10 redirects 'referer' => "http://www.google.com", 'proxyhost' =>'85.25.8.14:80' ); $response = http_get("http://solve-ict.com/wp-content/themes/ict%20theme/js/jquery-1.7.1.min.js", $options , $info);but it works fine with http://domain.com/ , but with files css or js it gives 404, using some free proxy servers available ? Thanks. Trying to get this done: Page_1 has many external links, when certain links are clicked i do not want user to go directly to page, but rather go to a special add page_2 where user must click a second time on the link to finally get there. The add page_2 must show on screen the name of the initial link from page_1, it must change accordingly with the link it came from page_1,once on page_2 the hyperlink redirects outside the site. So far i am thinking give an id to the div or "<a href..." on page_1 then somehow have page_2 detect that id and fill in the variable for the final external link. Other wise is there a way to detect a url from incoming? I guess a similar example is how some domain name sellers landing page will indicate the name of the site. Such as "Thisdomain.com" is for sale. same landing page but the name changes according to the domain that was typed. I got a question im using izabi for me im one who loves the software. But there some quirks that they forgot to add when making the mail system. I was wondering how it would be possible to code in a peice of php where it says read after someone read the email. If you need a copy of the mail mail script let me know. Hi, very new to all this, so don't really know too much! I have been trying to edit some code to be able to retrieve some blocks of text from a database, then edit them and post them back. I have managed to retrieve them, however I can't seem to be able to post them back to the database edited. This is the code I'm using: Code: [Select] <?php require_once('config.php'); $con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); if (!$con){ die('Failed to connect to server' . mysql_error()); } mysql_select_db(DB_DATABASE); $ide15 = $_POST[idf]; $query15 = "SELECT id,titleus,aboutus FROM about WHERE id = 1"; $result15 = mysql_query($query15) or die ("Query:<br />$query15<br />Error:<br />".mysql_error()); while ($row15 = mysql_fetch_assoc ($result15)) { $title15 = htmlentities ($row15['titleus']); $news15 = nl2br (strip_tags ($row15 ['aboutus'], '<a><b><i><u>')); echo "<form class ='addform' action='editabouttext.php' enctype='multipart/form-data' method='post'>"; echo "<p>Uttsav Title:<br /><input class='titlefield' type='text' name='title' value='$title15' /></p><br />"; echo "<p>Uttsav About:<br /> <textarea name='news' rows='1' cols='15'>$news15</textarea></p><br />"; echo "<p><input name='submit' type='submit' value='Submit' /></p>"; echo "</form>"; } if ($_POST['submit']) { mysql_select_db(DB_DATABASE); $upid = $_POST[idf]; $uptitle = $_POST[title]; $upnews = $_POST[news]; $upimage = $_FILES['userfile']['name']; $sql = "UPDATE about SET titleus = '$uptitle', aboutus = '$upnews', WHERE id = '1'"; mysql_query($sql); if ($_POST['submit']) { echo "<p class='admintext'>Your project thumbnail has now been edited - <a href='about.php'>View The About Page</a></p><br />"; $name = $_FILES['userfile']['name']; $type = $_FILES['userfile']['type']; $size = $_FILES['userfile']['size']; $tmpname = $_FILES['userfile']['tmp_name']; $ext = substr($name, strrpos($name, '.')); if (strstr($type, "image")) { move_uploaded_file($tmpname, "images/portfolio/".$name); } } } ?> I am using an apache server at the minute and have had this code working for other pages and scenarios, yet can't get it working on this, I think it may have something to do with the id of the post, but as I am only going to be using one post that will just get edited I took out the WHERE id = $ide15 and put in WHERE id = 1 as this is the id of the only post! Any help would be much appreciated! as I said, just starting to get to grips with things like this! Thank you Martin |