I'm currently trying to wrap my mind around multiple categories. So far the whole selecting works perfectly fine, but I can't figure out the how to post everything to the join table.
I don't understand how to use the cat_array and foreach elements. Can someone help me out? My PHP knowledge is still very basic and PHP.net just confuses me. Thank you :)
Relevant parts of the script (with some weird testing-stuff and some stuff commented out): Currently, this version posts both an entry to the blog table, but it only posts one category into the catjoin table (always the one with the highest ID), however, it should of course make seperate entries for each checked category checkbox.
...
$cat_array = array();
....
<.form...> ...
# select the categories from the cat table to create a list of checkboxes include('connect.php'); $result = mysql_query("SELECT blog_cat.catID, catname FROM blog_cat LEFT JOIN blog_catjoin ON blog_cat.catID=blog_catjoin.catID GROUP BY blog_cat.catID ORDER BY catname ASC") or print ("Can't select categories. " . $result . " " . mysql_error());
.... # insert all the stuff into the database $sql = "INSERT INTO $table (...) VALUES (....)"; $result = mysql_query($sql) or print ("Unable to post data. " . $sql . " " . mysql_error());
if ($result != false) { print "Entry has been posted! ($title)"; }
$idresult = mysql_query("SELECT id from $table ORDER by id DESC LIMIT 1") or print ("Can't select categories. " . $result . " " . mysql_error()); while($idrow = mysql_fetch_array($idresult)) { $id = $idrow["id"]; } /*foreach ($cat_array as $cat) {*/ $query_cat = "INSERT INTO blog_catjoin VALUES ('','$id','$catID')"; $result_cat = mysql_query($query_cat);
if ($result_cat != false) { echo "All categories successfully added."; } /*}*/
I try to get out of them when I can (will go out of the way to use explode when I can). But in this instance, I can't. And I'm stumped on one character
Here's the format any string with spaces:numeric/numeric ("john doe:45/89" for instance)
I can get everything to match up until I throw the / into the expression. I thought a \ would recognize it as a character. The numbers (or string before :) can be of any size. Can anyone with more experience with regular expressions tell me what I'm missing?
I THINK I FOUND IT preg_match('/^[a-zA-Z0-9 ]+:[0-9]+\/[0-9]+$/', "john doe:45/89")
I think pcre can get confused with POSIX shorthand like [:alnum:] especially if you're mixing in other characters (I think that even happens with ereg(). I broke it down old school way, put my +'s in (thanks signe), threw a $ at the end (found a hole there). I did multiple tests and I THINK it's pretty solid now. If anyone sees a hole in the format now, correct me (please :).
Alright guys, I'm having a bit of a problem. I'm in the process of writing this small document-tracking application for my mother's work and was writing it on my own site. It worked almost perfectly except for some functionality that I had yet to add.
But when I went to upload it to the server it was supposed to be on, I found out they were running an older version (4.4.1) than the one I had been writing for (5.1.2). So, I went in to go fix the problems (like removing Try-Catch statements), and I seem to have gotten most of them worked out, except one: for some reason the mail() function isn't actually sending any mail.
I've tried it with many different email addresses and no luck. Now, the server this is currently on (the server it will have to be run from as well) is using Microsoft Exchange which I don't really know much about. We've been looking at some of the other applications that are run on this server with working mail functionality and can't figure out why this application isn't running.
//File Name: docFunctions.php
//Author: Lisa Obenauf
//
//For use by Union Station of Kansas City (http://www.unionstation.org) only.
function generateEmail()
{
//MYSQL DB Connection and Table selection removed for privacy puroses//
//Verify the connections to the Database and Table
if (!$email_connect || !$db_select)
{
die("Problem connecting or selecting a database.");
} //end if
//initialize variables
$sender = $_POST['docFrom'];
$attachment = $_FILES['docAttachment']['name'];
$headers = "From:" . $_POST['docFrom'] . "\r\n";
$headers .= "Reply-To:" . $_POST['docFrom'] . "\r\n";
$headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";
$body = "
";
echo "Respond By: " . $_POST['docMonth'] . "-" . $_POST['docDay'] . "-" . $_POST['docYear'] . " ";
echo $_POST['docDescription'];
//Inserts information into the Database
$result = mysql_db_query("test", $query);
//Checks to see if the email needs to be sent to each person Sequentially or all at once.
//If sequentially, then the e-mail is just sent to the first recipient, and will be sent to the rest of the recipients.
//through confirmation via a different form.
if ($_POST['docDistribution'] === "all")
mail($recipient, "", $description, $headers);
else
mail($_POST['emailTo1'], "File: " . $_POST['docAttach'], $body, $headers);
//verifies the successful insertion of the information into the database.
if (!$result)
{
die("
Anyway, thanks for any advice you can give me. I appreciate it. I've wracked my brain, searched through my books and the internet, asked my friends, and now I'm asking you.
Cheers! --Lisa
P.S. The code isn't fully compliant with any HTML/XHTML standards as of yet, because it is still in development. I am more concerned with functionality than with compliance, and will update any HTML to be as compliant as possible when everything is working, so I apologize for any weird tags and suchnot.
Hi all, I'm obviously missing something stupid and need a second set of eyes to help proof this, and maybe help me understand something I missed in the docs. I've got a variable $pCurEvent[ "eventDate" ] that stores a date. The value in it looks like so: 2006-05-31 00:00:00.000
and that's correct/valid data. However I want to just draw the date-part, not the empty time values. Any variation I've used of date() and getdate() and other things seems to make the date value that gets displayed "roll over". It only wants to draw "Decmeber 1969", not the correct info.
Can somebody give me a sanity check and just let me know what I'm doing wrong? I'm certain it's something stupid, but it's currently 1am and I've been writing so much code over the last few weeks (in 3 different langauges) that I know I'm just not seeing something in PHP that should be obvious.
Was talking to a fellow programmer today at work and he was saying that there is a function or routine in PHP to alter a title of a page in an include file that has been called AFTER the head tag. But of course, he couldn't remember right off hand how to do it. I wouldn't doubt there's a way to do it though I thought PHP works asynchronously. But maybe not with output (???). This isn't the first time I've heard of it being done. But such a routine would be quite useful when using PHP as a page template with include files (not that that's common or anything ;)
Generally in the past I've just used but if there's a way to do it within PHP alone, could someone put up such an example or explain how it's done?
There's a lot of circumstances where it's not just convienent to set all page content in variables, call an include before output then shuffle them into place within different places on the page. I know about the xml_set_processing_instruction()/eval() design and using XML but in many cases that's more work than simply calling a short javascript tag (call me lazy).
This issue has been solved to a satisfactory level. Working example here.
Hey folks. I've been attempting to replace some AJAX stuff that refreshed every X milliseconds using the XMLHTTP object, with a streaming equivalent using inline frames and PHP delays. However, i've hit a snag in that data seems to be sent out in 4kb chunks - far too large for my intended purpose.
While this streaming example is fine providing that 4096 bytes of data is sent between each portion, this dosen't go very far towards increasing consecutive update speed and efficency (by preventing the constant cycle of connect-download-disconnect). I am aiming to only send out about 512 bytes from the server, per portion. I have yet to work out if the 4kb limit is being implemented by the client or the server.
So basically what I want to do is be able to have the code below work without needing 4kb of useless padding.
This code is not currently Moz/FF compatible, due to an issue with the way I move the content from the iframe with javascript (window.frames["streaming_iframe"].document.body.innerText returns "undefined" in FF).
// PHP consistent data streaming test. header("Cache-Control: no-cache, must-revalidate");
Solution: Inital padding with echo str_pad('',256)."\n"; (I feel that 256 bytes is an acceptable level of padding) Output flushinf with flush(); ob_flush();
Code (for possible future reference): // PHP consistent data streaming test. header("Cache-Control: no-cache, must-revalidate");
echo "";
if (@$_GET["stream"]) { echo str_pad('',256)."\n";
for ($i=0;$i<10;$i++) { echo $i."\n\r"; flush(); ob_flush(); usleep(500000); }
Hi, I have a Linux server that I am slowly learning how to use. A friend of mine who is very good with Linux not available for lots of questions set it up for me. I am at the moment trying to install Smarty Templates. I have a question about part of the installation instructions that I have copied below.
In our example, the document root is /web/www.domain.com/docs and the web server username is "nobody". We will keep our Smarty files under /web/www.domain.com/smarty
Who is the web server username that nobody is referring to?
Another question I have is about the location of the Smarty files. The installation docs suggest /usr/local/lib/php/Smarty/
Why that directory particularly? There was no php directory in /usr/local/lib/. I set one up and copied the files as instructed. I am just curious about that choice of location.
I was wondering if anyone had any experience creating on the fly PDF or Excel files via PHP? I'm currently working on a script that I wish to be able to do so but however I'm not familiar with PEAR and the main thing I've been able to find via Google is the PDFLib which requires Pear. Excel seems easy enough, I found this : http://www.stargeek.com/php_scripts.php?script=2 and it looks like it should work with PHP 5 on a Linux system, but if there's a better method please let me know. So mainly I'm looking for how to create PDF files dynamically on a Linux system using PHP.
Currently I'm working on a small and simple blogger for someone. It doesn't have to be anything extraordinary or anything, however, of course, I want it to be as secure as possible within my means.
I've heard all of the horror stories of SQL injection and whatnot where users input bad things to make bad things happen and that there is a general rule about NEVER letting the user input directly into a database without cleaning it up.
Well... in this case, it isn't that simple.
I don't want to really limit what characters the user can enter in (except for html.. That I'm stripping out). But, I don't want to limit it to alpha-numerical characters. So, I thought of another way where the user has more freedom, but I'm hitting some walls with it... and perhaps some of you could let me know if you see any glaringly obvious problems.
I was thinking of having the users input sent to a text file. A file, automatically named, maybe by timestamp or whatever, that contains the text the user has entered. Then, the DB would only contain the name of the file created, its ID number, and the user associated with it. Then, when viewing them, simply pull the name of the file from the DB, fopen and fread it and echo the results. I have the open and reading part working, however... I want to avoid people being able to go to that file directly (by some stroke of luck by guessing its name). So... my two concerns are:
1. Are there any obvious security issues by doing this with external files? 2. Is there any way I can prevent direct opening of these files?
Ok I just upgraded to PHP5 and started using GD. I have a function that takes an image name, a name for a thumbnail, a width and a height it then creates a thumbnail.
I only use the createthumb function and its in a file all by itself. I plug in the variables at the start and then run it from the command line. It works like a champ.
However when I put the function into my functions file and try to run it from the web application it fails. Even if I plug in the vars at the start of the function it fails with this error:
[client 192.168.40.254] PHP Fatal error: Call to undefined function imagecreatefromjpeg()
How is it that the function is undefined? Same server, same directory, same variables. Could it be the user? When I run from the command line I am myself but from the web browser I have different permissions. I am very confused.
Any light you all can shed on this would be great.
however as you can see, i still have a problem what should be at the 0 key is shouts_1001-1100.html. is there anyway to sort this array numerically without it grouping together numbers at the first digit?
however for some reason, this seems to be returning a whole document to me instead of what i'm hoping for. in the document, i've got number scattered about like so "".
i'm actually trying to get it to return an like array([0] => 512, [1] => 513, [3] => 514). however i only seem to be getting a whole documents worth of data, what am i doing wrong? i've never been good with regex.
I have a script that generates files using the fopen($file,'w+') function to create files that may or may not already exist, and it seems to be working fine but with one small gotcha--the permissions are for whatever reason set to 644 (decimal). This isn't a huge problem except that it doesn't give me enough permissions to edit the file using ftp or ssh (i.e. I can still get at it with another php script, but I can't modify it directly).
I've tried using the chmod($file,077) command, but it's obviously disabled as it has no effect. I do not have access to the php.ini file, although I do have ssh access to my directory on the machine. (I do not have a sudo password.) I tried using the chmod command in unix, but of course I don't have high-enough permissions.
I've googled a fair amount and haven't come up with too much other than the already-mentioned and failed chmod commands and functions.
Anybody know how to get php to create a new file with more liberal permissions?
is there a way to generate the url that a user typed in order to view a page? for example, if someone goes to "http://whatever.com" or "http://www.whatever.com", is there some kind of function that can return this value?
I really appreciated you guys' help last time. Here's another question.
It's easy to implement a calendar of the current month, by using date("m") and date("Y") to get current time. How can I implement "Prev" and "Next" buttons to get previous and next month's calendar? I mean how can I associate the buttons with the correct month and year values? (I can't just use date("m")-1, coz if I click "Prev" again, it would still be the same value.) There has to be an easy way to do this without using JavaScript or things like that, right? I need some inspiration, or even source code.
I want to be able to let $refer be the refering url but I'm not sure if I can get that from the HTTP headers, can I?
Application: Basically, what I want to do is, if the user gets the 404 error page then the refering URL (obviously with a dead link) will be put into a database for review. I can do all that, I just need to know how to set $refer.
however the problem i have is that i can't get it to go any deeper than a second array in. i've been racking my head to think of a way to get the code to recur upon itself, however i can't think of a methodology for that (this is inside a while).
if (!empty($comment['parentid']))
{
if (array_key_exists($comment['parentid'], $this->temp->comment))
{
$this->temp->comment[$comment['parentid']]['child'][$comment['commentid']] = create_comment($comment);
}
}
else
{
$this->temp->comment[$comment['commentid']] = create_comment($comment);
}
can anyone help me out as i'm totally lost now.
oh the create_comment() function is one of sheer simplicity
I'm already familiar with creating .xls files with PHP, though I only know how to code so users are prompted to open/save. What I'd like to do is save the xls on my server, instead of prompting users to do something with it. Can anyone help me?
The old get variable was section, which I have changed to page_id. I am trying to get it to redirect to the index and all I get is "No input file specified." I am not even sure where that error is coming from.
Any ideas?
EDIT: WTF?
I copied everythning to a dev directory to work on, and it works. On top of that, the live version works.