Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Everything posted by wildteen88

  1. Opps sorry had a few typo's. <?php error_reporting(E_ALL); display_errors("1"); $username = 'YOUR_MYSQL_USERNAME_HERE'; $password = 'YOUR_MYSQL_PASSWORD_HERE'; $database = 'YOUR_MYSQL_DATABASE_HERE'; echo 'Attempting server connection...<br><br>'; $conn = mysql_connect('localhost', $username, $password) or die('Unable to connect to MySQL server:<br>' . mysql_error()); echo 'Connected Successfully!<br><br>'; echo 'Selecting database....<br><br>'; mysql_select_db($database) or die('Unable to connect to db:<br>' . mysql_error()); echo 'Successfully selected database!'; ?>
  2. Line 5 or 6 in secound page: $$year=date("Y"); Notice the $$year. There is your problem. remove the extra $ There you are setting up a variable variable. A variable variable where you can set a variable name as the value of another variable, eg: $foo = 'bar'; $bar = 'hello world'; echo $$foo; Now as the year variable in your code does not exist yet PHP cannot create a variable variable and thus it is probably causing the problem you are having
  3. Is that it? If its you're halsf way there. You need to now run that query by using mysql_query function - make sure you have connected to the database first before you run it. Also make sure you have validated and made any data that being used within an SQL is safe. Never use raw GET or POST data. If you do not validate/make data safe for use within an SQL query you database can be exploited using SQL Injection - search google for that term. There are many sites out there that explain what it is and how to avoid it. EDIT: jscix beat me :-) but make sure you pay attention to what I said in the paragraph above ^^^
  4. Add display_errors("1"); too after <?php error_reporting(E_ALL); Looks like something in your code PHP is not liking and is killing the script. If something is wrong PHP should show errors to the screen.
  5. Ok Schlo_50 try this: <?php // get the suffix for the date function get_suffix($day) { // create a unix timestamp of the day $time = mktime(0, 0, 0, 0, $day); // using the unix timestamp get the date // suffix using PHP's built in date function $suffix = date('S', $time); // return the day with suffix // eg 1st, 3rd, 20th return $day . $suffix; } function getevents($event_month) { $file = file("data.txt"); //puts each line of the file into an array //loop through array foreach($file as $key => $val) { $data[$key] = explode("|", $val); //breaks up each line into seperate arrays, values seperated by | $day = $data[$key][0]; $month = $data[$key][1]; $event = $data[$key][2]; //will only list month you specify in function. if($month == $event_month) { $events[$day] = $event; } } ksort($events); foreach($events as $day => $event) { echo get_suffix($day) . " - $event<br />\n"; } } //Using the function getevents("Jan"); ?> This time save the data.txt in this formatt: 3|Jan|What to do.. 10|Jan|Birthday ... The code will now take care of getting the correct suffix for the day and your list will be in the correct numerical order.
  6. Hi Schlo_50 I helped you last time and provided you the code for this. Could you post an example of how data.txt is formatted. The way I have it coded is when the days are pulled form the file I save the day inro the array index and then assign the event to that index. ksort is then used to sort the array indexes into numerical order, eg 1, 8, 11, 21. This how I get the events to show up in order of day. The code should be doing the trick. EDIT: I see what is wrong now. Before (when I coded this script for you) you didn't have the date suffix in data.txt, eg: st, nd, rd etc. That is what is throwing the list out of order. If you remove the suffix you'll see it'll display in the correct order.
  7. Line 48 should be: if (mysql_affected_rows($dbc) == 1){ You put a space instead of an underscore between affected and rows.
  8. Set a cookie in javascript which holds the page name when they load a page. Then when the user access index.php have your script load the cookie just set and load the previous page that was loaded.
  9. I guess you are using notepad. Whn you go to save files in notepad it will always add a .txt file extension even if you have already defined one. To stop notepad from adding the .txt extension make sure the File Type field is set to All Files and not Text Document before you click the save button. Also make sure you save your php files in C:/wamp/www if you have WAMP installed. When you want to run your php files go to http://localhost/name-of-file-to-run-here.php - change name-of-file-to-run-here.php with your actual php file you want to run.
  10. Rather than using GUI's/clients to connect to mysql. Create a test php script call it mysql-test.php and place the following code in mysql-test.php: <?php error_reporting(E_ALL); display_errors("1"); $username = 'YOUR_MYSQL_USERNAME_HERE'; $password = 'YOUR_MYSQL_PASSWORD_HERE'; $database = 'YOUR_MYSQL_DATABASE_HERE'; echo 'Attempting server connection...<br><br>' $conn = mysql_connect('localhost', $username, $password) or die('Unable to connect to MySQL server:<br>', . mysql_error()); echo 'Connected Successfully!<br><br>'; echo 'Selecting database....<br><br>'; mysql_select_db($database) or die('Unable to connect to db:<br>', . mysql_error()); echo 'Successfully selected database!'; ?> Upload mysql-test.php to your site then go to mysite.com/msql-test.php Post all output you get when you run that script here.
  11. If you use square brackets in a form field name you must place them outside the _POST variables eg: $_POST['order'][0] - first radio button (YES) $_POST['order'][1] - second radio button (NO) Now with radio buttons there is no need to place square brackets after radio button names as radio buttons only submit 1 result. You only place square brackets after a form name if you want to group multiple fields together which will return multiple results, such as checkboxes.
  12. wildteen88

    DB

    Well the problem is only the last query is being run. The first query will never be run as the second query is overriding it as you are reassigning the $query variable a new value - which is the second query. In order for SQL queries to be ran you must run them with the mysql_query function. Just defining the query within a variable on it's own wont do anything as PHP sees the $query variable holding a string. PHP wont see it as an MySQL query and run that query through MySQL. This is what your code should be: <?php // run the first query which inserts the email addy into the blacklist $query1 = "INSERT INTO ".MYSQL_TBL_MAILLIST_BLACKLIST." VALUES ('$email')"; $result1 = mysql_query($query1) or die("Query1 failed : " . mysql_error()); // now we ckeck to see if the query ran successfully // if it did we'll run the second query if($result1) { $query2 = "DELETE FROM ".MYSQL_TBL_MAILLIST_SUBSCRIBERS." WHERE address = '$email' AND userkey = '$key'"; $result2 = mysql_query($query) or die("Query2 failed : " . mysql_error()); // rest of code here } else { // do something else } ?>
  13. Yes you uses MadTechie's suggestion above also don't for get to align the balance to the right as well: Change Print "<td>".$info['balance'] . " </td></tr>"; to: Print '<td align="right">'.$info['balance'] . " </td></tr>";
  14. No no no, nothing to do with error_reporting. The default setting for error_reporting is fine. In order for errors to be displayed you need to turn display_errors on.
  15. if(isset($_GET['content'])) { include $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['content'] . '.php'; } else { // display home page here }
  16. Yeah. With post it passes data submitted from a form in the background rather than passing it via the url - that is what GET uses. You can only use POST with forms.
  17. POST is just a method submitted data to the server.
  18. the 88 is my birth year - 1988.
  19. You should use trim which will remove whitespace characters at the beginning and end of a string. Depending on the OS the file was created on it could have \r\n or \n or \r whitespace characters for newlines using trim removes all possibilities giving you clean string/line
  20. I would recommend you to code with full PHP tags rather than short PHP tags this helps to keep your PHP code more portable. However if you must you cna enabled a setting called short_open_tag
  21. try redownloading a new copy of phpmyadmin. Looks like when you downloaded it it got corrupt. Make sure you download stable releases and not beta/alpha copies from phpmyadmin.net
  22. Does the kw column only contain numbers? If it does then there is not much point in setting it to TINYTXT data type Instead you should set it to INT or TINYINT
  23. Huh! isset and is_null checks for two completely different things. isset checks for variable existence and is_null checks to see if the variable holds a null value and not the existence.
  24. Is this what you mean: <?php $str = "see you soon redarrow"; $words = explode(' ', $str); $bad_words = array("a", "see", "c"); $bad_words_used = 0; foreach($words as $word) { // check whether bad words have been used in string // if they are we increment the 'bad_words_used' variable by one each time a bad word is used if(in_array($word, $bad_words)) { $bad_words_used++; } } // check to see if 'bad_words_used' variable is greater than 0 // if its greater than 0 we kill script display an error // if its not greater than 0 we add to database if($bad_words_used > 0) { die('Bad words have been used'); } // else badwords have not been used. else { echo 'No bad words have been used we add to database now'; } ?>
  25. becuase you are using the exit keyword in your if/else statement Once a match or non maych has been found you are telling PHP to stop and so nothing else happens. and thus you get Good word.
×
×
  • 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.