Jump to content

jamesjmann

Members
  • Posts

    247
  • Joined

  • Last visited

Everything posted by jamesjmann

  1. Um srsly dude, if u dont know php, dont try using other ppls scripts. A script like uploadify.php really isnt that complicated. If i were u, id gt a book and start reading up on php. In that way, you wont even have to use other ppls scripts and the best part is...you woul actually understand what was going on! Not trying to be mean but just giving u advice mainly becuz i used to be like that but after reading a small bOok i learned alt and have already moved on to javazcript
  2. In my opinion Your code iS poorly written/organized. I would use a nice switch statement to handle the script
  3. Ive only been learningphp for 3 months too and i already know ajax like my native language! Haha. No but really ajax isnt that hard. And you would use jquery to slide the login form out, ajax would be for handling the php script without having to reload/refresh the page. Both are, in essence, just javascript, so id start by going to borders or amazon.com and look for a book on javascript, ajax, jquery, or a combination of two or more of the above. I learned javascript in less than a week; its easy to learn because the syntax is darn near identical to that of php (save for declaring variables and all the various functions...).
  4. It takes one millisecond if that for my scripts to make ajax calls. And i consider it a huge importance having plain php as a backup plan case the user doesnt have javascript. Im just saying that one should always try to use javascript/ajax first, as it improves and enhances the gui and usability of the website, which im sure everybody wants.
  5. You're going to want to use a redirect in any case, but I'd rather use ajax, than just plain old PHP.
  6. Why not just use ajax? You could use ajax to log the person in, and THEN redirect after a certain period of time.
  7. Ok, doing that worked (after much trial and tribulation, I kinda feel like an idiot lol); however, now I'm having another problem that doesn't make sense... Assuming you're familiar with AJAX... After you click the button to check the availability of the username, if you type something different and try clicking again, nothing happens. Here's my JS code: function check_username(str) { document.getElementById("loading_availability").innerHTML = "<img src='../images/animations/loading 2.gif'>"; //If button hasn't been pushed... if (str == "") { //Display nothing in content box document.getElementById("availability_message").innerHTML = ""; return; } // code for IE7+, Firefox, Chrome, Opera, Safari if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); // code for IE6, IE5 } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { setTimeout ('document.getElementById("availability_message").innerHTML = xmlhttp.responseText', 500); setTimeout ('document.getElementById("loading_availability").innerHTML = ""', 500); } } xmlhttp.open("GET", "../php/scripts/registration/username.php?username=" + str, true); xmlhttp.send(); } Here's my new html code: <input type="submit" name="check_availability" id="check_availability" value="Check Availability" onClick="check_username(document.getElementById('signup_username').value);"> And here's my PHP code: <?php $username = $_GET["username"]; $mysql_host = "localhost"; $mysql_username = "root"; $mysql_password = "somethingyoudontknow"; $mysql_database = "database"; $mysql_connect = mysql_connect($mysql_host, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $mysql_connect); //Begin mysql query $sql = "SELECT * FROM fans WHERE username = '$username'"; $result = mysql_query($sql); $count = mysql_num_rows ($result); if ($count == 0) { echo "<p class='box2'>This username is available!</p>"; } else { echo "<p class='box'>This username is already in use!</p>"; } mysql_close($mysql_connect); ?> Now, you tell me
  8. then how do you get the actual value from the username field? Like this...? onClick="check_username(document.getElementById('username').value);" In which the document.get(...) call is not enclosed in quotes?
  9. I'm trying to get a value typed in by a user in one textfield and send it through a function that executes "onClick" on a button. Here's the code so far: <input type="submit" name="check_availability" id="check_availability" value="Check Availability" onClick="check_username('document.getElementById('username').value');"> This part: document.getElementById('username').value Is where my script breaks. I can't find a way to use those single quotes around "username" to make the value of the "username" field get passed through. Anyone know how to solve this?
  10. I would use arrays to store the messages you want displayed when an error occurs. This provides for easier future editing. Also, i came up with this concept where theres error objects and an "error report". Basically what you could do is write a list of if/else statements checking the various aspects of the form; and if something happens that you dont want, you would create a variable and set it to "true" (which is essentially your 'error object'). You'd also want to create a variable called $error_report (which is used later on in your script). And You would want an error object for every field and every aspect of each field. Each would carry a unique "error object" name but all of them would contain the same "error report". Then, you would create an action script that decides what to do once the form has been submitted and checked. This is where the "error report" comes in. If ($error report) { display_form(); } else { //do mysql query or whatever }
  11. Oh i figured it out. I had a problem for the longest time where empty fields would get passed to query string, breaking the script; however, a solution quickly occured to me that made sense and worked: Writing if statements on each post element to check if they are empty - and if they are NOT, assign them to a new array and then call that array in the foreach statement. It works PERFECTLY now. I appreciate the help everyone!
  12. Okay, I'm pretty sure I just solved your problem, but allow me to reexplain... First off, the isset function checks to see if a field has a set value. Technically, you don't need it, but it's always good to have it. Also - REMEMBER THAT ISSET IS NOT GOOD FOR COMPARING VARIABLES OR SATISFYING CONDITIONS. YOU ONLY USE ISSET TO CHECK IF THE FIELD ELEMENT EXISTS, NOT IF A FIELD ELEMENT CONTAINS AN EMPTY STRING. So, if you DONT want the empty fields to be submitted until there is something in them, again, you would write an if statement: //Check to see if the field exists, and obviously it will once submit has been pressed if (isset ($field)) { //Do actual validation of form if ($field == "default value") { //SHOW MESSAGE, DO NOTHING ELSE! } else { //INSERT INTO DATABASE } if ($field == "") { //SHOW MESSAGE, DO NOTHING ELSE! } else { //INSERT INTO DATABASE } } The above code ensures that the text box does not contain the default placeholder text and is not empty (VIA PHP) - and I'm pretty sure I already explained all this earlier, but anyway...
  13. Oh, and I can assure that I've check and rechecked my HTML code: nothing as far as I can tell that is causing this problem, so it would have to be the CSS. I'm guessing there is an alternative to the <br clear="all"> method that does the same thing?
  14. The reason why I structure it all that way is to make my CSS more easy to read and more organized, and the CSS does work (all of it), except for that one, stupid html tag "<br clear="all">". See, basically what I want to do is have two columns for the member's profile: one for the "general" information and the other for the more "personal" information. I want them to sit side by side, and I've always learned to use the clear property on a <br> tag for making any other element after them to sit below them (if you know what I mean). This works on my main template, just not in this particular document for some reason. Also, I don't think the two "body" IDS are what's causing this problem. This problem was still occurring even before I added the second body id, which I inserted in the hopes of solving this really annoying problem. And the code actually is doing something. I omitted everything I currently contain within the <div>'s as I figured they were irrelevant to this post. BUT, to show you an example of what's going on here, I'll post some pictures...one for the profile that does work, and one for a profile of the several that don't. I attached a picture of the only profile with a lot of information that does not suffer from this CSS blight. The other profiles look the same, except there's a HUGGEEEEE gap between the "sidebar" and "main" divs and the "friends" div. [attachment deleted by admin]
  15. For the javascript portion: You're going to have to run an if statement that checks to see if the default value in the field has been left untouched, or if that field is blank. If so, execute error message. As for the php...if you have text already inside the box when the page loads, you're going to have to write an if statement in php, quite similar to the one I mentioned above. The code would look this: <?php //Check to see if the textbox element was passed to the $_POST array if (isset ($textbox)) { if ($textbox == "Default text in form") { echo "You did not enter any text."; } else { mysql_query ($query); } } else { echo "For some impossible reason, the textbox did not get passed to the \$_POST array."; } ?> Doesn't get any simpler than that! Now if you want to make sure the javascript catches the error before submit is clicked, you're going to want to make sure that if statement within your function gets called ONLY onSubmit (the attribute that goes in the form) and onClick (when the user clicks "submit"). To ensure the form doesn't get submitted until the errors have been corrected, you have to give the "onSubmit" and "onClick" attributes a value of "return checkForm_function();" In your function you would create a var called "var status" where status is equal to true or false (don't declare it either initially, but make sure it is declared nonetheless...). Then, when you write your if statement, you would say: If ($("#var").val() == "default text in form") { status = false; $("#error_msg_box").fadeIn(500); } else { status = true; $("#error_msg_box").fadeOut(500); } So when you hit submit, the document will run the function with the if statement above, and if that user did not type over the default text, a div with an error message inside would slowly fade in, and the form would become "false", disabling the "action" on it. As soon as that error gets fixed, however, the form will be submittable. You can also add additional features to your form, such as "onKeyUp" and "onKeyDown" and "onChange" and "onBlur", and for each attribute you would assign a value of "checkForm_function();" This would make it to where whenever a user types a character or changes to another field or makes current field go out of focus, that function will execute and display error messages on the fly (or in "realtime", i suppose you can say). Hope this helped! NOTE: The above javascript code is in fact JQuery. If you are unfamiliar with the library, I highly recommend you invest time in learning it, as it will make life a lot easier for you when scripting.
  16. I'm having problems using "<br clear="all">" for structuring the profile template for my users. Here's my html: <html> <div id="profile"> <div id="default"> </div> <div id="other"> </div> <div id="contact"> </div> <div id="body"> <div id="sidebar"> </div> <div id="main"> </div> <br clear="all"> </div> <!--End Body--> <div id="friends"> </div> <div id="comments"> </div> </div><!--End Profile--> </html> And here's my CSS: <style> #body #content #profile #body #sidebar { float: left; width: 250px; margin-top: 10px; padding: 5px; color: #555; margin-right: 15px; } #body #content #profile #body #main { float: left; width: 450px; margin-top: 10px; padding: 10px; color: #555; border-left: 1px solid #CCC; } #body #content #profile #default { float: left; width: 300px; margin-right: 15px; padding: 5px; } #body #content #profile #other { float: left; width: 425px; border-left: 1px solid #CCC; padding: 10px; } #body #content #profile #contact { width: 225px; margin-top: 10px; padding: 5px; } #body #content #profile #friends { width: 70%; margin-left: auto; margin-right: auto; margin-bottom: 25px; } #body #content #profile #comments { width: 70%; margin-left: auto; margin-right: auto; } </style> The problem is, the "<br clear="all">" right after "#body #content #profile #body #main" is making everything after "#body #content #profile #body" span down multiple lines...This happens on profiles that do not contain a lot of information. On profiles that DO contain a lot of information, this isn't a problem. I'm having lots of trouble understanding why this is. Anyone have a solution?
  17. Hi I was wondering what the best way would be to go about making an "email system" or "email client" for my website? I've heard of POP3, but it seems really complicated, and I was wondering if PHP/Mysql alone could produce the same results as using POP3. Is this possible to just use PHP/Mysql? Is it recommended? What are the advantages/disadvantages? I have searched fruitlessly for answers to the above questions, but have found none. Does anyone have an opinion on the matter?
  18. Hey, I'm trying to make a simple form using jquery for validation and whatnot, and I can't seem to get it to work. Here's my code: <html> <head> <script language="javascript" src="jq/jquery-1.5.1.min.js"></script> <style> .box, button { margin:5px 10px 5px 0; } p { line-height: 10px; } body { line-height: 15px; } .box { color: #FF0000; font-size: 90%; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #FFD9DA; width: 250px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; padding: 10px; line-height: 15px; } .box2 { color: #00CC00; font-size: 90%; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #CEFFDB; width: 250px; padding: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; } </style> </head> <body> <form onSubmit="return check_name();" method="post" action="?hello=man"> <p>Name: <input type="text" id="btn1" value="" size="50" onKeyDown="check_name();"/></p> <p><div id="box1" class="box"><img src="images/icons/x.png" width="17" height="17" style="float: left; margin-right: 5px;"/>You did not enter a name!</div></p> </form> <script> function check_name() { if ($("#btn1").length == 0) { $("#box1").fadeIn(500); } else { if ($("#btn1").length != 0) { $("#box1").fadeOut(500); } } } </script> </body> </html> Now the problem is, I can't get the error message to be hidden initially. The second is, when you type something in the field, it goes away, but when you backspace everything to where it's empty, it doesn't redisplay the error message like it's supposed to. Anyone know how to fix this?
  19. It makes your query valid as you are now building it like: SELECT * FROM fans WHERE 1 AND $field = '$value' AND $field = '$value' .. You could also just write TRUE instead of 1, it won't make any difference. Everything else should be self-explanatory. Okay, well it definitely worked, only now I'm having this problem: Everytime I hit the submit button, EVERYTHING gets sent to the url, which means the query is looking for empty strings if a field is blank. This is breaking my code and I don't know how to fix it. For example, if I only fill out one of the eight fields, all eight fields get sent to the url, therefore getting defined in the query, and I keep getting this error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files\wamp\www\index.php Is there a way to "strip" the empty variables from the url? Or perhaps, stop them from becoming part of the $query variable?
  20. Thank you so much! That works exactly!
  21. Here's a function I use for displaying a member's profile using $_GET <?php function view_profile ($username) { include_once "connect.php"; $query = "SELECT * FROM fans WHERE username = '$username'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $username = $row["username"]; $name = $row["name"]; $email = $row["email"]; $region = $row["region"]; $country = $row["country"]; $gender = $row["gender"]; $status = $row["status"]; $subscription = $row["subscription"]; $time_registered = $row["time_registered"]; $date_registered = $row["date_registered"]; $birthdate = $row["birthdate"]; $age = $row["age"]; $last_time = $row["last_time"]; $last_date = $row["last_date"]; $default_photo = $row["default_photo"]; $about_me = $row["about_me"]; echo $name; echo $email; echo $status; echo $username; } } ?> The only problem is, its not echoing the member's information when the function gets called. I used a variable called "$count" and echoed that to see if it was getting any results, and it is, it's just the while loop isn't working and i don't know why as I used an identical function like this for another script. Any suggestions?
  22. What's the "1" for? What does it do? And thanks for the quick reply, buddy!
  23. I think this problem requires LOTS of brainpower, and as I am absolutely convinced at this point that I have none, I was kind of hoping someone could steer me in the right direction at the very least. What I'm scripting right now is a search form that allows users to browse members based on what they type in the forms. There's about 8-10 forms of various criteria, such as age, country, birthdate, email, etc. And once they hit submit, all the information they typed gets sent to the url ($_GET, in other words). Now, the way I structured my script is like this: <?php //If nothing was submitted (or if the url is completely blank) if ($_GET == array ()) { //Define a variable that will be used to query the members; in this case, it would select all members $query = "SELECT * FROM fans"; } else { //If the user typed at least one thing (in the form OR the url) if (count ($_GET) == 1) { //If what they typed is only for one criteria, define a variable that creates a query for only ONE criteria to search for $query = "SELECT * FROM fans WHERE"; foreach ($_GET as $field => $value) { $query .= " $field = '$value'"; } //If the user has typed in more than one field and hits search } else { //Define a variable for a query that selects members based off each criteria $query = "SELECT * FROM fans WHERE"; foreach ($_GET as $field => $value) { $query .= " $field LIKE '%$value%' AND"; } } } ?> Now, the problem with the above script is the very last part...defining a query to run if more than one field is selected. Because I'm using a foreach loop to structure that query, my options seem rather limited with what I can and can't do as far as querying the database. And the problem lies in where it says "$field LIKE '%$value%' AND". Because of the way the script is set up, the last $_GET variable will have "AND" at the very end, and when it runs through the mysql_query() function, it breaks, and does NOT work. Is there a way around this? I figure it probably requires some complex mathematical equation (one which I have absolutely no idea on how to create). Can anyone help?
  24. Yep, I print_r'ed both the $_POST and $_SESSION arrays and everything looks okay. I figured out how to do it properly (after a LOT of messing around)... <?php $query = "INSERT INTO fans (name, username, email, password, country, region, gender, status, account, subscription, time_registered, date_registered, birthdate, website, age, activation_key) VALUES ('{$_SESSION['user']['name']}', '{$_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']['website']}', '{$_SESSION['user']['age']}', '{$_SESSION['user']['activation_key']}')"; ?> This works perfectly. Thanks for all the help and suggestions guys!
  25. Okay, well I just rewrote the code like this: <?php $querry = "INSERT INTO fans (username) VALUES ('hello')"; mysql_query ($querry); ?> And this inserts "hello" in the field "username". So, I'm guessing the problem lies in all those session variables. I've tried nearly ever variation I can think of, but it just doesn't work. Do you know how to send those session variables to the query the CORRECT way?
×
×
  • 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.