Jump to content

rationalrabbit

Members
  • Posts

    16
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    Yike! He's doing it again!
  • Age
    50

rationalrabbit's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Really appreciate the timely responses from both of you. Unfortunately, I'm still unsure of the solutions. $pattern = '~([href|title|class]+)="([a-zA-Z0-9:/.,; ]+)"~'; $string = '<a href="http://phpfreaks.com" title="Coding Freaks" class="myClass">Don\'t click here, it is addicting</a>'; preg_match_all($pattern,$string,$matches); Very nice way of getting the attributes into an array. But how would I get the string? (Other than going character-by-character from each <a to > $search[]='/class=".*?"/'; Wouldn't this replace the class in the div? (which, of course, I don't want to do) You have both gotten me into learning more about preg_replace; preg_match - something I should have done a long time ago. I finally went to a JavaScript solution: $IntroText = str_replace('<a','<a onclick="Lightview.show({ href: this.href, rel: \'iframe\', title: this.title, options: {fullscreen: true }}); return false;"',$IntroText); I tried this earlier, but there was a conflict between the href and the onclick. Adding "return false" solved that. So a link comes out looking something like this: <a onclick="Lightview.show({ href: this.href, rel: 'iframe', title: this.title, options: {fullscreen: true }}); return false;" href="http://www.godzilla.com" title="Godzilla">Godzilla on the Web</a> A bonus is the link is still there, which degrades nicely if someone has JavaScript turned off. Thanks again. Your help is very much appreciated. I would still like to know if my 2 comments above, pertaining to your solutions, are off base or not.
  2. You might have <a class="MyClass" title="Godzilla" href="http://www.godzillaslair.com">Godzilla</a> or <a title="Godzilla" class="MyClass" href="http://www.godzillaslair.com">Godzilla</a> or <a href="http://www.godzillaslair.com">Godzilla</a> also, in the same main string, you may have <div class="MyClass"> How would you differentiate these with preg_replace? Using PHP's DOM functions, I could grab the attributes and place them in an array, so I would have something like this $Arr[0][class] = "MyClass"; $Arr[0][title] = "Godzilla"; $Arr[0][href] = "http://www.godzillaslair.com"; $Arr[1][class] = "AnotherClass"; $Arr[1][title] = ""; $Arr[1][href] = "http://www.anotherlink.com"; etc., then alter the values and the first 'a' tag would be the first array, etc., but that would still be pretty clutsy, because I would have to save the old values for replacement comparison. Maybe there's something I don't know about preg_replace (very possible) but I don't know how it would be used. It's not like I can just search for, as an example, "class='MyClass'" and replace it, and it is not like I can search for "<a class="MyClass", etc.
  3. Obtaining the attribute values is no problem. The problem is knowing where the attribute values came from to put them back. There may be several links on a page.
  4. Thanks for the reply MMDE, but I fail to see how preg_replace would solve the problem. Every link is different. There is no pattern to match other than "<a" and ">", and I have to be able to exact match everything in between so that I can save the href, and change, replace, or create the others. I can pull the attribute values and put them into an array and say, "there's no class, so this attribute string needs a class" or "This has a class and I can add a second class to it, or replace it", but I would need to take the full string, change it, and replace the old string with the new string, or replace each selective attribute. I suppose I could use strpos to know where to put it back. Just seems like the must be an easy way to replace those attributes. Without an ID, Maybe not. I could iterate through a particular 'a' tag, character-by-character till I get to the ">" character, but that's a lot to do at page load. If there was just some way of replacing ... like "this tag does not have a class, so create one" or "This tag has a class, so add to it" or save the href, remove all attributes and put the href back and create a new class and title - all easy to do. It's putting it back into the big string that's got me puzzled.
  5. I have a site that allows members to create pages. These pages consist of small sections some of which HTML can be entered. To keep visitors from straying away from the site, any outside urls are brought up in a modal window. Using inline attributes, a class has to be created (or added to), and the title tag requires some special characters. I can probably get around this by inserting an onclick or something, but there must be a way to replace attributes, and I am at a loss. The text segments are stored in a database. What I want to do is change the <a> tag attributes as the page is created. So I have a segment of text "$TheText" and I want to change or replace the attribute values. For instance, If $TheText contains an 'a' tag that looks like this: <a class="MyClass" title="Godzilla" href="http://www.godzillaslair.com">Godzilla</a> I would want to change it to <a class="MyClass Lightview" title="Godzilla :: {Lightview's parameters}">Godzilla</a> Or even just replace the attributes entirely, so it would look like <a class="Lightview" title="{Inserted Title} :: {Lightview's parameters}">Godzilla</a> In other words, just replacing the attribute values. Of course, I need to see if the attributes exist. I know how to do that and how to get their values. But all that tells me is that I have an 'a' tag in the text with those values for those attributes. I cannot, for example, then do a str_replace in the first example, because there may be another tag in the text with the "MyClass" class. I can iterate character by character between <a and </a> but there must be a better way. I'm no good at regex, so I haven't even attempted that. Any suggestions would certainly be appreciated.
  6. Hmmm - No one answered this? Well, just in case someone stumbles upon it as I did, you will want to use Pear, which is probably installed on your server. Here are a couple of links for information: http://email.about.com/od/emailprogrammingtips/qt/et073006.htm http://www.cyberciti.biz/tips/howto-php-send-email-via-smtp-authentication.html CodeWorxTech's free mailer: http://phpmailer.codeworxtech.com/index.php?pg=tutorial
  7. I'm embarrassed to say I had not thought of checking logs. I will have both of your suggestions in mind as I test the second database, which will be a few days yet. Thanks.
  8. I took the code down to basic bare bones. Still had the same problem. I then removed the auto-increment from the ID field and moved the primary key to another field, and saved two entries without the duplication problem. I then re-instigated the auto-increment in the ID field, and moved the primary key back to that field. I no longer have the problem, and everything is as it was originally. ??? I still have an identical database that I have not altered. I will try to do some more careful tests with that database, as I really want to know the problem source. I'm quite swamped right now, so it will be several days before I have the time to do that, but I will post the results here. As far as isset($_POST['Submit']), I would think that $_POST['process'] == 1 should work as long as the value is reset to 0 or undefined. I did not do this, however, until after the insert code. Should not matter though, should it? In testing, I also halted the program and exited directly after the insert code, Neither of these solutions prevented the problem. The code is working fine now, using "if($_POST['process'] == 1)", so I would say that does not appear to be the problem.
  9. devknob - I spent hours working on this, including a lot of time searching the web for other people with the same problem, or some MySQL guru who might have a clue, and coming up empty handed. I've been told things like "well, if you validate a unique field, you won't have that problem". True, but I want to find out why the problem is occurring - not hide it and pretend it didn't happen. Currently, the problem is gone. All I can tell you is that I added two fields to the database, turned off auto-increment on my "id" field, moved the primary key to another field (and forgot to remove the primary key from the auto-increment field), saved two records, and there were no duplicate saves. I then turned auto-increment back on in the id field, removed the primary key from the second field, and all is working fine. At this point, I would say the problem really appears to be a MySQL bug. If you read my other post ("Saving Data Twice"), you would remember that I have two identical databases (except they are different MySQL versions). I'm swamped with work, and have to go out of town, but next week I will go to the other database, and do a lot more careful investigation. When I am done, I will post my findings here.
  10. That, of course, was my first thought, especially since the file is posting to itself. However, I have tried different things; clear($_POST); header("location: otherfile.php"); exit and finally separated the HTML and PHP into to different files and posted to the PHP file. All these had the same result. I also tried halting the file and waiting for user input directly after the SQL insert, and then physically checking the database before proceeding. I have taken the code down to the bare bones and only 4 fields and still the same result. I think the problem has to be in the database setup, although it is quite simple: 15 fields; integers; tinyintegers; varchar; date; char & float 1 auto-increment id field as primary two indexes (first & last name)
  11. Ah ... pardon me? This is a real problem. And what does "got this thing" mean? Did you post here to be productive or sarcastic? Further testing appears to reveal this may be a MySQL problem, as some inserts, rather than inserting the same data in two different records, inserted the data in one record and duplicated another, already existing record in the database. I have run this on two different databases on two different servers. Further research reveals that I am not the only person experiencing this problem. The form is very simple - in a nut shell: <?PHP if ($_POST['process'] == 1) { Place values from the POST variables back to regular variables and perform some simple validation Create error messages for fields that do not validate Set error variable to true if any fields do not validate if all fields validate (error variable is false) { if (!$connect = mysql_connect($HOST, $USER, $PASSWORD)) { echo ("Error: Did not connect to database!"); } else { mysql_select_db($DBName) or die ('Unable to select database!'); $SaveIt = "INSERT INTO CheckList (NameFirst, NameMid, NameLast, Position, StartDate, Salary, Hourly, Status, App, LCV,DirDep, EmpBook, W4, I9, SSCard) VALUES ('$NameFirst', '$NameMid', '$NameLast', '$Position', '$StartDate', '$Salary', '$Hourly', '$Status', '$App', '$LCV','$DirDep', '$EmpBook', '$W4', '$I9', '$SSCard')"; if(mysql_query($SaveIt)) { echo('<div style="border:2px solid #000000; background-color:#0000FF; color:#FFFFFF; padding:3px; font-weight:bold; text-align;center;"> Your Data Has Been Saved </div>'); clear($_POST); } else { echo('<div style="border:2px solid #000000; background-color:#FF0000; color:#FFFFFF; padding:3px; font-weight:bold;"> There was an error in processing the data </div>'); } } } else // nothing has been submitted yet { set variables for form } } ?> <html> Print top of page <? Print any error messages if fields did not validate ?> <form name="NewEmpCheck" method="post" action="newemployee.php"> // This form, of course input fields, ending with: <input type="hidden" name="process" value="1"></input> <input type="submit" name="Submit" value="Submit"></input> <input type="reset" name="reset" value="Reset"></input> </form> </html>
  12. See More on this subject under "Insert doing double duty" (I did not notice this when I posted.)
  13. I am having the same problem and I can not figure out why. I didn't see this post, and created one called "Saving Data Twice." I've placed an exit after the save and even cleared the post variables, and it still happens. I believe it is not doubling the declared insert, but rather duplicating the current record in the database. I believe this because, while testing, for a while, rather than saving the same data twice, it was duplicating another current record in the database. I'm sorry I can't give you any more detail than that - I don't know what may have moved the pointer, but it may be an eye opener. That said, and still being uncertain, I need to ask if you are posting to your form file or a different file?
  14. PHP 5, MySQL 5 I have a small form that is posting to itself by setting a variable which is read at post time to detect the submit. (if $_POST['variable']) I have several other forms very similar that work fine (except that they use $_SERVER['PHP_SELF']; in the form action, where this one uses the file name). For some reason, this form is entering two records with each save to the database. I've gone through the flow, put an exit right after the save, cleared the post variables directly after the save - still does the same thing. Following is my save routine (this is the only thing very different from my other forms): $SaveIt = "INSERT INTO CheckList (NameFirst, NameMid, NameLast, Position, StartDate, Salary, Hourly, Status, App, LCV,DirDep, EmpBook, W4, I9, SSCard) VALUES ('$NameFirst', '$NameMid', '$NameLast', '$Position', '$StartDate', '$Salary', '$Hourly', '$Status', '$App', '$LCV','$DirDep', '$EmpBook', '$W4', '$I9', '$SSCard')"; if(mysql_query($SaveIt)) { notice that data has been saves } else { error message } Any ideas would certainly be appreceiated!
  15. Hah! Should have been '$VacStatus' instead of $VacStatus in the Query (needed quotes)
×
×
  • 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.