Jump to content

DavidAM

Staff Alumni
  • Posts

    1,984
  • Joined

  • Days Won

    10

Everything posted by DavidAM

  1. I'm not real sure, but I think you need to change $groups[$i['id']] to $groups[$i]['id'] and $groups[$i['links']] to $groups[$i]['links'] I don't remember ever seeing multi-dimensions written the way you have it. But the line numbers don't match up. Did you cut out some code or something?
  2. Based on your original code, $groupidrow is an array, so the reference should be $groupidrow['id'] (unless you changed something that you're not showing). I don't know why you have the foreach loop in there twice, the first one is completely unnecessary since you overwrite the only value it creates in the second one. To get all of the keywords inserted into the database as separate rows, you will have to move the INSERT code up into the foreach loop. The way you have it written, $keyword will be the value of your 5th keyword posted and the first four have just been ignored. If this is the code you are still using, move it inside the loop. $involv = "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls) VALUES ('','{$keyword}', 2, '{$row['userid']}', 0, 1, '')"; if (!mysql_query($involv)) { die('Error: ' . mysql_error()); }
  3. Your form will submit an array of keywords in the super-global $_POST. You will have to loop through that array using something along these lines: if (isset($_POST['keyword'])) { // Always check to see if there is something to process foreach ($_POST['keyword'] as $ind => $keyw) { // $ind is now the index of the keyword; i.e. 0, 1, 2, etc. // $keyw is the keyword the user typed (or empty) // **** CHECK THE USER'S INPUT TO MAKE SURE IT IS VALID // Insert the data into the table } // end foreach } else { // end if(isset($_POST)) // No data submitted, what will I do now? } // end else
  4. // Specify the name of the file containing the quotes to be loaded $quotes = "quotes.txt"; /* Load the entire file into an array. This creates an array with each element containing one line from the file. A line ends with a new-line and the new-line is kept on the end of the line in the array. The array will be indexed starting at zero. */ $quotes = file($quotes); /* seed the random number generator so we get a more random random number */ srand((double)microtime() * 1000000); /* count($quotes) returns the number of entries in the $quotes array. This is the number of lines loaded from the file. rand() returns a random number between the two values supplied (in this case zero and count()-1). We have to subtract 1 from the count because the index starts at zero and therefore the maximum is one less than the count. */ $ranNum = rand(0, count($quotes)-1); // Print the Nth line from the quote file (where N is the random number we just generated) echo ($quotes[$ranNum]);
  5. is coming from the var_dump($involv); its a variable dump usually used during debugging to see what is in a variable. You should probably remove that line from the final page. is being echoed by your script at echo "$row record added"; although I don't see where $row is defined. So, it's not an error message, it is output that you told the script to produce.
  6. It is possible, and fairly simple. HOWEVER, there are several gotchas that could cause significant problems with the result. RTF is a markup language, kind of like HTML. However, it has some different rules and very different structure and tags. Open one of your RTF files in notepad (or your favorite text editor) and have a look. RTF elements are grouped together using curly braces ( { and } ) and always start with \rtf. So a minimum rtf file would be {\rtf } which is an empty document. So to merge two RTF files together the way you described, you would load the first one and drop the ending brace, add a page command (\page), then add everything from the second file after the openning brace. BUT WATCH OUT!!!! All commands in an rtf file start with a back-slash, and end when whitespace is found OR an new command starts (with another back-slash) or a new group starts (curly brace). So to change the color there is a command like \cf1, which changes to color 1 (one). But what is color 1 you ask? I'm glad you asked that. At the beginning of an RTF document is a color table. It lists the colors that are used in the document, ex: {\colortbl ;\red0\green128\blue0;\red0\green0\blue255;} So in this color table, color 1 is green and color 2 is blue. The colors are added to the color table in the order that they are introduced to the document. NOT the order they appear in the document. So in this case, I made something green and then later made something blue. The blue text may be before the green or not, it's the sequence of adding them that matters. There is also a font table at the beginning of the document that behaves in the same manner. THIS IS A PROBLEM in the merge instructions above because a well-behaved rtf reader will ignore unexpected and unknown tags. The color table and font table belong at the beginning of the document, so these tables from the second document, appearing in the middle of the document are ignored. If the color tables or font tables are different between the documents, the second document will not be formatted properly. There is also a styles table, which I have never analyzed much, but I expect it behaves in a very similar manner. So, unless you have complete control over all the RTF files and you KNOW you will ALWAYS create the documents using the same colors and fonts and styles IN THE SAME ORDER your merge is going to break down. There is a lot more going on in the "head" of an rtf document (margins, tabs and indents, default font, color, etc) that may or may not be "obeyed" in the (second) merged document. To get around the tables issues, you could load the two documents separately, grab the color tables and compare them. Merge them into a single table and do a search and replace in the second document to use the color indexes from the merged table. Do the same with the font table (and possibly the style table). Throw away the tables from the second document and append the rest of it to the first (with the \page in between). It will take some work, but is probably doable.
  7. That's too bad. It seems like such a waste. But good to know. I guess I'll stay off my soapbox for a while.
  8. corbin, all very good points. Normalize the data and use logical datatypes. That will definitely improve performance. I don't know the specifics on how MySql determines the plan for a query. But I think it could make a difference. For example: Table: Books; Columns: ID (auto-increment & Primary Key), ISBN, Title, Author, Publisher, Synopsis, some other stuff; Index: (ID, ISBN) Table: Sales; Columns: ID (auto-increment & Primary Key), dateSold, BookID, qty, price, maybe some other stuff too; Index: (dateSold, BookID) SELECT b.ID, b.ISBN, s.dateSold FROM Books b JOIN sales s ON s.BookID = b.ID WHERE dateSold BETWEEN 2008-01-01 AND 2008-12-31 This query is covered by the indexes. If you use the Date index on the Sales table, and the ISBN index on the Books table, you never have to look at the data pages. So there are fewer disk seeks and reads. Now if instead of writing the query that way, I write this (because I'm too lazy to be specific about what I want and I'll just reference the fields I need on the front-end): SELECT * FROM Books b JOIN sales s ON s.BookID = b.ID WHERE dateSold BETWEEN 2008-01-01 AND 2008-12-31 The server has to read the data pages because I've asked for all of the data from the tables. This would probably use the Date Index on Sales and the Primary Key (ID) on Books. Or it might just do a table scan on one table or the other. Or it might use the same indexes. However, it will definitely have to read the data pages in addition to whatever index it uses because it has to retrieve ALL of the data from the selected rows. And that was my primary point. Using Select * can cause additional reads that are not needed if you don't actually need everything. This is a forced example, but I think it makes the point. Back when I did this for a living, I actually needed to create composite indexes to cover a query that would have run much longer than acceptable without it. (I did not design the database, and could not correct the design as it was a third-party application). Yes, the additional indexes used a lot of disk space, but it was a trade-off.
  9. Well, I stand corrected and I learned something new today . Thanks, I'll have to remember that.
  10. Glad to help. It's actually kind of fun. Do you want to make each Job Entry a separate form, so clicking Submit will only send 1 job to update? You could move the form openning and closing tags inside the loop: <?php while($row=mysql_fetch_array($result)){ ?> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' value="<? echo . $row['JobNumber'] . ; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' value="<? echo $row['JobTitle'] . ; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]'value="<? echo . $row['JobCompany'] . ; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]'value="<? echo . $row['JobLocation'] . ; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><input type='textarea' name='JobDescription[]' > <? echo . $row['JobDescription'] . ; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> <?php } ?> I guess you could do it that way. This might confuse the user. You might want to add some kind of visual separator between entries to help clarify the fact that they are individual forms. I am NOT 100% sure that all browsers will treat that (forms inside a table) correctly or that it is even "legal" by the specs. But I have put multiple forms inside a table before, I just have not tested it in multiple browsers.
  11. right, I guess I should actually RTFP. I thought OP was listing all the data to the page in the loop and wanted to add the count at the end. If there is no need to list the data, then the SELECT SUM is definitely the way to go. Uses less resources all the way around.
  12. Looks like we got all of the data back, and in the expected elements of the array. I don't see why it would be updating incorrectly. It must be something small that we're just not seeing. Take those three lines back out and maybe echo the SQL instead of sending it to the server to see what we are telling it to do. Wait, there it is. Something small, easy to miss: $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]. "', JobCompany='".$JobCompany[$i]. "', JobLocation='".$JobLocation[$i]. "', JobDescription='".$JobDescription['$i']. "' WHERE JobNumber=".$JobNumber[$i]; Look at the subscript on JobDescription, you've put quotes around it (the $i). I bet that is messing up the SQL statement. (I just added the line breaks so you can see it a little easier.) Remove those single quotes and give it a whirl.
  13. Dan'O to the rescue again That was my first thought, and then I second guessed myself. Second guesses are almost always wrong. And octal still confuses me, sometimes. :'( Check the owner and/or group of the files (and directories) and compare that to the user/group that the server is running as. You'll likely have to change one or the other on the files. You do NOT want to make them WORLD writable (i.e. 777). Daniel0, what's the best practice on this, change the group to match the server so the site admin still owns them, or change the owner to the server and set the group? I think the former is better, but I don't have any sites published yet, so I don't have any "real world" experience to base that on.
  14. Hmm. let's see what is getting posted. Back up near the top let's add a couple of lines. Find if(isset($_POST['Submit'])){ and add this after it: print '<PRE>'; print_r($_POST); exit(); This will display the contents of the POST array and then exit (no sense messing with the data until we figure it out). You can leave the rest of the code as is. Post the results so we can see what the problem is. Make sure you xxxx-out any sensitive information (if necessary).
  15. I'm not sure, I was kind of hoping the statement would trigger a suggestion from someone who knows a little more the I do. Basically, the error message indicated it was trying to reference ./cache/cache_amazon_ (looks like you truncated it when you posted). The ./ at the beginning indicates the current working directory, which, as I understand, is the path of the main script executing (from the URL). Of course if you changed directories (i.e. chdir() or through some script or system call), it could be referring to another directory. I avoid this issue by always using absolute paths. Since, in general, I know where the file should be. I have defined a constant (C_PHP_ROOT) which is the absolute path of where my scripts are. So to open a file, I might use: $fp = fopen(C_PHP_ROOT . 'cache/whatever.ext'); and then I don't have to worry about not finding the file. You might echo out getcwd() just before the open and see what directory you are in just to know it is the correct one.
  16. from the PHP manual http://us.php.net/manual/en/function.fopen.php Check the settings for safe_mode and open_basedir. Since you moved to a different server, one of these may be causing your problem. Also, $filename seems to be a relative filename. Are you sure it is referring to the file you think it is?
  17. Well, I just whipped that out real quick, but I see a closing parenthesis out of place. This: echo $done . ' updates succeeded (out of ' . $count . ' attempted.'); should actually be this: echo $done . ' updates succeeded (out of ' . $count . ' attempted.)'; Also be sure to use the $_POST on all of those lines inside the loop, I only did the first one in the sample code I sent.
  18. Well, you are inside a loop, so there would be one SQL statement for each pass through the loop. The error is at the end of the statement: WHERE JobNumber= equals what? In fact there are no values supplied to the statement at all. So, now I see what I missed before: $JobTitle[$i] = mysql_real_escape_string($JobTitle[$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $JobTitle (and the others) have not been defined. At least, they are not defined in the code you provided earlier. If you are looking for the POSTed values it should be: $JobTitle[$i] = mysql_real_escape_string($_POST['JobTitle'][$i]); Let me point out one other problem which might cause you confusion later. You are populating the table with data from the database, and allowing the user to change it. Then when they make changes and Submit, you are populating the table from the database, THEN updating the database with the posted changes. The data you see on the page is the data from the database BEFORE it was updated. So, you're going to think it did not update. I know it feels counter-intuitive, but you probably want to put the database update code up BEFORE you select for display. Watch out, because you will not have the $count for your loop. For example (this is just a quick swing from your original code, but you get the idea) <?php // connect to database $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("job_listing", $con); // If user POSTed an update if(isset($_POST['Submit'])){ $count = count($_POST['JobNumber']); $done = 0; for($i=0;$i<$count;$i++){ $JobTitle[$i] = mysql_real_escape_string($_POST['JobTitle'][$i]); $JobCompany[$i] = mysql_real_escape_string($JobCompany[$i]); $JobLocation[$i]= mysql_real_escape_string($JobLocation[$i]); $JobDescription[$i] = mysql_real_escape_string($JobDescription[$i]); $JobNumber[$i] = mysql_real_escape_string($JobNumber[$i]); $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription['$i']."' WHERE JobNumber=".$JobNumber[$i]; $result1=mysql_query($sql1); if ($result1) $done++; } echo $done . ' updates succeeded (out of ' . $count . ' attempted.'); } /* NOTE: $result1 will NOT be defined if there are no updates. Also, $result1 will be TRUE or FALSE based on the results of the LAST call. */ //if($result1){ // echo 'all done'; //} // Show the current data $sql = "SELECT * FROM jobs"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table class="listing"> <form method="post" action="<?php $_SERVER['REQUEST_URI']; ?>"> <?php while($row=mysql_fetch_array($result)){ ?> <tr> <th>Job Number:</th> <td><input type='text' name='JobNumber[]' value="<? echo . $row['JobNumber'] . ; ?> "> </td> </tr> <tr> <th>Job Title:</th> <td><input type='text' name='JobTitle[]' value="<? echo $row['JobTitle'] . ; ?> "> </td> </tr> <tr> <th>Company:</th> <td><input type='text' name='JobCompany[]'value="<? echo . $row['JobCompany'] . ; ?> "> </td> </tr> <tr> <th>Location:</th> <td><input type='text' name='JobLocation[]'value="<? echo . $row['JobLocation'] . ; ?> "> </td> </tr> <tr> <th>Job Description:</th> <td><input type='textarea' name='JobDescription[]' > <? echo . $row['JobDescription'] . ; ?> </textarea> </td> </tr> <tr> <td> </td> <td> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </form> </table>
  19. Uh, I always thought a text field was more like a blob than a varchar. Other DB's I've worked with allocate space for the BLOB/TEXT columns in 2K chunks. Which means storing a short string in a text column actually wastes space. In any case, your final suggestion would be the preferable way to store this data unless there is some very compelling argument for a text column.
  20. mysql_error says line 1 because it is line 1 of the sql you sent (not line 1 of the php code). It is usually line 1. Try echoing the sql just before you send it to the server, then look for the " (double quote) or is it '' (two single quotes) somewhere where it doesn't belong. $sql1="UPDATE jobs SET JobTitle='".$JobTitle[$i]."', JobCompany='".$JobCompany[$i]."', JobLocation='".$JobLocation[$i]."', JobDescription='".$JobDescription[$i]."' WHERE JobNumber=".$JobNumber[$i]; echo '<PRE>' . $sql1 . '</PRE>'; $result1=mysql_query($sql1); (I use PRE so it is easier to read in the page.)
  21. Hmm, I can't see any reason for that. What is the second email? Are you getting the admin email twice or one of each? After each send, you are echoing "user email sent". How many times do you see that on the screen? Maybe you just flooded the mail server and it hasn't caught up? Comment out one of the calls to send_email and see if you get the correct result, then comment out the other (and uncomment the first) and see what happens.
  22. add this line after you execute the query: $result1=mysql_query($sql1); // after this line add if (! $result1) echo mysql_error(); see if we can find out why
  23. This is not the correct way to write a TEXTAREA <textarea input type='text' name='JobDescription[]' rows="10" cols="61" value="<?php echo $row['JobDescription']; ?>" </textarea> I never liked that it is different, and I mess it up every time, too: <textarea name='JobDescription[]' rows="10" cols="61"><?php echo $row['JobDescription']; ?></textarea> It is NOT an INPUT tag (removed that stuff), it has NO value attribute, instead the "value" goes between the openning and closing tags. So much for consistent standards.
  24. In your function: function send_email($from, $to, $subject, $message){ $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; //SETUP USER EMAIL COMMANDS if (mail($to,$subject,$message,$headers) ) { echo "user email sent"; } else { echo "user email couldn't be sent"; } //SETUP ADMIN EMAIL COMMANDS if (mail($admin_to,$admin_subject,$admin_message,$headers) ) { echo "admin email sent"; } else { echo "admin email couldn't be sent"; } } you are sending two emails -- one to user and one to admin Then in your code you are calling this function twice. So you are sending, or trying to send, 4 emails. The second send inside your function (the one for the admin) is referencing variables that are not defined within the scope of the function. You should be getting an error message and the mail() function should fail. I think if you take this second mail section out of the function (and continue to call the function twice as you do now), it should work. The messages at the end of the 'thank you' page are coming from the echo() statements after the mail() function calls. You should remove these if you don't want them or reword them appropriately. You probably have syntax errors but you are not seeing them. Add the following two lines of code to the top of every PHP script (especially during development) so you can see the errors: error_reporting(E_ALL); ini_set('display_errors', 1);
×
×
  • 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.