PHP - Array_diff() Results Are Wrong
I have two arrays of strings, one is read in from a file, the other is collected on a previous page using js and passed with a form through $_POST. The array from the file I label $oldImages and the array from the previous page I label $newImages (each is a list of image URLs). I need to compare the two and add them together so that there are no duplicate entries. I'm using array_diff() on them and the result I'm getting includes one entry that is in both arrays.
I've tried different ways of reading the file, none of them seem to make any difference in the results. I've been printing the arrays with print_r() to have a look at the contents of the arrays and I decided to use implode() and explode(), and str_replace() to try to remove any irregularities that might be in the objects somehow which I'm not seeing. I'm not a PHP programmer, BTW. Here is some code. I've also attached a screenshot for you--link at the bottom. Code: [Select] <body> <?php $file = file("image_list.txt") or exit("Unable to open file!"); $oldImages = implode($file); $oldImages = str_replace(" ", "", $oldImages); $oldImages = explode("\n", $oldImages); $newImages = implode($_POST); $newImages = str_replace(" ", "", $newImages); $newImages = explode("\n", $newImages); $newAdditions = array_diff($newImages, $oldImages); print_r($newImages); echo '<br><br>'; print_r($oldImages); echo ' <form method="post" action="#"> New Images<br> <textarea id="displayText" rows="5" cols="105" wrap="off" name="existing"> '; foreach($newImages as $key => $entry) echo $entry; //echo $newImages; echo ' </textarea> <br> Stored Images<br> <textarea id="newText" rows="5" cols="105" wrap="off" name="new"> '; foreach($oldImages as $key => $entry) echo $entry; //echo $oldImages; echo ' </textarea> <input type="submit" class="button" value="Submit"><br> </form> Newly Generated Image List<br> <textarea id="newText" rows="30" cols="105" wrap="off" name="new"> '; foreach($newAdditions as $key => $entry) echo $entry; echo ' </textarea> '; ?> <div class="clear"></div> </body> Here is the code from the previous page which produces the array that is stored in $_POST. What you can't see in this code is the javascript functions toggleEntry() and displayList(). All they do is handle the addition and removal of image URL strings to/from the textarea object, which I do using document.getElementById('text').InnerHTML=$myList, where $myList has strings being added or removed to/from it. Code: [Select] <script type="text/javascript" src="/js/user_selection_list_builder.js"></script> <script type="text/javascript"> function toggleAndDisplay(key) { toggleEntry(key); displayList(); } </script> </head> <body> <form method="post" action="add_images2.php"> Selected Images<br> <textarea id="displayText" rows="10" cols="90" wrap="off" name="comments"> </textarea> <input type="submit" class="button" value="Submit"> </form> <div class="clear"></div> <?php $i = 2; include 'simple_html_dom.php'; if($i===1) $html = file_get_html('lookbook-source.htm'); elseif($i===2) $html = file_get_html('http://lookbook.nu/preference/look-list-gender/girls'); elseif($i===3) $html = file_get_html('http://lookbook.nu/new'); // Match all div tags of the class 'look_photo'. foreach($html->find('div[class=look_photo]') as $key => $entry) { echo " <div class='imgBox'> <a href='javascript:toggleAndDisplay(".$key.")'><img id='".$key."' src='".$entry->last_child()->last_child()->src."'></a> </div> "; } ?> </body> Similar TutorialsGood Evening, What I am trying to do in here is to display data based on my selected option in the drop down list. I don't have submit button, I just want it to automatically display results based on my selection. Here's my code: <link href="add_client.css" rel="stylesheet" type="text/css"> <?PHP include("dbconnection.php"); //Include database connection to file $query = "SELECT * FROM records"; if(isset($_POST["territory"])) { $query .= " WHERE territory LIKE '%".$_POST["territory"]."%' ORDER BY territory ASC LIMIT 0,15" ; $result = mysql_query($query, $connection) or die(mysql_error()); } ?> <!-- Start of table --> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <td> <table width="760" border="0" cellpadding="0" cellspacing="0"> <!-- Table data containing the Asia Logo --> <td width="199" align="center" valign="top"> <a href="login.html"> <img src="asia.gif" alt="" width="152" height="58" border="0" /> </a> </td> <!-- Table data containing Home button --> <td width="176" align="right" valign="bottom"> <a href="main.php"> <img src="Home.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Table data containing View Client button --> <td width="130" align="right" valign="bottom"> <img src="View.jpg" width="104" height="20" border="0"/> </td> <!-- Table data containing the Add Client button --> <td width="146" align="right" valign="bottom"> <a href="add_client.php"> <img src="Add.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Blank table data --> <td width="109" align="right" valign="bottom"> </td> </table> <!-- Table design division and body--> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="3" bgcolor="#1B1C78"> <img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"> <img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> <tr> <td height="500" colspan="2" align="center" valign="top" bgcolor="#F3FAFE"> <!-- Page contents --> <!-- Search Query --> <br> <form name="form" action="trustlist.php" method="post"> <table width="293" border="0"> <tr> <td width="140" align="left" valign="middle"> SEARCH RECORD: </td> <td width="143" align="center" valign="middle"><select name="territory" id="territory" style="width: 143px" width="230"> <option selected="selected" disabled="disabled">Select Territory</option> <option>Territory 01</option> <option>Territory 02</option> <option>Territory 03</option> <option>Territory 04</option> <option>Territory 05</option> <option>Territory 06</option> <option>Territory 07</option> <option>Territory 08</option> <option>Territory 09</option> <option>Territory 10</option> </select></td> </tr> </table> <br> <!-- End of search query--> <!-- Start of Search Results--> <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="148" align="center" bgcolor="#E0E8F3">Acute Trusts</th> <th width="262" align="center" bgcolor="#E0E8F3">Employer</th> <th width="160" align="center" bgcolor="#E0E8F3">Name</th> <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$last_name.", ".$first_name."</td>"; echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>"; echo "</tr>"; } } ?> </table> </form> <!-- End of page --> </td> </tr> </table> </td> <tr> <td height="38"> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white> <a href="disclaimer.html"> <font color="#FFFFFF">Legal Disclaimer</font> </a> </td> <td width="560" align="center" bgcolor="#0076CC"> Copyright © 2006 - 2010 AsiaLimited. All rights reserved. </td> </table></td> </tr> </table> I'm practising how to do date and time in PHP. I wanted to see if I can get all of the date/time variables from user submission and format them correctly. I went with ISO 8601 date... // From the Manual: // date('c', mktime(1, 2, 3, 4, 5, 2006)); // Prints something like: 2006-04-05T01:02:03+00:00 ...but my attempts always produce a slightly different result for the year, month and timezone... Code: [Select] $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, (int)$timezone, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; // Should return: 2013-11-02T02:30:01+00:00 // Instead returns: 2012-12-02T02:30:01-08:00 The timezone value coming from HTML... <option value="1.0">(GMT +1:00)</option> I noticed; 1. It always picks a year less than whatever year I select. 2. It always selects 12 as the month. 3. It always adds -08:00 after the picking the correct timezone. How come? Thanks in advance. Hi everyone. I'm stuck on the following query. I need to display all the fields listed below on a page, but linked via communications.CommID. I'd appreciate any assistance you can provide. thank you. Code: [Select] <?php $result = mysql_query("SELECT records.NameFirst_1, records.NameLast_1, records.CompanyName, records.CompanyBranch, records.CompanyReferenceNumber, records.CaseOwnerSelect, communications.ConversionType, communications.Contact, communications.ContactFrom, communications.CommID, communications.ContactPosition, communications.ContactTelephone, communications.ContactEmail, communications.ContactFax, communications.CallDate, communications.CallTime, communications.ActionTextField FROM records INNER JOIN communications ON records.IDNumber = '$IDNumber'") or die(mysql_error()); $row = mysql_fetch_array($result); ?> Our product is running on LAMP(PHP) architecture. For MySQL operation PDO library has been used. We are in the process of moving the product to a new Linux server. On the new server we are facing MySQL query output related issue. At the end of the post I have listed the server configuration details of both the servers and the sample PHP program with the output. It works fine in server 1 but when the same code moved to Server 2, the output is not correct. Would appreciate any points to solve this problem The following piece of code is tested and output is also given. <?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'ram'; /*** mysql password ***/ $password = 'tellmehow'; try { $dbh = new PDO("mysql:host=$hostname;dbname=inhouse", $username, $password); $sql = "SELECT first_name,last_name,user_id,email FROM users LIMIT 1"; $stmt = $dbh->prepare($sql,array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE)); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_OBJ); $stmt->closeCursor(); /*foreach($result as $key=>$val) { echo $key.' - '.$val.'<br />'; }*/ print_r($result); $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } ?> Output for server 1: stdClass Object ( [first_name] => super [last_name] => admin [user_id]=>1 [email] => ram@greynium.com ) output for server 2: stdClass Object ( [first_name] => super [last_name] => admin [users] => ram@greynium.com ) On server 2 I am not getting the output for field 'user_id' from the table 'users'. For the field 'email' from 'users' table, it is displaying the name of the table itself (users). Not sure what is wrong. The configuration of the servers are given below Server 1 -------- OS Details: Linux 2.6.9-5.ELsmp PHP Details: PHP 5.2.3 (cli) (built: Aug 28 2007 11:48:30) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with Suhosin v0.9.22, Copyright (c) 2007, by SektionEins GmbH PDO details: PDO PDO support => enabled PDO drivers => sqlite2, sqlite, mysql PDO Driver for MySQL, client library version => 5.0.37 PDO Driver for SQLite 3.x => enabled Server 2 --------- OS Details: Linux 2.6.18-8.el5 PHP Details: eAccelerator requires Zend Engine API version 220060519. The Zend Engine API version 220090626 which is installed, is newer. Contact eAccelerator at http://eaccelerator.net for a later version of eAccelerator. PHP 5.3.2 (cli) (built: Jul 6 2010 17:57:31) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies PDO Details: PDO PDO support => enabled PDO drivers => mysql, sqlite, sqlite2 PDO Driver for MySQL => enabled PDO Driver for SQLite 3.x => enabled I have two strings: $string = shell_exec('reg.bat '.$arg); //returns word\0word\0word $stringA = "$string"; $stringB = "word,other,word2,other2"; $array1 = explode('\0', $stringA); $array2 = explode(',', $stringB); $result = array_diff($array1, $array2); I can use array_diff to find the differences, but the last word in $array1 shows up as not in both strings even though it is because of the \0 delimiter. How can I include the last word as well? I have a very simple script which should be working with no problems. I have 2 arrays, and I'm simply trying to array_diff them to get the results from array1 which are not present in array2. $scrubbed = array_diff($numbers, $dnc); print_r($numbers); print_r($dnc); print_r($scrubbed); The results: Code: [Select] Array ( [0] => 3042476001 [1] => 3042476002 [2] => 3042476003 [3] => 3042476004 [4] => 3042476005 [5] => 3042476006 [6] => 3042476007 [7] => 3042476008 [8] => 3042476009 [9] => 3042476010 [10] => 3042476011 [11] => 3042476012 [12] => 3042476013 [13] => 3042476014 [14] => 3047655291 [15] => 3047281328 ) Array ( [0] => 3042476068 [1] => 3047281328 [2] => 3047652846 [3] => 3047652982 [4] => 3047655291 [5] => 3047655398 [6] => 3047655458 [7] => 3047655719 [8] => 3047657562 [9] => 3047657747 ) Array ( [0] => 3042476001 [1] => 3042476002 [2] => 3042476003 [3] => 3042476004 [4] => 3042476005 [5] => 3042476006 [6] => 3042476007 [7] => 3042476008 [8] => 3042476009 [9] => 3042476010 [10] => 3042476011 [11] => 3042476012 [12] => 3042476013 [13] => 3042476014 [14] => 3047655291 [15] => 3047281328 ) Now, $numbers is drawn from a single column .csv file, and $dnc is concatenated from anywhere between 1 and 3 mysql database queries (there are 3 seperate Do Not Call lists). There are 2 numbers from $numbers which should have been removed, but are not. I have tried intval() to make sure all types are the same using array_walk(), and I have also tried to trim() with array_walk() in case there were any extra characters not showing up on the print_r. I am at quite a loss here Someone help? EDIT: I have also tried to use the following work around functions function array_diff_alt($array1, $array2){ $result = array(); foreach ($array1 as $value){ if (!in_array($value, $array2)){ $result[] = $value; } } return $result; } function array_diff_alt($a, $b) { $map = $out = array(); foreach($a as $val) $map[$val] = 1; foreach($b as $val) unset($map[$val]); return array_keys($map); } function array_diff_alt($a, $b) { $result = array(); foreach ($a as $avalue){ foreach ($b as $bvalue){ if ($avalue != $bvalue){ $result[] = $avalue; break; } } } return $result; } Why is this not working??? If $adsused prints out: 1, 5, 6, 7, while ($tarray=mysql_fetch_array($admintotadsq)){ $adsused .= $tarray['adnr'].', '; } $array1 = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20); $array2 = array($adsused); $diff = array_diff($array1, $array2); print_r($diff); print_r($diff); prints out: Array ( => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 [16] => 17 [17] => 18 [18] => 19 [19] => 20 ) What am I doing wrong? I am trying to understand why the following code outputs the value of 4 (it is part of a PHP quiz question). I know that array_diff will compare one array with another and return the result but I just don't understand what is going on with the code below: Code: [Select] <?php $a = array(1,2,4,8); $b = array(0,2,4,6,8,10); echo count (array_merge(array_diff($a, $b), array_diff($b, $a))); //prints 4 ?> Would someone be able to walk me through it? I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners I am querying... $sql = "SELECT `messages_inbox`.`message_id`, `users`.`firstname`, `users`.`lastname`, `users`.`username` AS `from`, '${user_info['username']}' AS `to`, `subject`, LENGTH(`files`) AS `len`, 'inbox' AS `box`, DATE_FORMAT(`messages_inbox`.`time` ,'%T %D-%M-%Y') AS `time` "; $sql .= "FROM `messages_inbox` INNER JOIN `users` ON `messages_inbox`.`from_id` = `users`.`id` WHERE `to_id` = ${user_info['uid']} AND `messages_inbox`.`deleted` = 0 ORDER BY `messages_inbox`.`message_id` DESC"; and I am trying to output $displayName = ucwords("${message['firstname']} ${message['lastname']}"); by using $messages = pm_fetch_all($_GET['box']); I know my fetch works but for some reason firstname and lastname are only returning the logged in users first name and last name, not the person who sent the message. Ok I have this code.. it logs into my myspace accounts and grabs some info.. it is supposed to log into each account and write the info to a file.. what it does is logs into the first account and writes the info to the file then when it signs into the second account it doesnt write the info on the new line it just overwrites the info from the previous account.. here is some of the code for($i=0; $i!=count($account_data); $i++){ echo "\n::: ".strtoupper($account_data[$i][0])." :::\n"; if($account_data[$i][1] != "" && stristr($account_data[$i][0], "@") && stristr($account_data[$i][0], ".")){ list($place[0],$place[1],$place[2],$place[3]) = authorize($account_data[$i], $game_link); if($place[2] > 1 && strlen($place[3]) == 40){ $filename = 'auth-keys.txt'; $fp = file($filename,'a+'); $data = $place[2]." ".$place[3]."\r\n"; file_put_contents($filename, $data); echo $data;}}} sleep(10000); heres a pic Any help would be greatly appreciated Code: [Select] <?php include('connection.php'); $test1=$_POST('firstname'); $test2=$_POST('lastname'); $test3=$_POST('username'); if (!eregi("([^A-Za-z0-9]"),$test1)){ if (!eregi("([^A-Za-z0-9]"),$test2)){ if (!eregi("([^A-Za-z0-9]"),$test3)){ $query="SELECT * FROM vendors WHERE username = '$_POST(username)'" $result=mysql_query($query); $num=mysql_num_rows($result); if ($num == 0) { $query1="SELECT * FROM vendors WHERE email = '$_POST(email)'" $result1=mysql_query($query2); $num1=mysql_num_rows($result1) if ($num1 == 0) { if (($_POST['password']==$_POST['password1'])&&($_POST['email']==$_POST['email1'])) { $name=strip_tags($_POST['username']); $first=strip_tags($_POST['firstname']); $last=strip_tags($_POST['lastname']); $pass=strip_tags($_POST['password']); $country=strip_tags($_POST['country']); $address=strip_tags($_POST['address']); $email=strip_tags($_POST['email']); $city=strip_tags($_POST['city']); $zip=strip_tags($_POST['zipcode']); $state=strip_tags($_POST['state']); $phone=strip_tags($_POST['phonenumber']); $aql="INSERT INTO vendors SET username='$name', firstname='$first', lastname='$last', email='$email', Country='$country', zipcode='$zip', password='$pass', city='$city', state='$state', phonenumber='$phone', address='$address'" $result=mysql_query($sql) if ($result){ header(location:http://www.digitaldesignersmall.com/ffx.html) } else { header(location:http://www.digitaldesignersmall.com/fff.html) } } else( header(location:http://www.digitaldesingersmall.com/afx.html) } } else { Header(location:http://www.digitaldesingersmall.com/afx.html) } } else{ header("location:http://www.digitaldesignersmall.com/cxs.html") } } else{ header("location:http://www.digitaldesignersmall.com/cxs.html") } } else{ header("location:http://www.digitaldesignersmall.com/cxs.html") } ?> Here is code I have, I can't seem to figure this error out, I bet it is obvious, but I clearly am not seeing it..... Here is error: Problem with the query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 (not really that good of an error, but maybe help getting started?) Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } // Set error message as blank upon arrival to page $errorMsg = ""; // First we check to see if the form has been submitted if (isset($_POST['name'])){ $name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $phone = ereg_replace("[^A-Z a-z0-9]", "", $_POST['phone']); // filter everything but spaces, numbers, and letters $username = ereg_replace("[^A-Z a-z0-9]", "", $_POST['username']); // filter everything but spaces, numbers, and letters $address = ereg_replace("[^A-Z a-z0-9]", "", $_POST['address']); // filter everything but spaces, numbers, and letters $city = ereg_replace("[^A-Za-z0-9]", "", $_POST['city']); // filter everything but lowercase letters $state = ereg_replace("[^A-Za-z0-9]", "", $_POST['state']); // filter everything but lowercase letters $zip = ereg_replace("[^A-Za-z0-9]", "", $_POST['zip']); // filter everything but lowercase letters $cell = ereg_replace("[^A-Za-z0-9]", "", $_POST['cell']); // filter everything but lowercase letters $accounttype = ereg_replace("[^A-Z a-z0-9]", "", $_POST['accounttype']); // filter everything but lowercase letters $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters // Check to see if the user filled all fields with // the "Required"(*) symbol next to them in the join form // and print out to them what they have forgotten to put in if((!$name) || (!$username) || (!$password)){ $errorMsg = "You did not submit the following required information!<br /><br />"; if(!$name){ $errorMsg .= "--- Name"; } else if(!$username){ $errorMsg .= "--- Username"; } else if(!$Password){ $errorMsg .= "--- Password"; } } else { // Database duplicate Fields Check $sql_username_check = mysql_query("SELECT userid FROM members WHERE username='$username' LIMIT 1"); $username_check = mysql_num_rows($sql_username_check); if ($username_check > 0){ $errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another."; } else { // Add MD5 Hash to the password variable $hashedPass = md5($password); // Add user info into the database table, claim your fields then values $sql = mysql_query("INSERT INTO members (name, phone, username, address, city, state, zip, cell, email, accounttype, password ) VALUES('$name','$phone','$username','$address','$city','$state','$zip','$cell','$email','$accounttype','$hashedPass'") or die ("Problem with the query: $sql<br>" . mysql_error()); printf("Records updated: %d\n", mysql_affected_rows()); echo mysql_error(); echo '<meta HTTP-EQUIV="REFRESH" content="3; url=http://final.net46.net/success.php">'; exit(); // Exit so the form and page does not display, just this success message } // Close else after database duplicate field value checks } // Close else after missing vars check //Close if $_POST } ?> Hello all, I'm having trouble with the following code, it's supposed to go like this, you search for a hotel, choose a room, then it takes you to confirmation page before the paypal, but the problem is, in the confirmation page, it shows everything right, the number of nights, the number of guests, all except the number of rooms, it always give me 0 rooms It's seperated into 3 files, hotelsmanager.php, bookingmanager.php, and book.php here are the codes Code: [Select] while($row = @mysql_fetch_array($result)) { echo "<tr>"; echo "<td class=\"text\" align=center>".$row['room_type']."</td>"; echo "<td class=\"text\" align=center>".$row['price_per_day']."</td>"; echo "<td class=\"text\" align=center>".$row['people']." People</td>"; echo "<td class=\"text\" align=center>"; ?> <select name="nrooms" id="nrooms" onchange=" //alert('<?php echo $row['id'] ; ?>'); //alert(this.value); var exist = 0; if(roomids.length > 0) { for(var hh = 0;hh < roomids.length; hh++) { if(roomids[hh] == <?php echo $row['id'] ; ?>) { exist = 1; //alert(hh); roomnumar[hh] = this.value; } } if(exist == 0) { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } } else { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } document.bookingform.roomid.value = roomids; document.bookingform.roomnum.value = roomnumar; "> <option value=0> 0 </option> <?php for($i = 0; $i < $row['available_rooms']; $i++) { $nr = $i+1; $pr=$nr * $row['price_per_day']; echo "<option value=$nr>$nr ($pr\$)</option>"; } echo "</select> </td>"; echo "<td align=center> </td>"; echo "</tr>"; echo "<tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr>"; } echo "<tr class=\"rooms\"> <td colspan=\"4\"> </td> <td align=center><input type=\"submit\" value=\"book\" id=\"bookroom\" name=\"bookroom\"/></td> </tr>"; echo "</table>"; echo "</form>"; print_r($_SESSION['order']); $_SESSION['order']=0; unset($_SESSION['order']); } } ?> then booking info Code: [Select] <?php include("hotelsManager.php"); ?> <?php include("config.php"); ?> <?php include("textManager.php"); ?> <?php function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $datein = $_POST['datein']; $dateout = $_POST['dateout']; $roomid = $_POST['roomid']; $pr = $_POST['tp']; $_SESSION['hotelID'] = isset($_POST['hotelid']) ? $_POST['hotelid'] : $_SESSION['hotelID']; $_SESSION['datein'] = isset($_POST['datein']) ? $_POST['datein'] : $_SESSION['datein']; $_SESSION['dateout'] = isset($_POST['dateout']) ? $_POST['dateout'] : $_SESSION['dateout']; $_SESSION['roomid'] = isset($_POST['roomid']) ? $_POST['roomid'] : $_SESSION['roomid']; $roomsarray = explode(",",$_POST['roomid']); $_SESSION['roomsarray'] = isset($_POST['roomid']) ? explode(",",$_POST['roomid']) : $_SESSION['roomsarray']; $roonsNo = $_POST['nrooms']; $_SESSION['nrooms'] = isset($_POST['roomnum']) ? explode(",",$_POST['roomnum']) : $_SESSION['nrooms']; Then the confirmation page is Code: [Select] <?php echoPostedData(); ?> </td> </tr> <tr> <td valign="top"> </td> </tr> </table> </td> </tr> <tr> <td valign="top"><img src="images/spacer.gif" width="28" height="10" /></td> </tr> <tr> <td valign="top"> <?php if(isset($_POST['bookroom'])) {?> mysql_query("UPDATE categories SET active=0 WHERE id=$id"); What am I doing wrong here to get: Parse error: syntax error, unexpected T_STRING ??? ok so before this.. if there isnt description for the company..the logo cant be click..only can be clicked if there is description added..im confused.. Code: [Select] <? if(isset($_GET[ttid])) { $ttid = $_GET[ttid]; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query = "select master_event.* , (DATE_FORMAT(event_datefrom, '%d %M %Y')) as datefrom, (DATE_FORMAT(event_dateto, '%d %M %Y')) as dateto, ucase(event_name) as eventname from master_event where master_event.event_id = '$ttid '"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $eventname = $row['eventname']; $eventdesc = $row['event_desc']; //$companydescription = $row['company_description']; $eventvenue = $row['event_venue']; $eventfee = $row['event_fee']; $datefrom = $row['datefrom']; $dateto = $row['dateto']; echo "<font color='#000000' face='arial' ><b> $eventname </b> </font> <br>"; echo "<font color='#000000' face='arial' ><i>Date</i> : $datefrom - $dateto <br>"; echo "<i>Venue</i> : $eventvenue <br>"; $querypstype = "SELECT DISTINCT master_pstype.pstype_id, pstype_desc FROM master_pstype INNER JOIN master_psevent ON master_psevent.pstype_id= master_pstype.pstype_id where master_psevent.event_id = '$ttid' ORDER BY pstype_order"; $resultpstype=mysql_query($querypstype); while($rowpstype = mysql_fetch_array($resultpstype)){ $pstypeid = $rowpstype['pstype_id']; $pstypedesc = $rowpstype['pstype_desc']; echo "<br><font color='#8B3A3A' size='1' face='georgia' ><b><i>$pstypedesc</i></b></font> <br>"; $queryps = "SELECT master_psevent.*, pstype_desc, company_name, company_link, company_description, logo_filename FROM master_psevent LEFT JOIN master_pstype ON master_psevent.pstype_id = master_pstype.pstype_id LEFT JOIN master_ps ON master_ps.ps_id = master_psevent.ps_id WHERE master_psevent.event_id = '$ttid' and master_pstype.pstype_id= '$pstypeid' ORDER BY pstype_desc,company_name "; $resultps=mysql_query($queryps); while($rowps = mysql_fetch_array($resultps)){ $companyname = $rowps['company_name']; $companyid = $rowps['ps_id']; $companylinkori = $rowps['company_link']; $companydescription = $rowps['company_description']; $logopath = $rowps['logo_filename']; $describelink = "index.php?ttid=$ttid&content=describe&pstypeid=$pstypeid&psid=$companyid"; echo "<a href=\"$describelink\" target=\"_blank\"><img src=".$logo_dir."/".$logopath." width=\"15%\"></a>"; ?> <br> <? } echo "<br>"; } } ?> im new..so to make it simple..the problem is ..i want it to be (if there is description = logo can be click, if no = otherwise) or should I say can you tell me WHAT is wrong? getting error on line 19 Parse error: syntax error, unexpected '[' in /home/heaven/public_html/tester/view_thread2.php on line 19 <?php include("connect.php"); mysql_select_db("heaven_forum") or die ("Could Not Select Database"); $recent = mysql_query("SELECT phpbb_posts.id AS post_id, phpbb_posts.topic_id AS topic_id, phpbb_posts.forum_id AS forum_id, phpbb_posts.poster_id AS poster_id, phpbb_topics.topic_title AS title, phpbb_users.username AS usernameFROM phpbb_posts, phpbb_topics ON phpbb_posts.topic_id=phpbb_topics.id, users ON phpbb_posts.poster_id=users.idORDER BY post_time DESC LIMIT 5"); //pull array $recent_row = mysql_fetch_assoc($recent); //set varibles pulled $topic_name = $recent ['title']; $poster = $recent['usernameFROM']; echo $topic_name; echo "Posted By: $poster"; ?> I am trying to create a very basic object but am having troubles. Code: [Select] <?php class item{ public $name; public $price; function __construct($name,$price){ $this->name=$name; $this->price=$price;} function getName(){ return $this->name; } } $object = new item("car",400); echo $object->getName(); ?> The HTML output is: name=$name; $this->price=$price;} function getName(){ return $this->name; } } $object = new item("car",400); echo $object->getName(); ?> I'm sure that this code is clean but for some reason will not output the desired result! any help would be great. thanks. |