PHP - Input And Output Array... I Think
I'm kind of a beginner, but I really need this script and I'm not sure how quite to do it as needed...
With some html forms I need it so you can type a name in then click submit, then (with php) it will save that text into a text file or something. Later, when I hit a different button it will randomly display one of those texts/names from before. Similar TutorialsAfter inputing my email and password and clicking submit, the echo in Verify_User (in bold) doesn't show up, nor does it load the logged in form of the log in bar. If I reload the page or press submit again (even without entering any information), everything works. At first I though I might just be outputting before getting my input on the reload, but all info is obtained at the top. I also thought it might be $logoff, but it doesn't tell me "You logged off!", while still setting $logoff to true by the end in order to output the login menu. Therefore, it get's passed if($Logoff) but doesn't make it to Verify_user, so for some reason $L_Email and $L_Password aren't set after the first refresh. I'm a newbie so any help, related to the problem or not, would be greatly appreciated. P.S. The logoff button works the first time. Code: [Select] <?php $L_Email = $_POST['l_email']; $L_Password = $_POST['l_password']; $Logoff = $_POST['logoff']; //if the page was requested with an effort to logoff if ($Logoff) { //setcookie("session_email", "", time()-3600); setcookie("session_password", "", time()-3600); } //if logging in, Email and password are already set, make them cookies else if($L_Email && $L_Password) { setcookie("session_email", $L_Email, 0); setcookie("session_password", $L_Password, 0); } $L_Email = get_email_cookie(); $L_Password = get_password_cookie(); $logbar_html = ""; if($Logoff) { $logbar_html = $logbar_html . "You logged off!<br>"; } else { //if there was a cookie or apt input if ($L_Email && $L_Password) { //if logged on if(verify_user($L_Email, $L_Password)) { $logbar_html = $logbar_html . "Hello $L_Email!<br>"; $logbar_html = $logbar_html . "<form action='index.php?at=". $_GET['at'] . "' method='post'> <input name='logoff' type='submit' value='logoff'> </form>"; $logbar_html = $logbar_html . "<a href='index.php?at=edit_account'><text size=1>Edit your account!</text></a><br>"; if ($L_Email == "scott.jaromin@gmail.com") { echo "<a href='index.php?at=admin'>Admin</a>"; } } else { $logbar_html = $logbar_html . "Login Failed<br>"; $Logoff=true; $L_Password=NULL; } } //if this, you are definitely logged off else { $Logoff = true; } } //if you are logged off if($Logoff) { $logbar_html = $logbar_html . "<a href='index.php?at=register'><text size='0'>Register!</text></a><br> <form action='index.php?at=". $_GET['at'] . "' method='post'> Email: <input name='l_email' type='text' value='$L_Email'/><br> Password: <input name='l_password' type='password' /> <br> <input type='submit' /> </form> "; } function get_email_cookie() { $email_cookie = ""; if(isset($_COOKIE["session_email"])) { $email_cookie = $_COOKIE["session_email"]; } return $email_cookie; } function get_password_cookie() { $password_cookie = ""; if(isset($_COOKIE["session_password"])) { $password_cookie = $_COOKIE["session_password"]; } return $password_cookie; } function verify_user($email_check, $pass_check) { echo "verifying $email_check $pass_check"; $con = mysql_connect("my", "info", "only"); if (!$con) { die("Could not connect: " . mysql_error()); } mysql_select_db("begood4u_barter", $con); if(!$email_check || !$pass_check) { return false; } $result = mysql_query("SELECT Password FROM Members WHERE Email='$email_check'"); $real_pass = ""; if($row = mysql_fetch_array($result)) { $real_pass = $row['Password']; } else { echo "$result"; } echo " real pass: $real_pass"; mysql_close($con); return($pass_check == $real_pass); } ?> Hello all, I have yet again trouble finding a logical solution to my problem. I'm fetching an array which can hold 1 or more values. The problem is, I want these values to ouput in my json_encode function, but this also needs to happen dynamically depending on the amount of values. I can't explain it further, so here's the code so far: Code: (php) [Select] $files = mysql_fetch_array($get_files); $a = count($files); $i = 1; while ($files) { $variablename = 'fileName' . $i; $$variablename = $files['fileName']; $i++; } $output = array( OTHER VALUES , 'fileName1' => $fileName1, 'fileName2' => $fileName2, 'fileName3' => $fileName3, ............); // How do I add the fileNames dynamically depending on how many there are? This got me thinking, I also need to dynamically GET the values with jQuery. How would I do that, when the above eventually works? Thank you. function showCart() { global $db; $cart = $_SESSION['cart']; $output[] = '<div align="center"><table cellpadding="1" cellspacing="1" bgcolor="#666666" width="400">'; $output[] = '<tr bgcolor="#FFFFFF" valign="middle">'; $output[] = '<td width="70" align="center">Titlu</td>'; $output[] = '<td width="90" align="center">Imagine </td>'; $output[] = '<td width="60" align="center">Pret</td>'; $output[] = '<td align="center">Sterge Produs</td>'; $total += $price * $qty; $output[] = '</tr>'; $output[] = '</table>'; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="http://www.sprayart.info/new/sprayart.php"><div align="center" name="trimite" id="trimite"><table width="400">'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM com_images WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr bgcolor="#FFFFFF">'; $output[] = '<td width="70"> <input type="hidden" name="title[ ]" value="'.$title.'" size="5" maxlength="5" /> <input type="text" value="'.$title.'" size="5" maxlength="5" disabled="disabled" /></td>'; $output[] = '<td width="90" align="center" valign="middle"><img src=../../'.$thumbnail.'> </td>'; $output[] = '<td width="60" align="center">'.$price.'</td>'; $output[] = '<td ></td>'; $total += $price * $qty; $output[] = '<td width="50"><a href="cart.php?action=delete&id='.$id.'" class="r"><img src="../../media/sterge.jpg"></a></td>'; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<hr>'; $output[] = '<p align="right">Total De plata: <strong>'.$total.' RON</strong></p></div>'; $output[] = '<table border="0" width="444" id="table29" cellspacing="0" cellpadding="0" background="#BASE_URL#media/comand_form.gif" height="322"> <form action="#BASE_URL#sprayart.php" method="post" name="trimite" id="trimite"> <tr> <td width="25"></td> <td width="71" class="text_negru_left_25"><span class="style4">*</span> Nume:</td> <td width="146"><input name="nume" type="text" class="text_negru_fild_19" /></td> <td width="170"></td> <td width="32"></td> </tr> <tr> <td width="25"></td> <td class="text_negru_left_25"><span class="style4">*</span> Adresa:</td> <td ><input name="adresa" type="text" class="text_negru_fild_19"></td> <td width="170"></td> <td width="32"></td> </tr> <tr> <td width="25"></td> <td class="text_negru_left_25"><span class="style4">*</span> E-mail:</td> <td ><input name="email" type="text" class="text_negru_fild_19" /></td> <td width="170"></td> <td width="32"></td> </tr> <tr> <td width="25"></td> <td class="text_negru_left_25"><span class="style4">*</span> Telefon:</td> <td ><input name="telefon" type="text" class="text_negru_fild_19" /></td> <td width="170"></td> <td width="32"></td> </tr> <tr> <td width="25" height="139"></td> <td colspan="3" class="text_negru_left_25"><span class="style4">*</span> <textarea name="mesaj" cols="44" rows="7" ></textarea></td> <td width="32"></td> </tr> <tr> <td width="25" height="39"></td> <td colspan="2" valign="top" class="text_negru_left_25"></td> <td valign="top" class="text_negru_left_25"><input style="BORDER-RIGHT: #3a3a3a 1px solid; BORDER-TOP: #3a3a3a 1px solid; FONT-SIZE: 8pt; FLOAT: right; BORDER-LEFT: #3a3a3a 1px solid; COLOR: #b1b1a7; BORDER-BOTTOM: #3a3a3a 1px solid; FONT-FAMILY: Verdana; BACKGROUND-COLOR: #3a3a3a" type="submit" class="buton" name="trimite" value="Trimite" /></td> <td width="32"></td> </tr></table></form>'; how can i get the "title" for all products ! if i buy one its ok it will send me in email, but if is more products i get only the last added product!! Please help thank you ! I am trying to work on a code for php where you first have a form that asks the user to input a message then input a color. When they click the submit button it takes them to the output page. It should take their message and output it into boxes in a square. And the background should turn the color that they types in. The below is outputting: Array Fatal error: Unsupported operand types in /home/zyquo/public_html/area51entertainment.co/maintenance/home.php on line 28 So clearly $project_row_num is coming out as an array, and the multiplication is failing because its got a string not a number. I just don't see why it's getting an array out of $project_row_num. <?php $num_projects=15; $scroller_projects=""; require_once 'db_select.php'; $project_query_num="SELECT COUNT(*) FROM $tbl_name"; $project_result_num=mysql_query($project_query_num); $project_row_num=mysql_fetch_assoc($project_result_num); echo $project_row_num; //if($project_row_num <= $num_projects){ $project_query="SELECT * FROM $tbl_name"; $project_result=mysql_query($project_query); /*} else{ $project_query="SELECT * FROM $tbl_name WHERE project_release_date BETWEEN $start_date AND $end_date LIMIT 0,$num_projects"; $project_result=mysql_query($project_query); }*/ $i=1; while($project_row=mysql_fetch_array($project_result)){ extract($project_row); $scroller_projects.='<div class="project_entry" tabindex="'.$i.'" onclick="sndReq(\''.$project_id.'\');">Test</div>'; $i++; } if($project_row_num==""){ $films_row_num=$num_projects; } $scroller_width=$project_row_num*114; $content=' <div class="video_scroller_wrapper"> <div class="video" id="tabs"> </div> <div class="recentfilms_wrapper"> <div class="left_arrow"><img src="arrow_left.png" alt="Left" title="" class="arrow_left" onclick="jumpLeft(\'recentfilms\')" onmouseover="startScrollLeft(\'recentfilms\')" onmouseout="stopScroll()" /></div> <div id="recentfilms"> <div id="scroller" style="width: '.$scroller_width.'px;"> '.$scroller_projects.' </div> </div> <div class="right_arrow"><img src="arrow_right.png" alt="Left" title="" class="arrow_right" onclick="jumpRight(\'recentfilms\')" onmouseover="startScrollRight(\'recentfilms\')" onmouseout="stopScroll()" /></div> </div> </div> <div class="news_wrapper"> <div class="news"> <div class="news_title"><span class="category_title_text">Latest News</span></div> <div class="news_text"> <iframe src="http://www.indiegogo.com/project/widget/75876?a=9030" style="width: 224px; height: 429px; position: relative; left: 3px; top: 15px; border: 0px; overflow: hidden;"></iframe> </div> </div> </div> '; ?> Hi all I am having massive problems comparing the out put of array, basically my end result is to choose a selected option on a drop down in a form. I am trying to compare the output of ['allow-nether'] which is either true or false in my file. Here is what I have tried //code to get file contents Code: [Select] $file_handle = fopen("saves/server.properties", "rb"); $vars = array(); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); //if date not required if ( !isset($parts[1]) ) { continue; } $vars[$parts[0]] = $parts[1]; } Code: [Select] <?php //allow nether =false in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> which outputs: Code: [Select] 1 false 2 selected="selected" and if I set the file to allow-nether=true Code: [Select] <?php //allow nether =true in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> Gives: Code: [Select] 1 true 2 selected="selected" What am I doing wrong? Hi,I
I'm trying to setup Paypal Pro on a website - have everything working - but need to grab the 4th & 6th key values from the results given from the Paypal response and having difficulty with the task.
See the code that prints the response and the response sent from Paypal below - I need to grab the values for [TRXRESULT] and [TRXRESPMSG]
echo('<pre>'); print_r($PayFlow->getResponse()); echo('</pre>');and here's the response I get from Paypal on script execution - this is an example of a failed transaction: Paypal Response Array ( [RESULT] => 36 [RPREF] => RPC5B24581A2 [RESPMSG] => Transaction failed: Fail to obtain approval for the online transaction [TRXRESULT] => 23 [TRXPNREF] => EUJPC36F2092 [TRXRESPMSG] => Invalid account number: Unsupported Credit Card type )Again, I want to grab the values from [TRXRESULT] and [TRXRESPMSG] and assign them to local variables so i can work with them within the local php script. Example: $trxresult and $trxrespmsg Here's part of the class (file name is Class.Payflow.php find on Github) that pertains to this snippet of code in question: Class.Payflow.php /** * @uses Gets the response from Paypal. * @access Public * @param None. * @return Array/String - Returns an array of Paypal's response or empty string if not return. * @example $PayFlow->getResponse(); */ public function getResponse() { if($this->response) { return $this->response; } else { return ''; } }Thanks in advance for help w/this one! Hi all What I am trying to achieve is a for each loop for the following output Code: [Select] Array ( [result] => success [source] => getDirectory [success] => Array ( [0] => /root/mc/world/data/ [1] => /root/mc/world/level.dat [2] => /root/mc/world/level.dat_old [3] => /root/mc/world/players/ [4] => /root/mc/world/players/herghost.dat [5] => /root/mc/world/region/ [6] => /root/mc/world/region/r.-1.0.mcr [7] => /root/mc/world/region/r.0.0.mcr [8] => /root/mc/world/session.lock [9] => /root/mc/world/uid.dat ) ) How would I go about saving each path from the [success] output? Basically I wish to loop through the array and delete the files. Many Thanks I have an array and I would like to insert commas and the word 'and' to make a sentence using an array. For example... $sports = array(baseball, soccer, tennis); Ted played baseball, soccer and tennis or Ted played baseball, soccer, boxing and tennis What's the best way to do this? Hi, got a problem with my arrays, every string gets duplicated 11 times instead of just one time. How to fix this? I came up with this but it outputs the value 3 times... (because there are 3 variables) ie mathsmathsmaths How do I fix this or do it the correct way? Thanks Code: [Select] $subject = "maths"; $phone = "1235"; $colour = "red"; $all_vars = compact("subject", "phone", "colour"); get_value($subject); function get_value($variable){ global $all_vars; foreach($all_vars as $key=>$value){ if ($key = $variable) { echo $key; } } } I have a function which finds a list of companies associated with a country from a custom taxonomy. It finds their logo and creates an output which is all logos associated with a country, and the logo has a href to link to a company page. The code for this is: function countryCompanies(){ global $post;
$echo = f_print(array(
The f_print function finds the logos, and their sizes. So the 'mainlogo' type is a pull down of the thumbnail at 200px size.
What I need to do is write CSS and PHP which will display these results in a grid, 4 colums across, and as many down as results from the array. At the moment all I can get is all the results in one column. What tutorials would I need to write appropriate CSS to create this, and then is it as simple as adding the div prior to the echo of the $echo variable? Thanks Here is my function which almost works as expected: <?php function find_value($array,$value) { for($i=1;$i<sizeof($array);$i++) { if($array[$i] == $value) { echo "$i . $array[$i]<br />"; return; } } } ?> And I call the function like so: <?php $names = array('Jason','Mike','Joe'); $name = 'Joe'; find_value($names,$name); ?> And the output is: 2 . Joe According to my understanding of Arrays, Joe would be index 3 BECAUSE my counter starts at 1 in my for loop??? Why is the result like this? What am I not understanding here? I have this code Code: [Select] $nArr = array('A', 'B', 'C', 'D', 'E', 'F'); $counter = 3; while ($counter > 0) { $chunkedValues[$counter][0] = 1; for ($j = 0 ; $j < $counter ; $j++) { $chunkedValues[$counter][$j + 1] = $nArr[$j]; } $nArr = array_slice($nArr, $counter--); } var_dump($chunkedValues); that outputs: Code: [Select] array 3 => array 0 => int 1 1 => string 'A' (length=1) 2 => string 'B' (length=1) 3 => string 'C' (length=1) 2 => array 0 => int 1 1 => string 'D' (length=1) 2 => string 'E' (length=1) 1 => array 0 => int 1 1 => string 'F' (length=1) But i need this index structu Code: [Select] array 0 => array 0 => int 1 1 => string 'A' (length=1) 2 => string 'B' (length=1) 3 => string 'C' (length=1) 1 => array 1 => int 1 2 => string 'D' (length=1) 3 => string 'E' (length=1) 2 => array 2 => int 1 3 => string 'F' (length=1) I want to avoid loops with ceil. Any idea? thanks for your time. Hi the above title explains it all.How to output a post array which has been given input using forms.I know you can do it my echo but what about print() Thanks Trying to do something that I think should be very simple. Let's assume that I have an array populated with the numbers 1 to 24 for this example. I need to output these items in 4 columns to accomodate my CSS layout but still have them read from left to right, top to bottom. I also want this to be somewhat dynamic - I'm okay hardcoding it to split into 4 columns, but need it to handle any number of items in the array. I'm not sure if the best way to do this would be to split the original array into an array for each of the 4 columns, or to loop through the original array 4 times and output items 1+4, 2+4, and so on. Or maybe I should be using array_filter with some custom callback functions. I'm fine with any solution. The end result is echoing the array in the following groupings so I can surround each column with the appropriate column HTML for layout (in this case the array actually contains IMG urls): Column 1: 1, 5, 9, 13, 17, 21 Column 2: 2, 6, 10, 14, 18, 22 Column 3: 3, 7, 11, 15, 19, 23 Column 4: 4, 8, 12, 16, 20, 24 Any help would be appreciated! This one is driving me nuts and I know it should be relatively easier. Guess I should stick to HTML + CSS. I'm trying to create a website, that echo's out a bunch of groups, where each group contains a group of checkboxes, containing A value, and a label for the checkbox, the way it is created right now, is foreach that echo's out a bunch of php arrays, which was easier than the static way before - But still, it's static in some way, or not very user friendly at the moment.. My problem is that I really want to write it in a database when I have the option. Is there anyone that can give some tips how to do? At the moment, my foreach looks like this: Code: [Select] echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "<h2>{$list['title']}</h2>\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "<label class='checkbox'><input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'> {$cbox[0]}</label>\n"; } } echo "</form>"; And my array is something like this: Code: [Select] $items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do. My current database looks like this: Thank you! I have a problem with the below code: Code: [Select] <?php $sql_ranks = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date > '$last_sunday' AND vtp_tracking.action_date < '$next_sunday' GROUP BY teams.team_name ORDER BY surfs DESC"); $rsranks = mysql_query($sql_ranks); echo "<br><table align='center' valign='top' border='0' width='300px'> <tr><td colspan='2' align='center'><font size='2px'><b>Team Rankings (Current Week)</b></font></td></tr> <tr><td><font size='2px'><b>Team</font></td><td align='right'><font size='2px'>Total Surfs</font></td></tr>"; while ($row = mysql_fetch_array($rsranks)) { echo "<tr><td><font size='2px'><b>".$row[team_name]."</font></td><td align='right'><font size='2px'>".$row[surfs]."</font></td></tr>";} echo "</table>"; ?> Problem is that the last output (".$row[surfs].") is the same for all teams. It seems it is not making a total of all id's and not per team_name. anyone can see what I am doing wrong. I need to sort by team_name and the surfs should display the total of the members with team_id is ".$_GET['t']." Hello everyone. I need help with the following PHP APP. I am running on (Version PHP 7.2.10) I am trying to have a page table form on table.php pass the input variable of “5-Numbers” to another page called table_results.php I want that variable string of “5-Numbers” to be compared against 4 arrays and output any duplicates found within each of those 4 lists. If nothing is found, I still want some visual output that reads “None found”.
Lets pretend I have the following example .. On table.php, I typed inside my table form the 5-Numbers .. INPUT: 2,15,37,13,28 On table_results.php, the 4 arrays to be compared against my input numbers “ 2,15,37,13,28” are ..
$array_A = array(2,6,8,11,14,18,24); $array_B = array(1,2,9,10,13,14,25,28,); $array_C = array(1,3,7,9,13,15,20,21,24); $array_D = array(4,5,12,22,23,27,28,29);
So my output should read as follows below .. OUTPUT:
TABLE COLUMN 1 COLUMN 2 ROW 1 Matches Found Results .. ROW 2 GROUP A: 2 ROW 3 GROUP B: 2,13,28 ROW 4 GROUP ? 13,15 ROW 5 GROUP ? 28 ROW 6 5#s Input: 2,15,37,13,28
Please let me know if anyone has any suggestions on how to go about it. Thanks. Edited January 1, 2019 by Jayfromsandiego Wanted to include image example |