Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. nevermind, reply needs some work before it would work. Edit: The following query does combine both suggestions to get the expire date and the number of days left (tested this time) - SELECT *, @exp:= DATE_ADD(date_purchased, interval 1 year) as expire_date, DATEDIFF(@exp,CURDATE()) as days_remaining the_rest_of_your_query_here...
  2. Again, you can do this directly in the query when you retrieve the data - This would be available as $orders['days_remaining'] Edit: Actually, I don't think that gives the correct answer (I was not thinking straight when I wrote that), but you can still do this directly in the query.
  3. If your current code is related to the upload code you have posted on the forum previously, the code that is testing the ['type'] element of the $_FILES array is not testing the file extension, it is testing the mime type that the browser supplies and someone previously stated in this thread why you might get different values from different browsers for the same file. You would both need to display the value you are receiving as part of the error message and add it as one of the permitted types.
  4. The __sleep function must -
  5. You can do this directly in your query - DATE_ADD(date_purchased, INTERVAL 1 YEAR)
  6. Setting a php variable to null has nothing to do with a null value in a sql query. You would need to use the null keyword in the sql that makes up the query.
  7. What's the name of the page of the code you posted? index.php?
  8. There must not be any \n in the data. Have you examined what is in $string or in $lines to see if they contain what you expect?
  9. Your while(){} loop works the first pass through it. However, your code inside the while {} makes no sense. You are both checking mysql_num_rows() inside the loop (if you are inside the loop there WAS at least one row in the result set) AND you are reusing the $query variable, thereby wiping it out, so of course your mysql_fetch_assoc() statment is producing an error when it tries to fetch something from the $query result resource the second pass through the while loop.
  10. Your error checking and error reporting logic in your code should tell you why the upload is failing so that you don't have to guess. Best guess is that you are checking the mime type and different browsers send different mime types for the same file (actually some send a more correct mime type, others send a more general mime type.)
  11. I would use triggers (one each for INSERT, DELETE, and UPDATE queries) to write the datetime to a Semaphore table that you could query to find out if the table in question has been changed.
  12. No one said to remove error_reporting(E_ALL|E_DEPRECATED); Why did you do that?
  13. You need to add the following - ini_set("display_errors", "1"); The error_reporting/display_errors should be set immediately after your first opening <?php tag (so that session_start and errors due to your connect.php will be reported.) I had hoped that you had not used the mysql_connect() code that had been posted, for a couple of reasons - you are already apparently making a connection in connect.php (for your initial query on the page) and since the posted code didn't select a database, it would be producing more problems.
  14. There are very few incompatible differences between php4 and php5. Most php4 code will work as is under php5, given the same php.ini configuration. Most problems are due to code that is using old outdated/depreciated php features, such as register_globals. Are you debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that all the php detected errors will be reported and displayed to help you find problems in your code? You will save a ton of time. What kind of things have you needed to change so far, as that would narrow down the possible problems and help us to tell you what might need to be changed in the code you posted. Also, what symptoms or errors are you getting, as that would narrow down the possible problems and help us tell you what might need to be changed in the code you posted. Short-answer: Don't just post code that 'does not work' without also stating what problem, error, or symptom it exhibits when you tried it. Most of the variables in your code don't have any code setting them and will be undefined. Your code is likely relying on register_globals, which were turned off by default over 8 years ago. Your code should have been updated to current php standards a long time ago and this has nothing to do with php4 vs php5.
  15. Here is rework of your code that will get you closer to a final solution - <?php include_once 'dbinfo.php'; if(isset($_POST['kuldes'])){ $name = trim($_POST['nev']); $username = $_POST['felh_nev']; $password = $_POST['jelszo']; $email = $_POST['email']; $phone = $_POST['telefon']; $gender = $_POST['sex']; $hobby = $_POST['hobby']; $regfelt = $_POST['regfelt']; $name = strip_tags($name); $name = stripslashes($name); $username = strip_tags($username); $email = strip_tags($email); $phone = strip_tags($phone); $date = date("d-m-Y"); $errors = array(); if($name == NULL || $username == NULL || $password == NULL || $email == NULL || $phone == NULL || $gender == NULL){ $errors[] = "Please complete the form or one of the boxes is empty."; } else { // all the required form fields are present, validate data if(strlen($username) <= 3 || strlen($username) >= 30){ $errors[] = "Your username must be between 3 and 30 characters.."; } else { // username is valid length, check if already in use $stmt = $connect->prepare('SELECT username FROM users WHERE username=?'); $stmt->bind_param('s',$username); $stmt->execute(); $stmt->bind_result($username); while ($stmt->fetch()){ printf("Name: %s\n", $name); $errors[] = "The username is already in use!"; } $stmt->close(); } if(strlen($password) <= 6 || strlen($password) >= 12){ $errors[] = "Your password must be between 6 and 12 digits and characters.."; } if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $errors[] ="Your email address was not valid.."; } if(!eregi("^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,10}$",$phone)){ $errors[] ="Phone number is invalid. Only numbers with hyphen. Allowed format: countrycode-areacode-phonenumber"; } if(!isset($hobby)){ $errors[] ="Youd didn't select any hobbies"; } if(!isset($regfelt)){ $errors[] ="You didn't accept the terms"; } // all validation is done, process data if no errors if(empty($errors)){ $stmt = $connection->prepare('INSERT INTO users(name,sex,email,phone_number,username,password,hobby) VALUES (?,?,?,?,?,?,?)'); $stmt->bind_param('sssssss', $name, $sex, $email, $phone_number, $username, $password, $hobby); $stmt->execute(); $stmt->close(); } } } // prepare error string for form $final_report = ''; if(!empty($errors)){ foreach($errors as $error){ $final_report .= $error . '<br />'; } } ?> <h1>Registration Form</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="registration_form" method="POST"> <p>Name: <input type="text" name="nev" value="<?php echo (isset($name) ? $name : ''); ''?>" size=25></p> <p>Username: <input type="text" name="felh_nev" value="<?php echo (isset($username) ? $username : ''); ?>" size=10></p> <p>Password: <input type="password" name="jelszo" size=10></p> <!--<p>Password again:<input type="password" name="password_confirmation"></p>--> <p>E-mail: <input type="text" name="email" value="<?php echo (isset($email) ? $email : ''); ?>"/></p> <p>Phone number: <input type="text" name="telefon" value="<?php echo (isset($phone) ? $phone : ''); ?>"/></p> <p>Sex: <label><input type="radio" name="sex" value="no" >Female</label> <label><input type="radio" name="sex" value="ferfi" >Male</label></p> <p>Favorite hobbies (Using CTRL you can select more than one):</p> <select name="hobby[]" size="4" multiple> <option value="sport">Sport</option> <option value="mozi">Movies</option> <option value="kirandulas">Hiking</option> <option value="olvasas">Reading</option> </select> <p><input name="regfelt" type="checkbox" value="elfogad">I accept the terms!</p> <p><input name="kuldes" type="submit" value="Submit form"> <input name="reset" type="reset" value="delete"></p> <table width="501" border="1"> <tr> <td><?php echo $final_report; ?></td> </tr> </table> <p> </p> </form>
  16. The current problem is a logical error in your code. In the block of code that is checking if the username is currently in use, you are using a prepare() statement as the elseif() logic test - When that is TRUE (the prepare itself worked) the code inside that conditional statement is executed, but then your code skips over the remainder of the logic and displays the form again. When validating user input, you generally want to check as much of it as possible, rather than check one value, display one error, fix one value, go onto the next value... I would get rid of all those elseif() statements and perform each test by itself, one after the other unconditionally, and either set an error element in an array or add to your $final_report error message if any of them fail.
  17. If it was, several of the errors would have been reported. What does a phpinfo(); statement show for the error_reporting and display_errors settings?
  18. The HTTP 500 error page just means that an incomplete response was generated. Php does this on purpose when you have a fatal parse or fatal runtime error and the error_reporting/display_errors settings set to hide errors. You should set error_reporting to E_ALL and display_errors to ON in your master php.ini so that all the errors php detects will be reported and displayed to help you find problems in your code. Stop and start your web server to get any change made to the master php.ini to take effect.
  19. Wow, whoever wrote the ip2country code was not very kind to your database server. Each of the major functions, get_country_name() (which calls the other function internally) and get_country_code() opens and then closes the database connection surrounding the query. I would personally remove all the $this->close(); statements from that code. Alternatively, you could set the 4th parameter in the mysql_connect() statement in your makeConnection() function to TRUE so that it makes a new connection instead of reusing an existing connection. This assumes that your code is using the value that your function returns in each query as the connection link.
  20. What method did you use to create this table? Have you successfully executed any queries using the posts table? If you cannot find the reason why mysql would report that the table does not exist, you would need to post your table definition so someone could look. You either have a spelling error, the actual table is in a different database, your have some non-printing characters as part of the table name (likely a space), or the table simply does not exist.
  21. There's a complementary function to DATE_FORMAT() called STR_TO_DATE() - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date However, since you should be validating the data you receive before putting it into a query, your php code could break apart (explode) the d/m/yyyy values and put them together in the yyyy-mm-dd format before you put it into a query.
  22. If the following is your current code immediately up to the point where the undefined index error is reported - $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); And you do in fact have error_reporting set to E_ALL and there are no other errors being reported, then you must have a space or something as part of the 'xbodyx' column name, or you would not be getting that undefined index error.
  23. Why aren't you building the array directly from the source data? Processing the same data 3-4 times makes no sense.
  24. One of the points of programming is, you can try something to see if it works the way you expect. You posted a generic query without any other information at all, so the generic answer is yes, that query could work. The query you posted would work as is, depending on what your data types are (string data values must be enclosed in single-quotes.)
  25. To do what the OP asked, would require that you retrieve the rows you want in the order that you want them. Then iterate over the result set and output it the way you want - <?php $query = "SELECT * FROM your_table WHERE your_where_condition_here ORDER BY category, title"; // order the titles under each category if($result = mysql_query($query)){ if(mysql_num_rows($result)){ // one or more rows in the result set $last_category = null; // remember the last category, initialize to a value that will never exist in the data while($row = mysql_fetch_assoc($result)){ if($last_category != $row['category']){ if($last_category != null){ // close the previous <ul> echo "</ul>\n"; } // the category changed, output the header echo "<h3>{$row['category']}</h3>\n<ul class=\"nav1\">\n"; $last_category = $row['category']; // remember the new category } // output the data from the row echo "<li><a href=\"#\">{$row['title']}</a></li>\n"; } echo "</ul>\n"; // close the last <ul> } else { // query worked, but matched zero rows echo "Your query did not match any existing data"; } } else { // query failed due to an error echo "Query failed: $query<br />" . mysql_error(); // for debugging purposes only... } ?>
×
×
  • 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.