Jump to content

mikr

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by mikr

  1. If I understand you right, you have a video table with the following fields: name desc videoid comments And you want comments to contain a comma delimited list of user id and comments. So, what if the user's comments contain commas? Having worked with csv situations, I always aim to avoid them when possible, so here's a suggestion... Why don't you create one new table (that's all you need) with the following columns: id, datetime, fk_video_id, user_id, comments Then you can have multiple comments for each video, and you can timestamp em and it makes it easier to delete unwanted messages.
  2. First, a minor point on the html. You've named the input and the select both "aNumber[]", and as your comments indicate, select ought to be named "select[]". Second, I thought I'd walk through your code and tell you what it tells me. <?php $i = 0; // initialize $i // for every element $key in the array $_POST["aNumber"], add 1 to $i foreach ($_POST["aNumber"] as $key) $i++; echo $i; // so $i = count($_POST["aNumber"]) $j = 0; while ($j<=$i) { // loop $i times. // append the arrays $_POST["aNumber"], $_POST["select"], and $_POST["extOp"] // togther, with inner comma's and set $content. $content = $_POST["aNumber"] . "," . $_POST["select"] . "," . $_POST["extOp"]; $j++; } echo $content; // echo $content which will probably echo... // array(),array(),array() or thereabouts ?> Now, some suggestions... <?php $content = array(); for ($i = 0; $i < count($_POST["aNumber"]); $i++) { $content[] = $_POST["aNumber"][$i] . "," . $_POST["select"][$i] . "," . $_POST["extOp"][$i]; } // at this point, I'm a little unclear as to what you want to do with the extra rows. // if I understand you, you just want to add them in a comma seperated form to the $content // string. So... $content = implode(",",$content); echo $content; ?> Ok, some points. First, two reasons your while loop didn't work. First, you were appending the the arrays together and not their individual elements (see where I add [$i] after each name). Second, you were setting $content each time through the loop, thus wiping out all previous values of $content. I decided to make $content an array (initially) so that I could then implode the final results into a string. Also, your foreach loop can be replaced by a call to the function count() which returns the number of elements in an array. Hope all this helps! Good luck.
  3. Do you still have some of the older forms that worked? If you do, then try them out and see if they still work. If they do, try to compare them with what you've got now. Otherwise, my other suggestion is to check if sendmail_form is set: <?php print ini_get("sendmail_from"); ?> If it isn't set, try setting it before executing mail() without the fourth variable. <?php ini_set("sendmail_from", "fromaddress@host.com"); ?> At some point this may be a server problem, and if it is, the question becomes whether you have access to the server or not. If you don't, you'll have to take it up with the owner. If you do, you may try looking at the sendmail logs and seeing what they say.
  4. In the past, did you have a header containing a From in it? The php manual suggests that if sendmail_from is not set in php.ini and a custom From header is missing, sendmail may fail. Try adding as a fourth variable, "From: yourself@yourwebsite.com\r\n" .
  5. Like Ken2k7 said, I assumed you would change the variables as they properly should be changed. So, assuming that, and you are still having trouble... You need to figure out if it is something you are doing, or something wrong with the server. So you start small. Don't use any variables, just attempt to use mail... <?php mail('me@wherever.com', 'Test Subject', 'Test message'); ?> Replace me@whataever.com with your email address, of course. So, if that works, then replace 'Test Subject' with your $subject variable and test again, then 'Test message' with your $body variable. You may be running afoul of mail in some manner.
  6. Ooh. Good catch. That's embarrassing. That's what I get for not running code through php -l...
  7. It would be as simple as: <?php if (mail($to, $subject, $message)) { echo "Mailer accepted mail."; } else { echo "Mailer did not accept mail."; } ?>
  8. Taking what Ken2k7 said into account, and assuming that $v is an array containing fieldnames, the following would work (I added 'Date' and 'Time' to the array since they were both header names and field names according to your code). <?php $v = array('Date', 'Time', 'Height', 'Weight'); // To print table header of Date and Time echo " <table width='120%' border='1' cellspacing='0' cellpadding='0'>"; echo "<tr> // To print table header for the selected variables ($var) foreach ($v as $var) { echo "<th bgcolor='#CCCCCC'>$var</th>"; } // <- no problem with this echo "</tr>"; while ($row = mysql_fetch_array($result)) { foreach ($v as $var) { echo '<tr><td align=center>' . $row[$var] . '</td></tr>'; } } //end while ?>
  9. Perhaps your server can't handle the format of sending to "NAME <EMAIL ADDR>" (are you running on Windows?). It sounds like it's executing the line after mail() properly. If so, then something isn't right about your mail() command. Some folks seem to suggest there needs to be a space between the above NAME and '<'. Maybe that's the problem? I assume you've changed $to_name and $to_email for the purpose of this discussion and that they are properly filled out. You could try checking if mail() returned true or false. True, just because the mail was accepted for delivery, it does not mean the mail will actually reach you, however, it will tell you if the problem is between you and your mailer, or your mailer and the world.
  10. Since simplexml_load_file() is read only, that shouldn't be a problem, should it? However, just for fun, supposing you still want to lock it, you don't have to lock the file itself. Let's say your file is whatever.xml. Then, if you want to be sure you are the only one reading whatever.xml (but you can't use fopen/flock), you can use fopen/flock on whatever.xml.lock. Essentially, you are creating your own lock system using filenames. So, when you are about to read the xml file, you first attempt to fopen/flock the xml file with a ".lock" extension. If you can do that, then you go ahead. If not, then someone else has a lock. There are two downsides. If a process dies before the lock file is deleted, you are stuck having to ftp in (or whatever) and delete it by hand. Also, you have to police your own locking and unlocking.
  11. If I understand you right, you are saying that when the user isn't logged in, it won't submit the data to the db (which is good), but it also won't redirect to a new page (which is bad). A couple possibilities. If there is a blank line above your php code in that file, the header will fail to work. You can't output any html (even a blank line) before the header, else the header will be ignored. Second, Location requires an absolute address. Some clients allow a relative one (such as you are using), but those following the standards will not. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself. Capitalization is also important. Capitalize the L. Hope all that helps.
  12. Here's an approach that uses regular expressions. May not be what you need, but may help you in your quest. <?php $data = "textFileNameHere.txt"; $contents = file_get_contents($data); $res = array(); preg_match_all('/\*start\*(.*?)\*stop\*/',$contents,$res,PREG_PATTERN_ORDER); $res = $res[1]; print_r($res); // prints an array of matches ?>
  13. I grabbed this from the php documentation: <?php $fp = fopen("/tmp/lock.txt", "w+"); if (flock($fp, LOCK_EX)) { // do an exclusive lock fwrite($fp, "Write something here\n"); flock($fp, LOCK_UN); // release the lock } else { echo "Couldn't lock the file !"; } fclose($fp); ?>
  14. Why don't you reshow your code as it now stands and a short comment on expected behavior. Otherwise, I'm not sure if by getting the error worked out, you mean you removed the semi-colon from the while statement or not.
  15. Is there a possibility that you aren't setting $id correctly? You may wish to echo $sql to find out what the SELECT statement looks like. If you have access to something like phpMyAdmin, you could do what I often do, which is grab that select statement that you just echoed and try it in phpMyAdmin. Another possibility is that one of your fields is a reserved keyword for mysql. I often hedge against that by using back-quotes (` - usually under the tilda on your keyboard) around all fieldnames (ie `id`,`Playername`,`Password` ...). Other than that, more info on what you're experiencing would be helpful.
  16. When you create your captcha image, you set a session variable ($_SESSION['key']). When you test for the correct value, you test a cookie variable ($_COOKIE['tntcon']). That might be your problem.
  17. It looks to me like you are using some reserved keywords. I think in and out are both reserved keywords (google mysql reserved keywords and the first on the list will take you to a mysql page showing a list of such). The simple solution is to put backwards quotes ( ` ) around each field name ie( instead of review='$review' have `review`='$review' ). Also, as an aside, I sure hope you are validating your input, because else, you're leaving your db wide open. I hope that my above comments about reserved keywords help you out.
  18. I can tell you why the echo "hello" didn't work. <?php echo '<div id="feature" class="'.$class.'"> '.self::getModule($featured).' </div>'; ?> The command "echo" is expecting a value returned to it from self::getModule() which it will then place within its string: ie '<div id="feature" class="$class">{return val from getModule}</div>' . getModule() isn't returning a value, it is just echoing "hello". Amusingly, it executes its echo before the outer echo. So, "hello" ends up in front of the div, while the div ends up empty. Instead of echo "hello" in getModule(), you want to return "hello". That will solve that problem.
  19. Also, just to make sure you know this (if you do, my apology). If you have form elements in a web page that have the same name with square brackets at the end (ie element[], element[], and element[]), then, when they get submitted to php, they will end up in $_POST['element'] as an array. So if you have three fields: <input type="text" name="element[]" value="fred" /> <input type="text" name="element[]" value="frank" /> <input type="text" name="element[]" value="bertha" /> These three field will appear in $_POST as follows: <?php $_POST['element'][0] = 'fred'; $_POST['element'][1] = 'frank'; $_POST['element'][2] = 'bertha'; ?> Which is really cool, because then you can easily do an implode on those values alone: <?php $string = implode(',',$_POST['element']); print $string; // will print fred,frank,bertha ?> And I know you can do this with javascript, as I had to implement this type of feature in an application just last week. PHP will receive them in the order that they appear within the html document (so, if you give the user the tools, they can rearrange them, if you'd like).
  20. When you want to create comma separated items, implode($glue,$pieces) is awesome. In your case, you want to put all of the post variables you want into your own array ($pieces) and then use as your glue ",". That way, you only get commas in between each item. <?php $array = array(); // our empty array foreach($_POST as $key => $value) { if ($value == "Submit") { } elseif (strpos($key, "bp") !== false) { array_push($array,$value); // adding $value to the array $array } } $theString = implode(',',$array); // creating our string. // if you want quotes around each, then you would have done... // $theString = "'".implode("','",$array)."'"; // those are double quotes surrounding single quotes. echo $theString; ?> Also, the reason why it repeated the 'd' in your code is because you were printing each letter within the loop, but outside of the if/else statement. So, when you got to the submit button, while it didn't process the submit button like a bp element, it still executed the line that read: echo $theString. And $theString still had the value "d," in it.
  21. You'll want to use ob_start() and ob_get_clean() around curl_exec().
  22. While you are looping through $dir (while (($filename1 = readdir($dir)) !== false) ), you cannot reassign $dir. The inner loop needs a new variable ($dir2?). You are, in essence, stepping on your own variables.
  23. @radi8 Correct me if I'm wrong, but since 'bp' is at the zero position, don't you need to write: <?php if (strpos($key, "bp") !== false) { } ?> Because, while the zero position is not false, it is also, technically, not true? At least, that's what the manual seems to say: @headmine Question: wouldn't it be easier to let php create an array out of a series of form elements with [] at the end of their names (ie <input name="bp[]">)? Then you could implode() one element.
  24. I'm not sure what you are asking, but three things. By setting $count = count(...) + 1, you'll have the for loop iterate one beyond your total number of files. I'm guessing, your output below, would have futher read "There is : 4". Also, you may gain better traction, using move_uploaded_file() rather than copy(). PHP docs suggest that if you wish to use copy() in a move sense, then use rename(). You're killing your $i counter (probably why it doesn't run more than once). You have an inner for loop using $i (which kills the $i for the outer loop). Change that to $k or something else, and it should run through 'em all. If that is confusing, think of it this way: whatever value $palsize is, that will be the value of $i after the first image is uploaded.
  25. I believe you need to join the tables <?php $query = "SELECT header.fileName FROM header JOIN vals ON header.headerId = vals.headerFk WHERE vals.word LIKE '%" .$var."%' order by header.headerId"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.