
leeming
Members-
Posts
93 -
Joined
-
Last visited
Never
Everything posted by leeming
-
i have looked up and down on php.net on the "array" list, but cant seem to find a function that will work for what i have... i am using "array_unique()" so any duplicate entries in the array are turned to NULL... i am basicly trying to find the last KEY that doesnt have the value of NULL eg. [code] array ( 0= blue 1= NULL 2= NULL 3= red 4= NULL ) [/code] last key is 4, but it = NULL... i want key 3 to be found
-
Warning: session_start(): Cannot send session cookie
leeming replied to AdRock's topic in PHP Coding Help
is this file include(), from another page? not 2 sure if you can have session_start() after output -
[quote author=mcfly link=topic=102783.msg410249#msg410249 date=1154793071] OK, thanks, folks! But I can't get it to work.. Excactly where shall I write it? Could anyone just edit the code for me and post it here? (I'm not a web-dude at all, I was just left alone trying to fix my own page) Thanks! Erik [code]<?php while(list($key, $val) = each($HTTP_POST_VARS)) { $val = str_replace("<", "<", $val); $HTTP_POST_VARS[$key] = str_replace(">", ">", $val); } $date = date("d. m. Y H:i:s"); $logit = "<font style=\"font-family: arial; font-size: 8pt;\"><p><b>Name:</b> ".$HTTP_POST_VARS["navn"]."<br>". "<b>Time:</b> $date<br>". "<b>Comment: </b>".$HTTP_POST_VARS["kommentar"]." <br><hr> \n"; $logit = stripslashes($logit); $fp = fopen ("innlegg.txt", "r+") or die("Error, something is wrong."); $Old = fRead ($fp, filesize("innlegg.txt")); fclose ($fp); $fp = fopen ("innlegg.txt", "w") or die("Error, something is wrong."); fwrite ($fp, $logit); fwrite ($fp, $Old); fclose ($fp); header("Location: crapbook.php"); ?>[/code] [/quote] add the code AndyB said... like this [code]<?php // function to check for all our favorite penis extenders and other spam trash function flag_spam($text) { $total_matches = 0; $trash = array(); // Count the regular links $regex = "/<\\s*a\\s+href\\s*=\\s*/i"; $total_matches += preg_match_all($regex, $text, $trash); // Count the PHPBB links $regex = "/[\\s*/\\s*url\\s*]/i"; $total_matches += 5 * preg_match_all($regex, $text, $trash); // Check for common spam words $words = array('phentermine', 'viagra', 'cialis', 'vioxx', 'oxycontin', 'levitra', 'ambien', 'xanax', 'paxil', 'casino', 'slot-machine','texas-holdem','ringtones'); foreach ($words as $word) { $word_matches = preg_match_all('/' . $word . '/i', $text, $trash); $total_matches += 5 * $word_matches; } if ($total_matches > 4) { return TRUE; } return FALSE; } //$_POST['comments'], change this to what ever your field name is for the message in the guest book. $comments = trim($_POST['comments']); if (flag_spam($comments)) { die("SPAM = LOSER"); // gotcha! } // comments not null so continue processing while(list($key, $val) = each($HTTP_POST_VARS)) { $val = str_replace("<", "<", $val); $HTTP_POST_VARS[$key] = str_replace(">", ">", $val); } $date = date("d. m. Y H:i:s"); $logit = "<font style=\"font-family: arial; font-size: 8pt;\"><p><b>Name:</b> ".$HTTP_POST_VARS["navn"]."<br>". "<b>Time:</b> $date<br>". "<b>Comment: </b>".$HTTP_POST_VARS["kommentar"]." <br><hr> \n"; $logit = stripslashes($logit); $fp = fopen ("innlegg.txt", "r+") or die("Error, something is wrong."); $Old = fRead ($fp, filesize("innlegg.txt")); fclose ($fp); $fp = fopen ("innlegg.txt", "w") or die("Error, something is wrong."); fwrite ($fp, $logit); fwrite ($fp, $Old); fclose ($fp); header("Location: crapbook.php"); ?>[/code] just see the php note i added... i hope that works
-
this is relaly weird.... [code]print"SORRY DEBUGGING...DONT BELIVE THE MAP!<BR><BR>"; $im = @imagecreatefrompng("worldmap.png"); /* Attempt to open */ if (!$im) { die('doesnt'); } else { die('works'); } [/code] it out puts... [quote]SORRY DEBUGGING...DONT BELIVE THE MAP![/quote] no "die" comment!?....
-
[quote author=ignace link=topic=103088.msg410234#msg410234 date=1154791133] I am not using the GD library, so my help is limited, sorry, but I think the error code is quite clear, and that it ran before, sure, but that also had the @-sign in front of it, not? However "./worldmap.png" bothers me, try changing it to just "worldmap.png" and see what comes up! I had this problem once with defined(); however the problem lay in one of my classes, what the actual cause was of the problem I can't remember! [/quote] oh sorry, forgot to mention i tried "worldmap.png" and "./worldmap.png" (thats what it was orginaly)... and no diference... i just looked up (copy paste) the error message onto google... [quote] If this error happens (mostly in the pixel selection) your GD library is not up-to-date or not installed fully. To create and read PNG images, the GD library supports normally the function imagecreatefrompng(). If not, your GD library is not complete. hand.jpgPlease ask your provider regarding this issue and ask him to add the PNG support to the GD library of PHP. He will do this. Afterwards, the error will not shown again. [/quote] if there any way apart from the server admin changing things... for this error to show?... if not, i will have to bug the server admin, to ask if hes messed around with the GD library
-
[quote author=ignace link=topic=103088.msg410223#msg410223 date=1154789813] imagepng(); returns a boolean value, check what you get whenever you put it in an if/else statement [code=php:0] $mapid = "map".$numb.".png"; if (imagepng($im, $mapid)) { // should have been written to file. } else { // not working } [/code] if this is not working, then please post the full code, so we can have an in-depth view. [/quote] well posting the whole code would be quite confusing.. but... i did test to see if the code was all running, by placing "print" tags, to see if its getting to that line.... found out it was this line stopping the script.. [code]$im = @imagecreatefrompng ("./worldmap.png") or die ("Cannot Initialize new GD image stream");[/code] so i took off the "@", to see the error (dont know why the or die wasnt working?) i get this message... [quote] Fatal error: Call to undefined function: imagecreatefrompng() in [i]<dir>[/i] on line 8 [/quote] i double checked by copy and pasting the function, into php.net, and yes it is spelt right... then i checked the php version.. and yes, i belive its valid for the php version (it has always ran before)... any suggestions now?
-
*edit* ive located the error, read down to my later posts hey, im asking for help with this function, as i dont have much experiance with it... i am looking after a site of a friends while he is away... and this image was working (and has been working) for ages.. but just the other day, it decided to give the red X (for ie)... so with this, im trying to edit the code a little... but it isnt fixing any thing (im trying to get it to save to a file, insead of just ouputting it stright away) this is what i have [code] $mapid= "map".$numb.".png"; imagepng ($im, $mapid);[/code] $numb, been a number between 1 and 7, for 7 different maps. so: map1.png map2.png map3.png ... etc but that code isnt saving to the file as im trying to do... any reasons why?
-
humm i figgured it out with this code [code] $leeming = "woot"; include($site_link."/inc/functions.inc.php"); include("inc/functions.inc.php"); include "inc/functions.inc.php" ; die($site_link); [/code] $site_link, is the full address... so it wasnt passing the variable
-
[quote author=ronverdonk link=topic=102616.msg407518#msg407518 date=1154462971] Are you sure that the statement [code]print"goo::$page::gooo";[/code] in the included file is NOT within a function? Because then $page would be a different variable (private to the function) from the one you set. ROnald ;D [/quote] no no its not in a function.. i just put it one of the 1st include files on my page 2 test it my theory (which took a while y my code wasnt working) its just a plain variable that works in the main page.. but as soon as its inside an include/require it stops existance.... heres another try.. (to check there is no mixing with values) [code] //main page $leeming = "woot"; include($site_link."/inc/functions.inc.php"); die($leeming); //include file if($leeming) { print"'leeming' is here<BR>"; } elseif(isset($leeming)) { print"'leeming' is set<BR>"; } else { print"no to all the above<BR>"; } [/code] outputs, [quote] no to all the above woot [/quote]
-
im totaly sure ive always been able to do this... [code] $var = 1; include("file.php"); echo $var; [/code] where file.php... [code] echo 'var is: '.$var.' :inside include<BR>'; [/code] where it should output [quote]var is: 1 :inside include 1[/quote] but the following code i did doesnt let me, (is there a setting in sum file that turns this on/off? because i've had trouble where the server admin has changed things on all sites instead of just one...) [code] include($site_link."/inc/functions.inc.php"); //...code between.. nothing to do with $page.... if(in_array("$page", $public_pages)) { include($site_link."/pub-".$page.".php"); die("goo::$page::gooo"); }[/code] functions.inc.php contains (i even commented every thing out apart form this line) [code] print"goo::$page::gooo";[/code] all i get from them is [quote] goo::::gooo goo::main::gooo[/quote]
-
[quote author=simcoweb link=topic=101817.msg403316#msg403316 date=1153849234] Heh..like I said..i'm a noob. Using the forums to learn more. Ok, a couple of things. Your last query example is correct. I think I was focusing on the comma separating the two fields and the lack of a space between the comma and the second field name. I honestly don't know if that makes a diff or not but what was being reported was a syntax error. Here's the example I use: [quote]$query = "SELECT b_name, b_author, b_cat, b_price from lib where id='" . $book_id . "'";[/quote] Noting the list of fields, the comma, then the space to separate. It's just a thought. But why you're getting an error unrelated to this query is strange. Unless you have a second query statement in your code. [/quote] the file im using, is included with another file (thus why i checked the other files aswell)... i even changed the name of the SQL (before the mysql_query part) just incase there was a mix with vearibles (not that it should matter, but im trying every thing lol) can some one who is experianced please even read this post lol
-
"SELECT AVG(More_Metrics.Days) FROM More_Metrics WHERE More_Metrics.Topic_Title='$title'" kinda like that
-
see above edit... as for the sql you said... 2 my knowledge, i have never seen it wrote like that... (does it work?) *any one else doesnt need to read down wards* normaly its some thing like this for a query [code]SELECT username FROM membersTable WHERE userid = '1'[/code] that would look up ur members.. find member id 1.. and only get the user name... using '*' means all fields, and using commas ',' for selecting more than 1 field
-
[code] ereg("[0-9]", $data); [/code] will return true if numbers are found, but i think its... [code]ereg("^[0-9]", $data)[/code] for only numbers *sorry if im not 100% on this, but i always got confused, and have a function to do this instead lol*
-
[quote author=simcoweb link=topic=101817.msg403271#msg403271 date=1153845927] I'm not an expert but in this statement: [quote]$sqlUser = "Select username,Account from users where id='$userid'";[/quote] I've never used a comma in the query string. The one you have after 'username'. Remove that, put a space there, and try again. [/quote] good suggestion, it actully did do some thing (didnt fix it, got a 2nd error, im gonna work on now)... as for the comma thing u said.. new or not to sql (? i dont know, but will explain)... instead of using, "SELECT * FROM....", '*' been the 'all' fields selected... instead i just SELECT the 2 fields username and account... *edit* urm, well i still cant seem to debug this at all, due to the mysql_error not returning the correct query!? [quote]Error: please report to an admin XX:01 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 'worldwar_game6''' at line 1::18[/quote] where the query is... [code] $sqlUser1 = "Select username, Account from users where id='$userid'"; $rUser = mysql_query($sqlUser1,$dbh) or die("Error: please report to an admin XX:01 ".mysql_error($dbh)."::".__LINE__);[/code] a little bit changed from the orginal.. like added __LINE__ just to double check it was the same line where i was looking... also tried mysql_error() with arguments (2 conections that are availible, $dbh and $dbh000) but no improvement.... urm and also searched for them other querys that had the same sql info in, and checked them for errors (the error returned shows a tripple ' single quote) now that it seems that this error is not for the query it is attacheched to... how can i go about finding out which query it is going on about
-
well say if your form tag is like this... [code]<form method="POST" action"pagename.php?posted=1">[/code] then you would need to write code to see if that form is submitted... [code]if($posted == 1) { ... }[/code] inside there.. *assuming you have already conected to your database.* [code]mysql_query("INSERT INTO tablename (description /*any other fields to insert form the form?*/) VALUES ('$_POST[description]' /*same as last comment*/)")or die('error with query #1, debug:'.mysql_error());[/code] some thing like that any way.. or am i not understanding, and making you sound like you dont know what your doing (sorry if ive assumed that, please give more details if so)
-
emails you with the results of what they inputted in the form.. then you want to email them also, saying some thing like, thank you for submitting your info? just set up another mail() [code] $sendTo = $_POST[email]; $subject = "Thank You ".$_POST[name]; $Message = "Thank you for submitting your details.... blah blah"; [/code]
-
[size=20pt]SOLVED[/size] im getting the following error... [quote]Error: please report to an admin XX:01 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 'Select `numb` from `games` where `db` = 'worldwar_game6'' at li[/quote] i located that error to.. [code] $sqlUser = "Select username,Account from users where id='$userid'"; $rUser = mysql_query($sqlUser,$dbh) or die("Error: please report to an admin XX:01 ".mysql_error());[/code] yet the above sql query doesnt contain the query given in the mysql_error... the $dbh, is a conection, with or die's conected to them, and i have checked these, and they are not them... also i have searched pages conected to this page, for the query given in the mysql_error, which i found 1 or 2 on other pages, and give them a diferent 'or die' message... yet the error message is still the "XX:01" which is the above code... is mysql_error() some how returning an OLD error?
-
custom function, mysql error reports- suggestions/bug holes...
leeming replied to leeming's topic in PHP Coding Help
[quote author=thorpe link=topic=101797.msg403160#msg403160 date=1153835690] If your using php 5 you'd be best to check out exceptions and custom exception handlers. [/quote] went into reading about it, but totaly forgot to check, php versionim running at.. (which sadly is PHP Version 4.4.1) suggested fix for this, or continued support on the above function -
custom function, mysql error reports- suggestions/bug holes...
leeming replied to leeming's topic in PHP Coding Help
ok thanks, just looking them up now, might not understand them, but still gonna look them up... one of them is "set_exception_handler" right? -
sorry if in wrong forum.. but it is kinda a help on fixing up this function i made, which replaces the "or die" after query errors, which relay on members of sites to report to you (if its just a die() message, or a mysql_error() message). i will show the code here now, before i talk more about it.... [i]edited, with line breaks as not to make it such a big scrolly text box[/i] [code] function reportError($note) //note is used to identify, and short description of what the query is doing, and to locate it on my code *see update ideas* { if($_SESSION[logname])//soon to be changed to an id, because of new site changes.. is the login name of user { $name = $_SESSION[logname]; } else //user is not a loged in user, pull ip instead { $name = getenv('REMOTE_ADDR'); } /* NOTE: 1 - see below for these notes */ //insert into the database table, witht these my fields //- by: the $name *above* value //- report: out put report for admin to view //- type: this is a report system on my site, users can also report other things, eg non DB bugs, or other users... //-date: the ovious date & time of error mysql_query("insert into error (`by`, `report`, `type`, `date`) VALUES('$name', 'Page:".$_SERVER['SCRIPT_NAME']."<BR><b>".addslashes(mysql_error())."</b><BR>\'$note\'', 'Auto Report','".date("Y-m-d H:m:s")."')") or die('<b>CRITICAL Function Error!!!</b>: Please <a href=report.php>report</a> this to an admin.'); //report.php been the loged in page for members to report non DB errors *NOTE: 2* //custom message for output from function, to let the user know there was an error, and it has been reported to the admin $message = "<b>ERROR</b>: There has been an error, but an error report has been sent and an admin will see to the problem as soon as posible <BR>Sorry for any inconvenience, please <a href=\"/index.php\">click here</a> to go back to the site."; die($message); }[/code] [quote][b][u]NOTES:[/u][/b] 1: See description of how reports look to admin *below* 2: Almost identical form, like members used to report, but for non loged in users (maybe its a log in bug or sign up?)[/quote] [u]Report out puts..[/u] shows reports to admin view only.. first thing it shows is, who it was reported by: -if a member reported it, then their id is used to look up their name, and a link to an insite mail (and their member account profile) -elseif a non loged in person (ip address), i have a code i found that vaidates ip addresses.. so it just shows the ip address. (doesnt show profile or mail link) Type, is basicly the type of report (my function creates the type as "auto report") Description, is normaly what the user inputs into a text area, but in this case, as an auto report shows description urm 'style' as it is when the INSERT query runs. now that i have explained how it works, and how its viewed (hopefully), i can continue on about imporvments im not too sure about (and any bug holes, i might have) 1. Removing $NOTE, as the function argument. and instead let it report the code line number (i tried this, but as my function is inside a functions include file. it shows the code line number for the query in that file (not where it was called from) 2. Very important failed DB queries, reported more directly to admin (email). 3. long shot / better way around... aswell as reported failed mysql queries, can be used with other error type messages (not syntax) like eg. [code] if($admin == 1) { ...admin code } else { //curently like die('you should not be here'); //but report these 'hack' attempts }[/code] ^or would it be better just to create another function for this if not, use mysql errors, as the default for the function. [code]function reportError ($errorType = "sql")[/code] that is basicly my custom built function... i hope to pick up any suggestions and/or help to patch it up (mainly for the mysql report part (the last suggestion was an extension.. not 2 needy). And also if any one would like to use it ,if it seems like a good function to have (???)... (but maybe have a note/comment in your code, if you do want to use the code. That it was orginaly wrote by me "Leeming" and edited by you for what ever reasons (to fit your database reporting system??) hope no one thinks its a stupid function, of if ive wasted my time, due to some thing thats way simple (??)
-
mysql_query() returning false on INSERT query... confused :-s
leeming replied to leeming's topic in PHP Coding Help
soory just another one where i totaly over look the small things, lol... sorry a lil tired... i had but the wrong table name... sorry -
This does not work at all... when ran, it doesnt show an mysql_error(), so i dont know where im going wrong... for any one who wants to know what the query prints out.. [quote]Error: Can not add user to new wait attacks! #F-1-002 ::debug:: ::query = INSERT INTO `users` (user_id) VALUES ('12')[/quote] [code] $newAttSql = "INSERT INTO `users` (user_id) VALUES ('$user')"; $newAtt = mysql_query($newAttSql,$dbh) or die('Error: Can not add user to new wait attacks! #F-1-002 ::debug::'.mysql_error().' ::query = '.$newAttSql); [/code]
-
[quote author=hvle link=topic=100745.msg398024#msg398024 date=1153022236] try this block of function, fill out the neccessary information: [code] function my_db_selection($num) { // connect to your db here $dblink = mysql_connect(argv here); // do a error handling here if $dblink is null // select schema: if ($num == 0) mysql_select_db('databasename0', $dblink); // fill in the name else if ($num == 1) mysql_select_db('databasename1', $dblink); else { echo 'invalid database selection'; exit(); } return $dblink; } [/code] then you can call a query like this: mysql_query($sql, my_db_selection(0)); [/quote] Thanks alot! i knew i was close with what i had.... yup i can finaly goto bed, now that its out o f the way lol