Jump to content

jamesjmann

Members
  • Posts

    247
  • Joined

  • Last visited

Everything posted by jamesjmann

  1. I just tried what you suggested and cut the code down to just insert one value into one field in the table, and I got the same error. Here's the revised code: <?php mysql_query (INSERT INTO fans (username) VALUES ('.$_SESSION["user"]["username"].')); ?> I tried put single quotes in the ["user"]["username"] part of the $_SESSION variable, but I get that error message either way. What in the heck is going on? I've done queries like this in the past before, so I'm like...really confused...
  2. Thanks, for the tip, but I did do that. The input comes from an html form, and gets stored in the $_POST array, and then I format those post values using a variety of functions (Like mysql_real_escape_string for instance) and assign them to session variables so I can span the registration form over multiple pages. I also like to allow the user to review their information before submitting, so that's another reason. And once they hit the submit button, the information gets inserted into the database, and I just dump my $_SESSION array, so as to "unclutter" what's going on, essentially.
  3. Is there something wrong this? If so, I'm not seeing it...I keep getting this error: Here's my code for registering a member: <?php mysql_query (INSERT INTO fans (id, username, email, password, country, region, gender, status, account, subscription, time_registered, date_registered, birthdate, name, website, age, activation_key) VALUES ('', '{$_SESSION["user"]["username"]}', '{$_SESSION["user"]["email"]}', '{$_SESSION["user"]["password"]}', '{$_SESSION["user"]["country"]}', '{$_SESSION["user"]["region"]}', '{$_SESSION["user"]["gender"]}', 'Offline', 'Inactive', 'Unsubscribed', '{$_SESSION["user"]["time"]}', '{$_SESSION["user"]["date"]}', '{$_SESSION["user"]["birthdate"]}', '{$_SESSION["user"]["name"]}', '{$_SESSION["user"]["website"]}', '{$_SESSION["user"]["age"]}', '{$_SESSION["user"]["activation_key"]}')) or die ("Could not register member"); ?> Help, please and thank you!
  4. I just found a solution: <?php $get_domain = strstr ($_SESSION["user"]["email"], "@"); $website = preg_replace ("/@/", "", $get_domain); $trim_domain = preg_replace ("/.com|.net|.biz|.info|.org/", "", $website); $format_domain = ucwords ($trim_domain); $domain = $format_domain; $email_link = "<a href='http://www." . $website . "'>Go to " . $domain . " mail now!</a>"; echo "<p class='center_align'>" . $email_link . "</p>"; ?> The above works MAGNIFICENTLY. Thanks for nudging me in the right direction!
  5. Yea like i just want the domain (yahoo for example) to be stored AFTER i use a function to find it after the @ sign. So then i can use the variable to disPlay a message with a link to the actual website of that domain.
  6. I just came up with this idea I got for my registration script, where when the user has complete all steps in the registration process, he/she comes to a page that displays this: <h1>Step 3: Activate your account</h1> <h2>Congratulations, <strong><?php echo $_SESSION["user"]["username"]; ?></strong>!</h2> <p>An email has been sent to <strong><?php echo $_SESSION["user"]["email"]; ?></strong> with an activation key, and important information regarding your account. Please check your email to complete registration.</p> Then this: $email_client = preg_match ("/[@][a-zA-z0-9]{10}\.com$/", $_SESSION["user"]["email"]); $email_link = "<a href='http://www." . $email_client . ".com'>Go to " . $email_client . " mail now!</a>"; echo "<p class='center_align'>" . $email_link . "</p>"; Basically, what it does, is it figures out what email provider the user supplied as their email, and generates a link that allows them to go to that website, without having to type it in the address bar (I think I got that idea from facebook lol; only they probably do it differently). So anyway, It's not complete, and this is where I need someone's help... I assign a preg_match function to $email_client, so if it finds a string like "@yahoo.com", $email_client will be true, but that's not what I want. I want $email_client to equal a string, such as "yahoo" or "aol" based off of what the preg_match function finds, WITHOUT using if/else statements. Before I did an if/else statement for every email provider I could think of, but I think it better if I do it this way, as some people have crazy a** email names lol. So, basically what I want to do is this: <?php //Step 1: Check email preg_match("/[@][a-zA-z0-9]{10}\.com$/", $_SESSION["user"]["email"]); //Step 2: Somehow assign the "a-zA-z0-9{10}" part to a variable //Step 3: Generate link with that variable used in the "href" attribute and the label ?> But I have no idea how to go about this...Help?
  7. I already tried that and it didnt work
  8. You can use get and make the links like this: <a href="?action=edit">edit info</a> Then write an if statement thats says If ($_get["action"] == "edit"{ Info_edit($_GET["username"]); } function info_edit($username){ query database and fetch array of every member where username = $username Use variables to display members information and do so in text fields Enclose all info in form tags <form action="?action=update&username=$_session["user"]" method="post"> </form> if ($_get["action"]=="update") { update_info($_get["username"]; } Function update_info($username) { process form information and update it in table where username=$username; } And that should work. Of course u mIte nneed to tweak it a bit...
  9. No i use my own server for now. I can post the entire scriPt on here for u to see though.
  10. Well, the thing is I have multiple error checks for each field as well as unique messages for each error and for each field. I like doing it that way, because I feel like I have more control, but the whole isset thing really complicates things, and as a result, my script is like greek. It's been this way ever since I tried implementing javascript to work with the very same form, so a first would be to contrive a possible way to organize the code so as to increase readability and most of all, organizationalibility (yes, I realize I just made up a word lol). It's really tricky, because there are several ways of which I could go about this... I could nest all field checks within the isset check, or I could write an isset check for each field check, which would make my script longer than it should have to be. But even the isset kinda confuses me, so BLAH
  11. Thanks, but I want to actually LEARN it. That way I don't have to go on some website or steal from someone else whenever I need to script something. I like doing everything on my own, but sometimes I just need a little "push" or "hint". So give me a "push" or "hint" lol
  12. preg_match("/^[a-zA-Z] [a-zA-Z0-9]{8, 13} [\_]{1, 1} \@ [a-zA-Z0-9]{1, 15} \. [a-zA-Z]{2, 4}$/", $string); Basically what I want it to check to see is that the email starts with one lowercase or uppercase letter. Then make sure the email contains only a-zA-Z0-9 characters than can span up to 13 chars long. And that a hyphen may be used if necessary, but is not required. Then of course make sure there is an "@" sign. The rest is to make sure that the domain name is only consisted of a-zA-Z0-9 characters that may be up to 15 characters long. Also, require a period right after, and then the TLD, which I would imagine the largest is only 4 characters long. Is that what the above does? If not, can someone guide me in the right direction and help correct any errors, if applicable?
  13. Thanks so much! That's what I figured, but I wasn't sure, and of course I had to be sure, so I could determine whether or not I should contrive alternative ways of organizing my code.
  14. Nvm the second problem, I just found preg_replace and I guess it works quite similarly to ereg and eregi. But does anyone know what the deal is with the first issue I'm having?
  15. First Since I first started learning PHP, I've been writing code for forms like this: $name = $_POST["name"]; if ($name == "") { echo "You didn't type anything"; } I've written scripts like this and tested them on a GOdaddy server, and they always worked fine. Now, after testing scripts like that on my own server (WAMP2 [php5, Mysql, Apache]), I get an error saying "Unidentified index: name", and so I have to nest that if statement AS WELL AS the variable assignment inside another if statement like this: if (isset ($_POST["name"])) { $name = $_POST["name"]; if ($name == "") { echo "you didn't type anything. } } The error doesn't actually stop the script from running, but a medium sized box appears in the browser with the error message contained that's after the element in the document of which is getting an invalid error. Which way is truly the correct way? Because now that I have to use the second way in order for my scripts to run correctly on my own server, I have to write more code and it all gets disorganized and more complicated to read. So...is this a configuration thing that I can tweak in WAMP2 to stop messages like that from popping up? Or is the second way the way you're supposed to do it? Also, I was wondering why ereg got deprecated and what the replacement of it is in PHP5? I've asked before and even googled it but I simply get taken to a "Pearl" function on PHP.net. I'm not sure what it is, or how to use it, and haven't got any hints from either PHP.net or anywhere else. Any suggestions?
  16. That's PRECISELY what I wrote, PRECISELY. But like I said, for some reason, it doesn't work for each if statement. It's really annoying.
  17. This is my first ever javascript script for form validation. I got it to work rather nicely, if I say so myself, however, there are a couple problems I can't seem to fix. Here's the code: <script language="javascript"> /*//Form Validation: Registration //<![CDATA[ function check_form() { var valid = true; /*------------------------------------ -------------------------------------- -------------Error Trapping----------- -------------------------------------- ------------------------------------*/ //Name if (document.registration_form.name.value == "") { var div_blank = document.getElementById("name_blank"); div_blank.style.display = "inline"; valid = false; document.registration_form.name.className = "invalid_form"; } if (document.registration_form.name.value.length < 5) { var div_min = document.getElementById("name_min"); div_min.style.display = "inline"; valid = false; document.registration_form.name.className = "invalid_form"; } if (document.registration_form.name.value.length > 15) { var div_max = document.getElementById("name_max"); div_max.style.display = "inline"; valid = false; document.registration_form.name.className = "invalid_form"; } if (document.registration_form.name.value != "" && document.registration_form.name.value.length > 5 && document.registration_form.name.value.length < 15) { document.registration_form.name.className = "valid_form"; } //Birthdate if (document.registration_form.bd_month.value == "Month") { var div_blank_bdm = document.getElementById("bdm_blank"); div_blank_bdm.style.display = "inline"; valid = false; document.registration_form.bd_month.className = "invalid_form"; } if (document.registration_form.bd_day.value == "Day") { var div_blank_bdd = document.getElementById("bdd_blank"); div_blank_bdd.style.display = "inline"; valid = false; document.registration_form.bd_day.className = "invalid_form"; } if (document.registration_form.bd_year.value == "Year") { var div_blank_bdy = document.getElementById("bdy_blank"); div_blank_bdy.style.display = "inline"; valid = false; document.registration_form.bd_year.className = "invalid_form"; } if (document.registration_form.bd_month.value != "Month" && document.registration_form.bd_day.value != "Month" && document.registration_form.bd_year.value != "Year") { document.registration_form.bd_month.className = "valid_form"; document.registration_form.bd_day.className = "valid_form"; document.registration_form.bd_year.className = "valid_form"; } //Country if (document.registration_form.country.value == "Country") { var div_blank_cy = document.getElementById("country_blank"); div_blank_cy.style.display = "inline"; valid = false; document.registration_form.country.className = "invalid_form"; } if (document.registration_form.country.value != "Country") { document.registration_form.country.className = "valid_form"; } //Region if (document.registration_form.region.value == "") { var div_blank_rg = document.getElementById("region_blank"); div_blank_rg.style.display = "inline"; valid = false; document.registration_form.region.className = "invalid_form"; } if (document.registration_form.region.value < 3) { var div_min_rg = document.getElementById("region_min"); div_min_rg.style.display = "inline"; valid = false; document.registration_form.region.className = "invalid_form"; } if (document.registration_form.region.value > 26) { var div_max_rg = document.getElementById("region_max"); div_max_rg.style.display = "inline"; valid = false; document.registration_form.region.className = "invalid_form"; } //Gender if (document.registration_form.gender.value != "Male" && document.registration_form.gender.value != "Female") { var div_blank_gd = document.getElementById("gender_blank"); div_blank_gd.style.display = "inline"; valid = false; } //Email if (document.registration_form.email.value == "") { var div_blank_em = document.getElementById("email_blank"); div_blank_em.style.display = "inline"; valid = false; document.registration_form.email.className = "invalid_form"; } if (document.registration_form.email.value < 10) { var div_min_em = document.getElementById("email_min"); div_min_em.style.display = "inline"; valid = false; document.registration_form.email.className = "invalid_form"; } if (document.registration_form.email.value > 30) { var div_max_em = document.getElementById("email_max"); div_max_em.style.display = "inline"; valid = false; document.registration_form.email.className = "invalid_form"; } //Username if (document.registration_form.username.value == "") { var div_blank_un = document.getElementById("username_blank"); div_blank_un.style.display = "inline"; valid = false; document.registration_form.username.className = "invalid_form"; } if (document.registration_form.username.value < 10) { var div_min_un = document.getElementById("username_min"); div_min_un.style.display = "inline"; valid = false; document.registration_form.username.className = "invalid_form"; } if (document.registration_form.username.value > 15) { var div_max_un = document.getElementById("username_max"); div_max_un.style.display = "inline"; valid = false; document.registration_form.username.className = "invalid_form"; } //Password if (document.registration_form.password.value == "") { var div_blank_pw = document.getElementById("password_blank"); div_blank_pw.style.display = "inline"; valid = false; document.registration_form.password.className = "invalid_form"; } //Confirm Password if (document.registration_form.password_confirm.value == "") { var div_blank_pwCon = document.getElementById("passwordConfirm_blank"); div_blank_pwCon.style.display = "inline"; valid = false; document.registration_form.password_confirm.className = "invalid_form"; } //Both Passwords if (document.registration_form.password.value != document.registration_form.password_confirm.value) { var div_match_bpw = document.getElementById("bothPasswords_match"); div_match_bpw.style.display = "inline"; valid = false; document.registration_form.password.className = "invalid_form"; document.registration_form.password_confirm.className = "invalid_form"; } //Terms of Service /*if (document.registration_form.tos.value != "Agreed") { var div_blank_tos = document.getElementById("tos_blank"); div_blank_tos.style.display = "inline"; valid = false; }*/ return valid; } //]]> </script> Now, the first problem is, when two or more errors are found, the error messages DO display, but if you fix only one error and hit submit (javascript validation occurs on submit only), the text doesn't go away for that field. Also, I have it to where the classes on the forms themselves change (the colors change), depending on whether or not an error has been found. The problem with that, is I can't get it to change back to the first class after it gets fixed. So that's basically the two problems I have: 1. Getting the error message to disappear on submit. 2. Getting the class to change to "valid" state once the error's fixed. SUMMARY: There are three classes for the forms. 1. default 2. valid 3. invalid a. default is not included in the script, because it will never need to be changed back from another class b. invalid is and works fine, but it gets stuck until ALL errors are fixed and you click submit c. valid is in some places, because it works. i tried putting it in other places in the above script, but instead of the form getting disabled and showing errors, it actually submits to the external file and you only get a glimpse of the errors you didn't fix yet, and this really confuses me. How could it work in one place, but not the other? By "place", I am referring to the 'else' part of the if/else statements above. The first 2-4 if/else statements have else's, but when applying them to other if statements, the script breaks for some reason. Help is welcome =) EDIT: I apologize, the code to switch the classes to "valid" isn't in "else" clauses. I structured it so that if ALL types of error checks for the field is false, switch the class to "valid". Again, I tried doing this with other forms, but it doesn't seem to work and breaks the script. Also, the code to hide the error msgs once errors are fixed isn't in the above script. I tried with all forms, by simply adding some code into the if statement (as described in the previous paragraph), but that broke the script for all fields.
  18. I've read around, and apparently you don't need to edit config.inc.php in order to set a password for "root@localhost". Is it required to edit config.inc.php for any other purposes, though? Cuz I already tried giving that file the same password I used when setting one in the "priveleges" tab, but I still got the same error message. Then I tried creating a directory called "config" in the phpmyadmin folder under the apps folder, and then copied that file there. And if you do that, apparently you can edit the settings in that file through the browser, but it didn't help me fix the problem. It showed a list of options and stuff for setting up or configuring a new server, but other than that... Does anyone know what the problem might be? I honestly can't be the only one to experience this problem with WAMP2. I run it on 64X bit windows 7 home premium. Anyone got any answers? Please?
  19. I know, and I AM using javascript, but I'm making sure that php catches the errors if javascript isn't enabled on the user's computer. Just to be safe. And thanks for the quick reply. I'ma go look up PCRE, right now. Might need help converting my current ereg calls though.
  20. I'm sure this issue has been addressed before, but as I can't find anything on google OR bing, I've resorted to asking it here: Since, ereg and eregi are deprecated in PHP5, how do you test strings using regular expressions? Is there a new function for this? EDIT: I also looked on php.net, but all it says is its deprecated in PHP5. I didn't see any links to the new function(s) that have replaced the former.
  21. Okay, this is really aggravating me. I just download WAMP2 and everything has been working fine up until when I try to change the privileges in PHPMyAdmin. I click the "privileges" tab in PHPMyAdmin, and change the password, and it says it was successful, but when I refresh the privileges page, it comes up with this error: Error MySQL said: #1045 - Access denied for user 'root'@'localhost' (using password: NO) phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server. I uninstalled WAMP2 and deleted everything, then reinstalled everything, but it's still doing this. What do I do?
  22. Thanks, but that's not what I'm trying to do. On my search form, there's about 8 fields, and I want to write a statement that basically checks which fields contain data. Then, write a query using that foreach loop to display the $_POST array values into the query string. Do you know what I mean? That way, a member has unlimited amounts of searching options. For example, name LIKE name and gender LIKE gender and location LIKE location All with percentage signs (wildcard indicators) A query like that would search for a member who has a name LIKE the name they type - IN ADDITION TO someone whose, say male, who ALSO lives in LA.
  23. Ken Wowwwwwwwww, my book really sucks. I got this stupid reference manual at Borders and it says variables starting with underscores are invalid. WTF
  24. Actually, $_PUPPIES would be considered an invalid variable and would probably result in an error. Variables cannot start with underscores unless they're one of the superglobals
×
×
  • 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.