PHP - Php Errors With Sql Query And My Exhausted Brain
Help. I used the great Simple SQL search tutorial provided by this site, but when I tried to customize it for my site, it keeps falling apart. I am a newbie, but any disgust at my idiocy is fine as long as I find a ball of string to lead me out of the labyrinth.
Here's the code (modified from the tutorial) sans the login information: $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {olsendai_ssn}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT name, ssn FROM simple_search WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['name'])?"`name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['ssn'])?"`ssn` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the name as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `ssn`"; // order by ssn. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if ($num_rows < 1 ) { echo '<b>No Titles Found.</b><br><br><br>'; } }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['ssn']}<br /><br />{$row['name']}<br /><br />"; $i++; } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <name> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> name: <input type="checkbox" name="name" value="on" <?php echo isset($_GET['name'])?"checked":''; ?> /> | ssn: <input type="checkbox" name="ssn" value="on" <?php echo isset($_GET['ssn'])?"checked":''; ?> /> | /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </name> </html> When I try this, it gives me this message: Parse error: syntax error, unexpected '}' in /home/olsendai/public_html/sqlfour.php on line 65. Help. Please! It seems simple, but when I remove the unexpected '}', it comes back with this error - before I have even used the search feature Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/olsendai/public_html/sqlfour.php on line 60 The following had errors: Search terms must be longer than 3 characters. Similar TutorialsPlease are going to start hating me about this haha. Hey guys i have been trying to do this for a few hours and my brain is hurting haha hope someone can help. Ok here is what i am trying to do. I have been making a website that allows users to make friends below is my friends table:: NAME: member_friends id friend_id << Person who has been sent the friend request my_id << Person who sent the friend request friend_since << when did they become friends is_friend << is set to 0 then friend request pending and this is the member_topics message_id member_id << this stores the id of the member from the members table message_contents << stores their message message_date message_reported << if set to 1 the message has been reported Ok basically i want the messages to be displayed on the members home page if they are friends, so if my name is JamesDean and i befriended a person called Harry if i post a message i want harry to see this and any other friends i may have. Same goes for their messages. Sorry if im confusing you stay with me. Ok here is what i am trying to do (did i mention im fairly new to php so please if im doing something wrong dont hurt me (: ) $query = mysql_query("SELECT * FROM member_friends"); while($row = mysql_fetch_array($query)){ $friend_id = $row['friend_id']; // Ok this is where i want the while loop to loop through all of my friends // Ok set up the new filter im gunna get lost here now $sql = mysql_query("SELECT a.*,b.* FROM member_topics as a, member_friends as b WHERE (a.member_id = b.my_id OR a.member_id = b.my_id) AND ((b.friend_id = '$friend_id') AND b.my_id = '$my_id') ORDER BY a.message_id DESC"); // $my_id is a variable created from session so thats ok and the $friend_id i want that to change fromt he first loop so the statement changes for all of my friends. // Sorry for the query above i have tried that many i dont even know my gender anymore // So while loop in a while loop i think while($row = mysql_fetch_array($sql)){ $message_id = $row['message_id']; $member_id = $row['member_id']; $message_contents = $row['message_contents']; $message_date = $row['message_date']; $message_type = $row['message_type']; $message_reported = $row['message_reported]; } } something like this hope someone can point me in the right direction before my brain fails thanks in advanced!!!!!!! $params = array(); $sqlFilters = ""; if(isset($filtertown)) { $sqlFilters .= " AND town =:town"; $params["town"] = $filtertown; } if(isset($filterinstagram) && !empty($filterinstagram)) { $sqlFilters .= " AND instagram >=:instagram"; $params["instagram"] = $filterinstagram; } if(isset($filtertwitter) && !empty($filtertwitter)) { $sqlFilters .= " AND twitter >=:twitter"; $params["twitter"] = $filtertwitter; } if(isset($filterfacebook) && !empty($filterfacebook)) { $sqlFilters .= " AND facebook >=:facebook"; $params["facebook"] = $filterfacebook; } if(isset($filterpinterest) && !empty($filterpinterest)) { $sqlFilters .= " AND pinterest >=:pinterest"; $params["pinterest"] = $filterpinterest; } if(isset($filteryoutube) && !empty($filteryoutube)) { $sqlFilters .= " AND youtube >=:youtube"; $params["youtube"] = $filteryoutube; } if (isset($userstatus)) { if ($userstatus == "active") { $sqlFilters .=" AND profilecomplete = 'yes'";} if ($userstatus == "incomplete") { $sqlFilters .=" AND profilecomplete IS NULL";} if ($userstatus == "block") { $sqlFilters .=" AND status = 'block'";} if ($userstatus == "cancel") { $sqlFilters .=" AND status = 'cancel'";} if ($userstatus == "showall") { $sqlFilters .=" AND status IS NULL";} } if (isset($search)) { if (isset($searchfirstname)) { $sqlFilters .= " AND firstname LIKE :searchfirstname"; $params["searchfirstname"] = $searchfirstname; } if (isset($searchsurname)) { $sqlFilters .= " AND surname LIKE :searchsurname"; $params["searchsurname"] = $searchsurname; } } if (isset($sort)) { $sqlStart = "SELECT * FROM users WHERE usertype = 'influencer'"; $sqlEnd = " ORDER BY `$col` $order LIMIT $offset, $rowsPerPage;"; $sql = $sqlStart.$sqlFilters.$sqlEnd; $sqlfiltercount = $sqlStart.$sqlFilters; $result = $pdo->prepare($sql); $result->execute($params); $resultfiltercount = $pdo->prepare($sqlfiltercount); $resultfiltercount->execute($params); $num_users = $result->rowCount(); $num_usersfiltered = $resultfiltercount->rowCount(); } else { $sqlStart = "SELECT * FROM users WHERE usertype = 'influencer'"; $sqlEnd = " LIMIT $offset, $rowsPerPage;"; $sql = $sqlStart.$sqlFilters.$sqlEnd; // sqlfiltercount removes the LIMIT to show ALL users on this userstatus filter $sqlfiltercount = $sqlStart.$sqlFilters; $result = $pdo->prepare($sql); $result->execute($params); $num_users = $result->rowCount(); echo "$sqlfiltercount"; $resultfiltercount = $pdo->query($sqlfiltercount); $num_usersfiltered = $resultfiltercount->rowCount(); } Hi there. I am writing a tool that displays a list of users. The page has pagination, set at 99 per page. This script combines the various filters added by the administrator, but if they select Active, Blocked or a few others, it bypasses that and runs the bottom {} brackets of query. You have the $num_users which is the total on screen at the time, plus the secondary count of TOTAL users in the system. This count is then show by 'users' on the page.
This runs fine on my local machine running php7.2, but on the live 7.2 server, it's showing nothing. No errors. If I comment out the $resultfiltercount lines, the page loads, but of course no count. Why might it be getting upset at that, and why would it not throw errors on screen at me? Hello, I have no experience when dealing with large files so I am not sure what to do about this. I have attempted to read several large files using file_get_contents ; the task is to clean and munge them using preg_replace(). My code runs fine on small files ; however, the large files (40 MB) trigger an Memory exhausted error: Code: [Select] PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 41390283 bytes) I was thinking of using fread() instead but I am not sure that'll work either. Is there a workaround for this problem? Thanks for your input. Al. Hello guys, I'm new in php and now I'm trying to make an php installer Right now it compress php project/dump database with gzip in a file called install.php and the idea is when the user run install.php in his browser he can choose directory, overwrite existing file etc... The problem is that when I try to run install.php in firefox I get this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 134217728 bytes) in Unknown on line 0 and when I run it with chrome I get this: <code> <?php //Compressed with Php Installer 0.5 //Directory list $directory = array(); $directory['C:\xampp\htdocs\magnatest'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/3dtags/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/__grundlayout/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/__grundlayout/bilder/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/actions/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/images/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/images/customize/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/jpgraph/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/jpgraph/lang/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/attachments/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/attachments/process/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000002/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000007/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000015/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000019/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000026/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000028/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000029/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000030/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000031/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000034/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000035/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000062/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000064/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000065/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000068/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000070/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000072/'] = array( 'perms' => 16895 ); ................................................. .... ................................................. ............ ................................................. </code> Can anyone tell me what might be the problem ? Is it a memory size problem ? Hi again, I did a simple request and i get right response from curl_exec($ch); but when i call the static method str_get_html my result is always the same. QuoteFatal error: Allowed memory size of 536870912 bytes exhausted I tried increase the memory memory_limit=2048M but the result is the same. Proof of memory limit: Memory Limit I also tried ->clear(); unset(); but doesn't work. I'm using the following library: kub-at/php-simple-html-dom-parser My code: $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $this->callback = HtmlDomParser::str_get_html(curl_exec($ch)); .... Any tips? I can use regular expression, but will be my last choice. Thank you! I think this problem requires LOTS of brainpower, and as I am absolutely convinced at this point that I have none, I was kind of hoping someone could steer me in the right direction at the very least. What I'm scripting right now is a search form that allows users to browse members based on what they type in the forms. There's about 8-10 forms of various criteria, such as age, country, birthdate, email, etc. And once they hit submit, all the information they typed gets sent to the url ($_GET, in other words). Now, the way I structured my script is like this: Code: [Select] <?php //If nothing was submitted (or if the url is completely blank) if ($_GET == array ()) { //Define a variable that will be used to query the members; in this case, it would select all members $query = "SELECT * FROM fans"; } else { //If the user typed at least one thing (in the form OR the url) if (count ($_GET) == 1) { //If what they typed is only for one criteria, define a variable that creates a query for only ONE criteria to search for $query = "SELECT * FROM fans WHERE"; foreach ($_GET as $field => $value) { $query .= " $field = '$value'"; } //If the user has typed in more than one field and hits search } else { //Define a variable for a query that selects members based off each criteria $query = "SELECT * FROM fans WHERE"; foreach ($_GET as $field => $value) { $query .= " $field LIKE '%$value%' AND"; } } } ?> Now, the problem with the above script is the very last part...defining a query to run if more than one field is selected. Because I'm using a foreach loop to structure that query, my options seem rather limited with what I can and can't do as far as querying the database. And the problem lies in where it says "$field LIKE '%$value%' AND". Because of the way the script is set up, the last $_GET variable will have "AND" at the very end, and when it runs through the mysql_query() function, it breaks, and does NOT work. Is there a way around this? I figure it probably requires some complex mathematical equation (one which I have absolutely no idea on how to create). Can anyone help? Hi. I tried to add some more if statements to check for validation and I'm now getting this error. The "on line ###" changes depending how many fields are FALSE. Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 35 bytes) in /home/content/f/u/s/fusionfashion/html/registration.php on line 133 I think it has to do with the php.ini file. So I added the memory_limit in the php.ini file. Code: [Select] register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 memory_limit = 128M post_max_size = 128M SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so But I'm still getting the error. How to I check my php version and this value within a browser? <?php phpinfo() ?> Found this. Its showing 64M in LOCAL and MASTER. But I just updated the local? Rage. The whole error message reads: Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 16 bytes) Dunno bout you but that doesn't make sense to me! Anywho I am constantly getting this error when any PHP variables are stored or anything. I'm guessing thats the case coz its saying the error is on line 6 which is: $card = rand(1,52); I tried a search on google but just got confused, is there a simple explanation why this is happening? thanks alot guys Hi , As you may all have experienced this problem is there way we can non-healthy exit of script ..due to memory problem........??? I got to know..we avoid this......by properly managing our php memory by unset function. remove unusable variables and objects from memory...... Is there any way we can check each time inside the script -to check memory is available or sleep for some time and check again.......to proceed without exit........ Is there a way to catch this fatal error and take necessary steps to avoid exit........ Thanks, redfort :confused: I'm getting a fatal memory error and have been unable to figure out what is causing it. To make it worse, the allowed memory size does not appear to be related in any way to the memory_limit value. Here's the information: Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 128 bytes) in template.php on line 164 Excerpt from template.php (line 164 is where $max is assigned): ... else if(isDateType($type) || isTimestampType($type) || isDatetimeType($type)) { $min = htmlentities($countpost['constraints'][$tablename][$fieldname]['min'], ENT_QUOTES); $max = htmlentities($countpost['constraints'][$tablename][$fieldname]['max'], ENT_QUOTES); echo "\t\tFrom: <input name=\"constraints[$tablename][$fieldname][min]\"" ." type=text value=\"$min\" onclickXSSCleaned=\"toggleCalendar(this)\" readonly>\n"; echo "\t\tTo: <input name=\"constraints[$tablename][$fieldname][max]\"" ." type=text value=\"$max\" onclickXSSCleaned=\"toggleCalendar(this)\" readonly>\n"; } ... These two lines were included at the top of the script and printed "Base Memory Usage: 473172 Memory Limit: -1": echo "Base Memory Usage: ". memory_get_usage() ."\n"; echo "Memory Limit: ". ini_get('memory_limit') ."\n"; I also get the same error in a slightly different location: Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 1 bytes) in template.php on line 153 Excerpt from template.php (line 153 is the simple variable assignment of an empty string): ... if(!isset($countpost['constraints'][$tablename][$fieldname]['value'])) $countpost['constraints'][$tablename][$fieldname]['value'] = ""; ... If I refresh the page repeatedly, the error will predictably occur at the same place. Once I change any code (even slightly), the location of the error will change to a new location, sometimes into an included file. The size of "tried to allocate X bytes" also changes. The only constant in this whole mess is the allowed memory size (which is ALWAYS 262144, no matter what the actual memory limit is). I had previously set memory_limit to -1 in the php.ini file, which seems to have no effect on the error. I am not using a .htaccess file. Changing the memory_limit doesn't change the "allowed memory size" whether it's set to 16M, 64M or whatever. I've restarted apache after each change in php.ini. I have memory_get_usage in the code several times to watch the memory. There are small changes, and a change of about 300k when I first load another file. The max gets up to 1048576 bytes (memory_get_peak_usage). 1 Mb does not seem very large to me and is much smaller than the memory_limit. Also, today I wrote a short php script to just use up memory. This was just to test php and see if my installation is messed up. It worked just fine and I got up to 128Mb used without encountering the error above. So it's something in my code. This is using php 5.3.2, apache2 2.2.14, on Ubuntu 10.04. Any insights would be greatly appreciated. I have a wordpress site that has this error in my error logs and seems to be causing the site to load very slow: PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 64 bytes) in /home/name/public_html/wp-includes/meta.php on line 339 this is line 339: Code: [Select] $cache[$mpid][$mkey] = array(); a couple line above and below: Code: [Select] if ( !empty($meta_list) ) { foreach ( $meta_list as $metarow) { $mpid = intval($metarow[$column]); $mkey = $metarow['meta_key']; $mval = $metarow['meta_value']; // Force subkeys to be array type: if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) $cache[$mpid] = array(); if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) $cache[$mpid][$mkey] = array(); // Add a value to the current pid/key: $cache[$mpid][$mkey][] = $mval; } } Can some please help this is causing major issues. Okay, I have a 3 column table layout on my forum, I want users to beable to select where they want 1 of there profile sections to go under, (and display order) either, left middle or Right side. See now I can code the javascript/etc ajax to make them update if selected to move to (any direction) But I need help to do it server side, what kind of value/row in my db should i use? just 1 field and use arrays? Also, let's say I want to move the "Calendar" to the middle or far right, and save that position, what kind of functions would i be working with (in php) I can prob do it if I use like 200 IF and ELSE conditions, but that would take way to long, any help? It's one of those days after a long weekend and a rainy morning. Simply trying to get the correct message depending on the variable's value if($a = 'one'){ echo "POOR";} if($a = 'two'){ echo "GOOD";} if($a = 'three'){ echo "VERY GOOD";} if($a = 'four'){ echo "EXCELLENT";} Not sure if I need to use ==, extra quotes, or ELSEIF for the best result.
For some reason I cannot think today. Code: [Select] <?php class { function meh() { $blah = $this->profile(); echo $blah->weirdname; } function profile() { // this is where I'm stuck.. // how do I properly set weirdname? } } ?> It's been a while since I've played with classes (been doing other things) so how do I set up the function profile() to return a value for weirdname. I am trying to create some navigation link with sublinks in a <ul> list. Here is the set up. Table = categories fields: id cattitle = title parentid = level of the link (0 = top level) cat_loc = the id value of the link that this link will be sublink of example: 1st link: id 1, title - home, parentid - 0, cat_loc - null; 2nd link: id - 5, title - info, parentid - 0, cat_loc - null; 3rd link: id - 6, title - test, parentid - 1, cat_loc - 5; so test should be a sublink of info. Here is what I have for code so far... <?php include $_SERVER['DOCUMENT_ROOT'] . './includes/magicquotes.inc.php'; include $_SERVER['DOCUMENT_ROOT'] . './includes/db.inc.php'; $result = mysqli_query($link, 'SELECT * From categories order by orderby asc'); if (!$result) { $error = 'Error getting categories: ' . mysqli_error($link); include 'error.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $navlink[] = array('id' => $row['id'], 'cattitle' => $row['cattitle'], 'cat_loc' => $row['cat_loc'], 'parentid' => $row['parentid']); } echo '<ul>'; $count = 0; foreach ($navlink as $nav): { if ($nav['parentid'] == 0) { if ($count!=0){echo " | ";} echo '<li>' . '<a href="home.php?id=' . $nav['id'] . '"' . ' ' . 'title="' . $nav['cattitle'] . '">' . htmlspecialchars($nav['cattitle']) . '</a>'; $count++; } if ($nav['parentid'] != 0) { $result2 = mysqli_query($link, 'Select * From categories where "$nav[cat_loc]" = "$nav[id]"'); if (!$result2) { $error = 'Error getting categories: ' . mysqli_error($link); include 'error.php'; exit(); } echo '<ul>'; while ($row2 = mysqli_fetch_array($result2)) { $subnavlink[] = array('id' => $row2['id'], 'cattitle' => $row2['cattitle']); } foreach ($subnavlink as $subnav): { echo '<li>' . '<a href="home.php?id=' . $subnav['id'] . '"' . ' ' . 'title="' . $subnav['cattitle'] . '">' . htmlspecialchars($subnav['cattitle']) . '</a></li>'; } endforeach; } } endforeach; echo '</ul>'; yes I do have the php closed further down the page. Part of my problem is that the sublinks won't be in the database right after their parent links so I don't think the way I have my foreach loop set up is right. I know I don't have my <ul>'s and <li>'s closed correctly yet. I just want to get the subnavs to show up, I can fix those later. Any ideas? Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes) in /home/a5418385/public_html/scripts/status.php on line 2 What does this mean? Ok this should be straight forward but my tired brain cannot work this out. I'm creating a simple contact form and for some reason the validation isn't working. It wont go past the check fields are filled in validation. Can anyone spot what I'm doing wrong? Code: [Select] <form method="get"> <h1 class='contact_form_h'>Contact Us</h1> <div id="login_response"></div> <input type='text' name='name' id='name' class='contact_form_input' value='Name' onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;" /> <input type='text' name='email' id='email' class='contact_form_input' value='Email' onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;" /> <textarea name='enquiry' id='enquiry' class='contact_form_textarea' rows='10' cols='10' onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">Enquiry</textarea> <input type='submit' name='contact' id='contact' class='contact_form_submit' value='Contact Us' /> </form> Code: [Select] <?php //Check if form is submitted if(isset($_GET['contact'])) { //Require check email function require "check_email.php"; //Variables $err_name=stripslashes($_GET['name']); $err_email=stripslashes($_GET['email']); $err_enquiry=stripslashes($_GET['enquiry']); $to="xxx@xxxx.com"; $subject="Website Contact Form"; $from = stripslashes($_GET['name'])."<".stripslashes($_GET['email']).">"; $message = $err_enquiry; $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; //Check all form fields are filled in if ($_GET["name"]!='' OR $_GET["name"]!='Name' OR $_GET["email"]!='' OR $_GET["email"]!='Email' ) { if (isValidEmail($_GET['email'])){ //Send Mail if (@mail($to, $subject, $message, $headers)) { echo "3 - sent"; } else{ echo "2 - not"; } } else { echo "1 - not valid"; } } else { echo"0 - Fill in"; } } ?> Below is the check email script. Code: [Select] <?php // This function tests whether the email address is valid function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)){ return true; } else { return false; } } ?> I have an array $INFO = array( 'joebob' => 'password', 'fred' => 'password', 'tom'=> 'password' ); how can i just do a simple check to see if a name and password match? something like if (in_array(can'tthink)); thanks hey peeps, I am trying to get my site to display related youtube videos under the main video here is what i have $query=mysql_query("SELECT title,mp3ID,youtube_ID FROM songs ORDER BY RAND() LIMIT 10 ") or die("Error Occured"); $left = true; while($row=mysql_fetch_array($query)) { if ($left) { echo "<tr>"; } echo "<td align='justify' width='100%' cellspacing='2' cellpadding='2' >"; echo "<td><img src='http://img.youtube.com/vi/".$row['youtube_ID']."/default.jpg'></td>"; echo "<td nowrap><a href='/music.php?id=".$row['mp3ID']."'>".$row['title']."</a></td>"; echo"</td>"; if (!$left) { echo"</tr>"; } $left = !$left; } ?> this is basic info of how i am able to get youtube video titles and image....i want to use the same youtube.com video ID To get related videos please help!! I've been trying to wrap my head around this for about two hours now. The file uploads just fine, the entry goes into the database just fine, EXCEPT for the file name like it's supposed to do. I wrote the code from scratch... it worked fine, then it broke (that's the way it's supposed to work, right?) Anyways, if anyone could take a look-see and point out what I'm missing? I've tried throwing errors on all the queries, I've made sure the filename is passed from the upload form, the form does have the proper enctype. require 'dbconfig.php'; $title = escape($_POST['title']); $content= escape($_POST['content']); $time = time(); //Check the file. if (!empty($_FILES['attachment'])) { //$filename = the name as saved on user's the computer. //$filename = $_FILES['attachment']['name']; if($_FILES['attachment']['type'] === 'image/jpeg' || $_FILES['attachment']['type'] === 'image/jpg' || $_FILES['attachment']['type'] === 'application/pdf') { //Move the file only if it's uploaded. if (is_uploaded_file($_FILES['attachment']['tmp_name'])) { //Whoops, an error. if (!move_uploaded_file($_FILES['attachment']['tmp_name'], './attachments/' . $_FILES['attachment']['name'])) { die('Error: File not uploaded. Please make sure it is a JPEG image or a PDF document.'); } else { $filename = $_FILES['attachment']['name']; } } } } if( $filename = '' || empty($_FILES['attachment'] )) { die('No attachment found. Please <a href="javascript: history.go(-1)">Go back</a>'); } if ($title === '') { die('News title is empty. Please <a href="javascript: history.go(-1)">Go back</a>'); } if ($content === '') { die('News content is empty. Please <a href="javascript: history.go(-1)">Go back</a>'); } else { if (mysql_query("INSERT INTO news (news_title, news_content, news_posted, news_edited, news_attach_path) VALUES ('$title', '$content', '$time', '0', '$filename')") or die(mysql_error())) { $posted = true; } else { $posted = false; } } ?> |