PHP - Conversion Of Text Data From $variables Issue
ARRAY Example scaled down to two (renamed example only) fields $data = array( "field1" => "Text within quotes processes OK", "field2" => "Text within quotes processes OK" );
The frustating thing has been trying to figure out how to $text1 = $db_field['sampletext1']; $text2 = $db_field['sampletext2']; I have tried: $data = array( "field1" => $text1, "field2" => $text2 ); *** (AND) *** $data = array( "field1 => '$text1', "field2 => '$text2' );
But neither approach works, even though the text in both $data = array( "field1 => "text1", "field2 => "text2" ); I also tried using strval but that did not work.
So how on earth to get the (actual) text from $text1 and
It is probably something simple, so maybe I don't know Thanks for any enlightenent. -FreakingOUT
Edited January 28, 2019 by FreakingOUT Similar Tutorialshow to get text-area text into variable without using <form> i mean can i get through $_GET please provide me solution it needed badly if ((isset($_GET['insertinto'])) &&($_GET['insertinto']=="true")){ if(isset($_SESSION["ajaxtext"])) { unset($_SESSION['ajaxtext']); $mysession = "" ; //my textarea typed data should b here $_SESSION['ajaxtext'] = $mysession ; //insertrow() ; } } print <<<EOD <textarea rows='3' cols='40' id='ajaxtext' name ='ajaxtext'>$mysession</textarea><br> EOD; I'm importing some text files from my windows servers in to a SQL database, but I'm running in to what I think is some sort of issue with either a special character or something to do with UTF-8, or UTF-16... I haven't dealt with this before, so I'm really not even sure. I read in the file as such: $handler = fopen($file, "r"); $Data = fread($handler, filesize($file)); fclose($handler); The text file itself contains the data formatted like this: Quote Unable to deliver this message because the follow error was encountered: "This message is a delivery status notification that cannot be delivered.". The specific error code was 0xC00402C7. The message sender was <>. The message was intended for the following recipients. OnlineHelp@somedomain.com If I simply echo out this data: echo $Data It'll come out in Firefox like the following. And I can see FF is choosing to view it as Western (ISO-8859-1), but if I choose to use Unicode (UTF-16) then the data displays correctly. Quote U�n�a�b�l�e� �t�o� �d�e�l�i�v�e�r� �t�h�i�s� �m�e�s�s�a�g�e� �b�e�c�a�u�s�e� �t�h�e� �f�o�l�l�o�w� �e�r�r�o�r� �w�a�s� �e�n�c�o�u�n�t�e�r�e�d�:� �"�T�h�i�s� �m�e�s�s�a�g�e� �i�s� �a� �d�e�l�i�v�e�r�y� �s�t�a�t�u�s� �n�o�t�i�f�i�c�a�t�i�o�n� �t�h�a�t� �c�a�n�n�o�t� �b�e� �d�e�l�i�v�e�r�e�d�.�"�.� � � � �T�h�e� �s�p�e�c�i�f�i�c� �e�r�r�o�r� �c�o�d�e� �w�a�s� �0�x�C�0�0�4�0�2�C�7�.� � � � � � �T�h�e� �m�e�s�s�a�g�e� �s�e�n�d�e�r� �w�a�s� �<�>�.� � � � � � �T�h�e� �m�e�s�s�a�g�e� �w�a�s� �i�n�t�e�n�d�e�d� �f�o�r� �t�h�e� �f�o�l�l�o�w�i�n�g� �r�e�c�i�p�i�e�n�t�s�.� � � �O�n�l�i�n�e�H�e�l�p�@�E�l�i�t�e�R�a�c�i�n�g�.�c�o�m� � � And finally, if I try to insert the data in to SQL, the data looks like this: Quote INSERT INTO Badmail VALUES( 2 , '00360053425643112201000000004.BDR' , 'U n a b l e t o d e l i v e r t h i s m e s s a g e b e c a u s e t h e f o l l o w e r r o r w a s e n c o u n t e r e d : " T h i s m e s s a g e i s a d e l i v e r y s t a t u s n o t i f i c a t i o n t h a t c a n n o t b e d e l i v e r e d . " . T h e s p e c i f i c e r r o r c o d e w a s 0 x C 0 0 4 0 2 C 7 . T h e m e s s a g e s e n d e r w a s < > . T h e m e s s a g e w a s i n t e n d e d f o r t h e f o l l o w i n g r e c i p i e n t s . O n l i n e H e l p @ S o m e d o m a i n . c o m ' , '2010-11-30 07:17:05' , GETDATE()) So basically, I'm not really sure if I'm supposed to convert the ASCII to UTF-8 or if I just need to do a bunch of str_replace to correct the data before inserting. I'd appreciate any feedback or suggestions anyone has. Thank you. About to pull my hair out. Looks simple, I think it's simple, but something is not behaving. I have a simple login page (loginpage.php) which checks a database for the FamilyID and Password, if it is a match, then it redirects them to userspage.php. I eventually want to use the FamilyID as a filter for my database so I only show the stuff relative to that FamilyID. Using CS5 and the built in functions, and it looks to me that the session variable 'MM_Username' should contain the FamilyID which is "adminid" in my database. It appears to work since it sends me to my userspage.php when I enter a valid FamilyID and Password, but it will not show me my session variable on the that page!!! PLEASE PLEASE HELP...Slap me in the face if it's a stupid question, but I have spent WAY too much time trying to figure what is wrong. I have included my code: CODE FOR LOGINPAGE.PHP <?php require_once('Connections/MyTest.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['familyid'])) { $loginUsername=$_POST['familyid']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "userspage.php"; $MM_redirectLoginFailed = "loginpage.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_MyTest, $MyTest); $LoginRS__query=sprintf("SELECT adminid, password FROM `admin` WHERE adminid=%s AND password=%s", GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $MyTest) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();} //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> <!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> </head> <body> <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>"> <p> <label for="familyid">FamilyID:</label> <input type="text" name="familyid" id="familyid" /> </p> <p> <label for="password">Password:</label> <input type="text" name="password" id="password" /> </p> <p> <input type="submit" name="Submit" id="Submit" value="Submit" /> </p> </form> </body> </html> CODE FOR USERSPAGE.PHP <?php if (!isset($_SESSION)) { session_start(); } ?> <!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> </head> <body> <strong>YOU MADE IT! </strong> <?php echo $_SESSION['MM_Username']; ?> </body> </html> THANKS IN ADVANCED!!! The below works for ?rma=non-returned and &year=$year, however once it's get down to month it doesn't work. Everything seems to be in the proper brackets, but it's still not working. It goes to a blank page when month=$month is added to the URL. The URL looks like this : ?rma=calander&year=2011&month=5 Code: [Select] elseif($_GET['rma']=="calender"){ $sql101010="SELECT DISTINCT rma_year_issued FROM $tbl_name4 WHERE rma_issued='y' ORDER BY rma_year_issued"; $result101010=mysql_query($sql101010); while($row101010=mysql_fetch_array($result101010)){ extract($row101010); $content.='<a href="./acp_admincp.php?rma=calender&year='.$rma_year_issued.'">'.$rma_year_issued.'</a> <br />'; } if(isset($_GET['year'])){ $content=""; $logout.=' | <a href="./acp_admincp.php?rma=calender">Back to RMA Calender</a>'; $rma_year_issued=$_GET['year']; $sql111010="SELECT DISTINCT rma_month_issued FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' ORDER BY rma_month_issued"; $result111010=mysql_query($sql111010); while($row111010=mysql_fetch_array($result111010)){ extract($row111010); if($rma_month_issued=="1"){$rma_month_issued2="January";} if($rma_month_issued=="2"){$rma_month_issued2="February";} if($rma_month_issued=="3"){$rma_month_issued2="March";} if($rma_month_issued=="4"){$rma_month_issued2="April";} if($rma_month_issued=="5"){$rma_month_issued2="May";} if($rma_month_issued=="6"){$rma_month_issued2="June";} if($rma_month_issued=="7"){$rma_month_issued2="July";} if($rma_month_issued=="8"){$rma_month_issued2="August";} if($rma_month_issued=="9"){$rma_month_issued2="September";} if($rma_month_issued=="10"){$rma_month_issued2="October";} if($rma_month_issued=="11"){$rma_month_issued2="November";} if($rma_month_issued=="12"){$rma_month_issued2="December";} $content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'">'.$rma_month_issued2.'</a> <br />'; } if(isset($_GET['month'])){ $content=""; $logout.=' | <a href="./acp_admincp.php?rma=calender&year='.$rma_year_issued.'">Back to RMA Calender Year</a>'; $rma_month_issued=$_GET['month']; $sql211010="SELECT * FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' AND rma_month_issued='$rma_month_issued' ORDER BY rma_date_issued"; $result211010=mysql_query($sql211010); while($row211010=mysql_fetch_array($result211010)){ $content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'&id='.$rma_id.'">'.$rma_number.'</a> <br />'; } } } } The issue maybe the AND in the SQL query... however I need to be sure that the data pulled is of that specific month and that specific year. Not one or the other. I have a table and the structure is Code: [Select] ID, UID, Site, Uname, PassI already have this <?php $result = mysql_query(sprintf("SELECT * FROM Logins WHERE UID = %d", $_COOKIE['UID_WatsonN'])); //check login table against cookie if(($num = mysql_num_rows($result)) > 0){ mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th>ID</th> <th>UID</th> <th>Site</th> <th>Uname</th> <th>Pass</th> </tr> <center> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"ID"); $f2=mysql_result($result,$i,"UID"); $f3=mysql_result($result,$i,"Site"); $f4=mysql_result($result,$i,"Uname"); $f5=mysql_result($result,$i,"Pass"); ?> <tr> <td><?php echo $f1; ?></td> <td><?php echo $f2; ?></td> <td><?php echo $f3; ?></td> <td><?php echo $f4; ?></td> <td><?php echo $f5; ?></td> </tr> <?php $i++; } } ?> which only gets the data from that one person. What is in the table is usernames and passwords for diffrent sites and i want to take all the usernames and passwords and put them into variables to pass on to the login form. When a user logs into my site I was to store the user_name, user_role, and user_id in a session variable, then store this in a regular variable to make querying easier, but I am having issues with my code as its causing issues with my queries. Code: [Select] if (mysqli_num_rows($data) > 0) { //set sessions $row = mysqli_fetch_array($data); $_SESSION['username'] = $row['username']; $_SESSION['user_role'] = $row['role']; $_SESSION['user_id'] = $row['user_id']; //set variables $username = $_SESSION['username']; $user_role = $_SESSION['user_role']; $user_id = $_SESSION['user_id']; } Any ideas whats wrong?! Thanks for the help!! I have two textboxes that inputted time, and I want to get the difference between two time. for example: $IN = 13:35; $OUT = 17:35; $OTHours = ($OUT - $IN); $OTHours = 4.00; and it is correct, but I have a scenario like this: $IN = 21:35; $OUT = 05:35; $OTHours = -16.00; it should be 8.00. Any help is highly appreciated. Thank you.. Hi Everyone, I'm trying to convert my MySql data into variables so I can use them on my website. For example, if I want to convert a city or even first or last name into a variable. How would I go about doing that? Thanks everyone! warning: I'm a self taught advanced newbie. I'm working on a multipage PHP app that has need to pass values between pages, usually very small text strings or small integers. I've designed it primarily using _SESSION variables to pass these bits of data. Some of them are written to SQL, but most of them are temporary in nature. Is using _SESSION variables in this capacity considered reasonable? Is there something else or a different way to go about this? (Page A writes a value into $_SESSION['myvalue'], and then page B grabs that data and does something with it.) Hi All, I have done a select from my DB and the data contains a '. echo "<td><a class='btn btn-primary col-sm-12' data-toggle='modal' data-userid='" . $uid . "' href='#userModal' data-firstname='" . $ufn ."' data-lastname='". $uln."' data-email='" . $ue . "' data-accountlevel='" . $ualid . "' data-mobile='".$um ."'data-role='".$urid."' data-active-sheets='".$ename."'>Manage</a></td>"; outputs <a class="btn btn-primary col-sm-12" data-toggle="modal" data-userid="2" href="#userModal" data-firstname="Chelsea" data-lastname="Hockley" data-email="chelsea@hotmail.com" data-accountlevel="1" data-mobile="0774882" data-role="1" data-active-sheets="A new event,Chelsea" s="" event'="">Manage</a> the issue part data-active-sheets="A new event,Chelsea" s="" event'="" Should be data-active-sheets="A new event,Chelsea's event" How do i prevent the ' from causing me this issue? I'm new to PHP and I have an html page I would like to pull specific data into certain areas on the page that I will modified for php. Here are some details. The page is a static html page that has the prices of 40+ products in a standard <li> list. When I update the prices in our database through our shopping cart, I have to change these prices manually in the html. https://www.novon.co...mic_mixers.html. It would be great if I could link the field for Base_Price in the products table to each affiliated <li> tag, I am pulling all the data I need into ($results) and can display it all but I don't know how to get just the single products Base_Price in my <li> tag. <?=$row['Base_Price'] ?> I know this code is not correct but to get the point across, can I create a variable that I define in each <li> tag with a statement like,,,, <?=$row['Base_Price with Product_Code=123456'] ?> I could create a new SQL query for each <li> like "SELECT Base_Price from Products WHERE Product_Code='123456' ", but that's a lot of calls to the DB and a lot of code on the page. And just so I weed out the hard core coders, I can not rebuild the entire page. This is too big of a project for me and my limited coding with PHP. Can anyone help?? Thanks in advance Michael Hey all, I am having a situation where I have a singleton class with a static array in it. I insert an element into that array, and then I redirect the user to another page. At that page, I then retrieve that array (it's stored in the session vars), but the array is then empty when I retrieve it. I can't figure out why. Here are some pertinent code snippets. First, the class with the static array: class Logger { private static $instance = NULL; private static $messages = array(); //Private constructor to prevent this class from being instantiated multiple times private function __construct() { } //The clone function is private to prevent cloning of this class private function __clone() { } //Returns the singleton instance of this class public static function GetInstance() { if (!self::$instance) { self::$instance = new Logger; } return self::$instance; } public static function GetMessageCount() { return count(self::$messages); } public static function LogMessage($new_message) { self::$messages[] = $new_message; } public static function GetMessages() { return self::$messages; } public static function ClearMessages() { self::$messages = array(); } } Here is the code where I insert something into the aformentioned array (the process is that a user tries to log in, but the login fails, and so we insert a message into the array saying that the login credentials failed). //Retrieve the message logging instance from the session data to be able to pass messages to the user. $message_log = $_SESSION['user_messages']; $user = $_SESSION['user_account']; //Create a new instance of the database management class and //try to connect to the database $dbm = new DBM(); if ( !$dbm->isConnected() ) { $message_log::LogMessage("We are sorry, but we are unable to access the database at this time. Please try again later."); } else { //Retrieve the user login information $useremail_dirty = $_POST['useremail']; $password_dirty = $_POST['userpassword']; //Check to see if the email we were given exists in the database, and if the password matches $doesPasswordMatch = $dbm->doesPasswordMatch ( $useremail_dirty, $password_dirty ); if ( $doesPasswordMatch ) { //Correct login information was received. Login the user and redirect appropriately. $user->Login(); header ( "Location: ".BASE_URL."/userpage.php" ); exit; } else { //If an incorrect email or password was given, report that information to the user. $message_log::LogMessage("Incorrect login information."); } } //The user has failed to login. Redirect to the appropriate page. header ( "Location: ".BASE_URL."/loginfailed.php" ); And finally, given an unsuccessful login attempt, this is where I pick back up the array of messages to display the messages to the user: $message_log = $_SESSION['user_messages']; $all_messages = $message_log::GetMessages(); print $message_log::GetMessageCount()."<br>"; print count($all_messages)."<br>"; foreach ($all_messages as $message_string) { $prepared_string = prepare_text_for_html_output($message_string); echo $prepared_string."<br>"; } $message_log::ClearMessages(); Unfortunately, the "all_messages" variable has nothing in it...it's like the messages that I logged in the previous PHP script never even existed. I am calling session_start, so don't worry about that (even though it's not seen in these code snippets). What could be going wrong? Not sure why this isnt working. Code: [Select] <?php session_start(); ?> <!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> <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script> <script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <LINK REL=StyleSheet HREF="inc/dyn_style.css" TYPE="text/css" MEDIA=screen /> <?php ?> <?php include('logic.inc'); mysqlConnect(); ?> <script type="text/javascript" src="bbeditor/ed.js"></script> <link rel="stylesheet" type="text/css" href="dyn_style.css" /> <title> Social </title> <script type="text/javascript"> function changeTitle(title) { document.title = title; } </script> </head> <body> <?php $inc = 'new_story.php'; $view = 'Newest '; $by = 'added'; $where = " "; $where2 = " "; $order = "ASC"; $gen = "All"; $rat = 'All'; $blerg = ""; $sort = 'newest'; //---------------------------------------------------------------------- if(isset($_GET['sub'])) { $sort = $_GET['sort']; switch($sort) { case "Most Popular"; $by = 'views'; $view = 'Most Popular '; $order = 'DESC'; break; case "Most Reviewed"; $view= 'Most Reviewed '; $by = 'reviews'; $order = 'DESC'; break; case "Newest"; $by = 'added'; $view = 'Newest'; $order = 'ASC'; break; } $genre = mysql_real_escape_string($_GET['cat']); $rating = mysql_real_escape_string($_GET['rat']); if($gen == 'All') { $where = " "; $blerg = ""; } else { $where = "WHERE cat='$gen'"; } if ($rat == "All") { $where2 = ' '; $blerg = 'AND'; } else { $where2 = $blerg ." rating = '$rat' "; } } //---------------------------------------------------------------------- ?> <?php serch(); ?> <form action="story.php" method="get"> <label id='inline'> Order By: </label> <select name='sort'> <option selected='yes' label='Currently Selected' > <?php echo $view; ?> </option> <option> Newest </option> <option> Most Popular</option> <option> Most Reviewed </option> </select> <input type='hidden' value='spec_view' name='p' /> <label id='inline'> Genre/Catagory: </label> <select name='gen'> <option selected='yes' label = 'Selected Genre - <?php echo $gen; ?>'> <?php echo $gen; ?> </option> <option> All </option> <option> Fantasy </option> <option> Adventure </option> <option> Science Fiction</option> <option> Drama</option> <option> Fable </option> <option> Horror</option> <option> Humor</option> <option> Realistic Fiction </option> <option> Tall Tale</option> <option> Mystery </option> <option> Mythology </option> <option> Poetry </option> <option> Shorty Story </option> <option> Romance </option> </select> <label id='inline'> Rating: </label> <select name='rat'> <option selected='yes' label = "Selected Genre - <?php echo $rat; ?>"> <?php echo $gen; ?> </option> <option> All </option> <option> C </option> <option> C13 </option> <option> YA </option> <option> A </option> </select> <input type='submit' value='Go!' name = 'go' /> </form> <?php $query = " SELECT * FROM story_info ORDER BY $by $order $where $where2 "; echo $query; $select = mysql_query($query) or die(mysql_error()); while($rows = mysql_fetch_assoc($select)) { $viewsdb = $rows['views']; $titledb = $rows['title']; $userdb = $rows['user']; $catdb = $rows['cat']; $ratdb = $rows['rating']; $id_db = $rows['story_id']; $sumdb = shorten($rows['sum']); echo "<h3><a href='?p=page&id=$id_db'> $titledb </a> </h3>"; echo "<div id='fun_info'>"; echo "$sumdb <br />"; echo "By <a href='?p=profile&user=$userdb'> $userdb </a> <br /> "; echo "$viewsdb Views | Rated: $ratdb | Catagory: <a href='?p=cat_view&gen=$catdb'> $catdb </a> </div>"; } ?> </div> </body> </html> Hello all, I'm hoping someone can help me out. Here is the code I have for a page that contains a user form: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> And here is the page that the user information is supposed to be passed to: <?php include "include/dbc.php"; include "include/header.inc"; $duration = $_POST["duration['.$row['Name'].']"]; echo '<h1>Added Activities</h1>'; echo $duration; ?> Well, this isn't working for me. The second page code returns this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING When I execute print_r, the values are returned to me. So I have two questions: 1) What do I need to do to change the code on the 2nd page to echo and POST the array? 2)The database contains multiple exercises under the same name. So, when the variables are passed to the 2nd page. All the values are returned regardless of whether they have been filled out or not. What can be done to only returned the user input and not the blank variables? so far I have: $crawler->filter('li.date, dt > a, li.style')->each(function ($node) { $output = $node->text()."\n"; $array = explode("\n", $output); $data = array_chunk($array, 3); // print_r($data); foreach ($data as $row) { [$date, $title, $type] = array_pad($row, 3, null); // here you have your variables print 'Date: '.$date; print 'Title: '.$title; print 'Type: '.$type; } }); and this outputs: QuoteDate: Saturday 13th Jun 2020Title: Type: Date: Alice in Chains UKTitle: Type: Date: Metal/ RockTitle: Type: Date: Monday 29th Jun 2020Title: Type: Date: Cage the ElephantTitle: Type: Date: Funk/ RockTitle: Type: Date: Friday 31st Jul 2020Title: Type: Date: The CureheadsTitle: Type: Date: Indie/ RockTitle: Type: Date: Thursday 20th Aug 2020Title: Type: Date: CreeperTitle: Type: Date: PunkTitle: Type: Date: Saturday 22nd Aug 2020Title: Type: Date: Fleetwood BacTitle: Type: Date: Pop/ RockTitle: Type: Date: Monday 31st Aug 2020Title: Type: Date: GZATitle: Type: Date: Hip HopTitle: Type: Date: Saturday 5th Sep 2020Title: Type: Date: Cock SparrerTitle: Type: Date: Only $date variable is set for each?! please help??
it should be: Date: Saturday 13th Jun 2020Title: Alice in Chains UKType: Metal/ Rock Date: Monday 29th Jun 2020Title: Cage the ElephantType: Funk/ Rock and so on.... For example: I am using this code: Code: [Select] $myFile = "newuser.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData; and it displays: Code: [Select] Bob 2 Which I am reading from my newuser.txt file! Which corresponds to the username bob, and he has the ID of 2. Now I want to make that linkable like this: Code: [Select] <a href=.?act=Profile&id=$IDFROMTEXTFILE(2)>$NAMEFROMTEXTFILE(BOB)</a> this is possible? If so, Thanks! It's been a while since I've dealt with text files and currently I am unable to write the contents of a variable to a text file, only the literal is being written. Should I be de-referencing or is this even possible? Also the problem is compounded by the fact that i also want to write the contents of a class display function into the text file. Any ideas on how to extract text from html like this into multiple variables? Code: [Select] <li class="even" style="padding-top:1.25em"><label for="job_title">Title</label><div>Expatriate Tax Director</div></li> <li class="odd"><label for="job_contract_type">Contract type</label><div>Permanent</div></li> <li class="even"><label for="job_market_sector">Market sector</label><div><a href="/en/candidate/market_sectors/1.html">Accountancy / Auditing / Tax</a></div></li> <li class="odd"><label for="job_country">Country</label><div><a href="/en/candidate/countries/GB.html">United Kingdom <img src='/images/flags/GB.png'/></a></div></li> <li class="even"><label for="job_location">Location</label><div>Reading</div></li> <li class="odd"><label for="job_min_salary">Salary</label><div>120.00 - 120.00 United Kingdom Pounds/Month <li class="even"><label for="job_description">Description</label><div>Expat Tax Director <br/>Circa 120k - UK - Reading <br/> <br/>Our client is seeking experienced tax professional to undertake this central role. This position has evolved due to the firm expanding. The firm now has an immediate need for a very experienced person to direct the team. The ideal individual will have experience in advising International organisations with international tax, cost & risk assessment as well as reorganisations of processes and systems for the management of cross border employees. Business Development skills and good Client Management are essential. <br/>Attractions: <br/>- Combination of HNWI, Corporate Expat Programmes and International Partnerships <br/>- Managing a skilled and established team <br/>- Working within a successful and profitable office <br/>- Central London location <br/></div></li> <li class="odd"><label for="job_expires_on">Expires on</label><div>February 28, 2013</div></li> <li class="even"><label for="job_ideal_candidate">Ideal candidate</label><div>Expatriate Tax</div></li> </ul></div></div><div class="warning">An EU passport or work permit is required for this position. Applicants without one of these will be rejected automatically.</div> Code: [Select] $IP = $_SERVER['REMOTE_ADDR']; $DATE = date("Y-m-d"); $TIME = date("H:i:s"); $NameOfSender = "BLABLABLABALLA"; $email = $fieldnm_3; // use their addy instead of yours $subject = 'ikwerkthuis.be inloggegevens introductie film'; // change subject $text = 'Beste $NameOfSender, Welkom bij ikwerkthuis.be. Hieronder vind U de logingevens voor het bekijken van de introductiefilm: Adres: http://ikwerkthuis.be/index.php/introductie Gebruikersnaam: introductie Paswoord: film2012 %DataOfForm% Wij nemen spoedig contact met u op. Met vriendelijke groeten, Het ikwerkthuis.be team IP: $IP Date: $Date Time: $Time'; // change text mail($email, $subject, $text, 'From: '.$emailadd.''); // send another one out header("Location:$success_page_name"); } ?> <?php error_reporting(0); $servername = "localhost"; $username = "user"; $password = "pw"; $dbname = "news"; $datatable = "ttrss_user_labels2"; // MySQL table name $datatable2 = "ttrss_entries"; $results_per_page = 10; // number of results per page // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?> <?php if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $results_per_page; $sql = "SELECT * FROM ".$datatable2.", ".$datatable." WHERE article_id = id ORDER BY date_entered DESC LIMIT $start_from, ".$results_per_page; $rs_result = $conn->query($sql); ?> <?php while($row = $rs_result->fetch_assoc()) { ?> <?php $title = preg_replace('/[^(\x20-\x7F)]*/','', $row['title']); $content = preg_replace('/[^(\x20-\x7F)]*/','', $row['content']); ?> <table id="news" border="1" cellpadding="1" class="mx-auto col-xs-12 col-sm-12 col-md-12 col-lg-12"> <tr class="wrap"><td class="rounded-lg shadow curved"> <?php echo '<div charset="UTF-16" class ="text-center" style ="font:14px/18px Arial,tahoma,sans-serif top:5px">', $title, '<hr class=mx-auto></div>'; ?> <?php echo '<div charset="UTF-16" class ="text-center" style ="font:11px/21px Arial,tahoma,sans-serif">', $content, ' ', '<a href= "' . $row['link'] . '" target=_blank>Read More</a>', '</div>'; ?> <div style ="font:9px/15px Arial,tahoma,sans-serif" class="text-right"><? echo date('F j, Y g:i a', strtotime($row["date_entered"])) ?><br></div> <? echo '</td></tr></table><br><br>'; ?> <?php }; ?> <!--Grid row--> <div class="row d-flex justify-content-center"> <!--Grid column--> <div class="top_menu col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="container"> <div class="row"><div class="col-md-9"> <ul class="pagination pagination-sm pagination-centered"> <?php $sql = "SELECT COUNT(ID) AS total FROM ".$datatable2; $result = $conn->query($sql); $row = $result->fetch_assoc(); $total_pages = ceil($row["total"] / $results_per_page); // calculate total pages with results $firstPage = 0; // or 1, depending on your implementation $currentPage = (int)$_GET['page']; if ($currentpage != $total_pages) { $nextpage = $currentPage + 1; $prevpage = $currentPage - 1; echo "<li><a href='index.php?page=$prevpage'><<</a></li> "; // for ($i=1; $i<=$total_pages; $i++) { // print links for all pages for($i = $page + 1; $i <= min($page + 4, $total_pages); $i++) { echo "<li><a href='index.php?page=".$i."'"; if ($i==$page) echo " class='curPage'"; echo ">".$i."</a></li> "; }; echo "<li><a href='index.php?page=$nextpage'>>></a></li> "; // echo "<li><a href='index.php?page=$total_pages'>last</a></li></u><br><br>"; } ?> </div></div></div><div class="clearfix">
Hi fellow PHP coders, I have gotten stuck with this code a bit as I was trying to build my first pagination script. I am getting only the 10 latest results from the database on all result pages. I am not sure what exactly I did wrong in this code to make it show all the results database has to offer spanning across pages at a rate of 10 per page from most current first to the oldest. Anyone have any ideas what I am doing wrong here? Any suggestions are much appreciated.
|