Jump to content

RyanSF07

Members
  • Posts

    221
  • Joined

  • Last visited

Everything posted by RyanSF07

  1. Well I'll be darn. Thanks Jessica.
  2. Hello, This code: $textlevel= $row['level_text']; $oldlevel = array("Intermédio", "Intermédio avançado"); $newlevel = array("intermediate", "high_intermediate"); $textlevel = str_replace($oldlevel , $newlevel , $textlevel); spits out "intermediate avançado" instead of "high_intermediate" How do I join "Intermédio" and "avançado" so that "Intermédio avançado" is in fact replaced with high_intermediate instead of only the first work replaced? thank you for your help, Ryan
  3. Hi All, I need some help blocking files that don't pass authentication from being uploaded to the server. Here is my script (below). It correctly throws errors, but regardless of error / no-error, the file is uploaded. For example, the only files allowed to be uploaded should be .png, .jpeg, .gif -- but I see .flv .docx etc in the destination folder. You'll see below a variable for each of the error messages. They basically say that the file name is too long, too big, not an allowed file type, or English characters only allowed in file title name. Again the errors work properly, but regardless files are uploaded to the "quiz_images" folder. What do I need to do to stop the upload if an error is triggered? Thank you for your help... here is the code snip: $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'quiz_images/'; $fieldname = 'file'; if ($_POST[submit]) { if ($_POST[title] <> "") { $a = TRUE; } else { $a = FALSE; $content .= "<p>$enter_title</p>\n"; } if ($_POST[video] <> "") { $b = TRUE; } else { $b = FALSE; $content .= "<p>$enter_embed</p>\n"; } if ($_POST[description_text] <> "") { $c = TRUE; } else { $c = FALSE; $content .= "<p>$enter_description</p>\n"; } if ($_POST[submit] <> "") { $f = TRUE; } else { $f = FALSE; $content .= "<p>$sorry_error</p>\n"; } if (is_uploaded_file($_FILES[$fieldname]['tmp_name'])) { $g = TRUE; } else { $g = FALSE; $content .= "<p>$sorry_error</p>\n"; } if (getimagesize($_FILES[$fieldname]['tmp_name'])){ $h = TRUE; } else { $h = FALSE; $content .= "<p>$error2</p>\n"; } if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 50000)) { $i = TRUE; } else { $i = FALSE; $content .= "<p>$error2</p>\n"; } if(preg_match('#^[a-z0-9_\s-\.]*$#i', $pic) ) { $k = TRUE; } else { $k = FALSE; $content .= "<p>$error3</p>\n"; } $desc_length = strlen($pic); $limit = 40; if ($desc_length <= $limit) { $l = TRUE; } else { $l = FALSE; $content .= "<p>$error4</p>\n"; } $now = time(); while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])) { $now++; } if (move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)){ $j = TRUE; } else { $j = FALSE; $content .= "<p>$enter_thumb</p>\n"; } $pic=$now++.'-'.$_FILES[$fieldname]['name']; if ($a AND $b AND $c AND $f AND $g AND $h AND $i AND $j AND $k AND $l) {............
  4. Hi Guys, I have this bit of code which only allows one single user to view the page (which works great and there are no problems), but I'd like to add another user's id so that she can view it as well. What is the correct way to change this "if clause" so that both users 123 and 456 can view the page? if ($_SESSION[user_id] == 123) { include("admin_nav.inc"); ...... Thank you for your help!
  5. I was able to get everything to work using string replace. Pulled the level_text from the database and modified it to format the correct, level specific url. Thanks! Ryan
  6. so trying to do something like this: switch($row['level_text']) { case "beginning": $page = "beginning.php?id="; break; case "low_intermediate": $page = "low_intermediate.php?id="; break; case "intermediate": $page = "intermediate.php?id="; break; case "high_intermediate": $page = "high_intermediate.php?id="; break; } The $page variable should be set based on the $row[level_text]. For example, if the $row[level_text] = low_intermediate, the $page variable would equal: low_intermediate.php?id= and the link <a href=\"$page" . $row['id'] ."\"></a> would go to: <a href=\"low_intermediate.php?id=" . $row['id'] ."\"></a> (the id's are working just fine -- it's getting that $page variable to set right that's giving me trouble.)
  7. Thank you Flappy_Warbucks, Sorry for the delayed reply. I have this array pulling 5 items into a table: while($row = mysql_fetch_array($result)) { Those items become links to the content. I'd like to make the first part of the link dynamic, so that the content can display on a level specific page. For example, instead of the 5 items pulled from db linked like this: <a href=\"default-page.php?id=" . $row['id'] ."\"></a> They would be like this: <a href=\"beginning.php?id=" . $row['id'] ."\"></a> <a href=\"low_intermediate.php?id=" . $row['id'] ."\"></a> <a href=\"intermediate?id=" . $row['id'] ."\"></a> <a href=\"high_intermediate?id=" . $row['id'] ."\"></a> .. again depending on the $row[level_text] Does that make sense? Thank you so much for your help with this!
  8. Actually -- that was close but not spot on... Trying to do more like this: switch($row['level_text']) { case "beginning": $page = "beginning.php?id="; break; case "low_intermediate": $page = "low_intermediate.php?id="; break; case "intermediate": $page = "intermediate.php?id="; break; case "high_intermediate": $page = "high_intermediate.php?id="; break; default: $page = "default.php?id="; //incase something goes wrong somewhere. Always plan to for things to go wrong } echo $page; The echo should produce something like: (there are 5 instances displayed) high_intermediate.php?id= beginning.php?id= beginning.php?id= low-intermediate.php?id= high-intermediate.php?id=
  9. looks like that is going to work. I'll keep playing with it. thank you!
  10. now trying this -- on the right track? not working yet... switch ($page) { case label1: if ($row['level_text'] == "beginning") { $page == "beginning.php?id="; } break; case label2: if ($row['level_text'] == "low_intermediate") { $page == "low_intermediate.php?id="; } break; case label3: if ($row['level_text'] == "intermediate") { $page == "intermediate.php?id="; } break; case label4: if ($row['level_text'] == "high_intermediate") { $page == "high_intermediate.php?id="; } } echo $page;
  11. also, it looks like $row[level_text] has been set to equal "beginning" in other places where that $row echo'd onto the page...
  12. I tried this: if ($row['level_text'] == "beginning") { $page == "beginning.php?id="; } elseif ($row['level_text'] == "low_intermediate") { $page == "low_intermediate.php?id="; } elseif ($row['level_text'] == "intermediate") { $page = "intermediate.php?id="; } elseif ($row['level_text'] == "high_intermediate") { $page == "high_intermediate.php?id="; } echo $page; and get: beginning.php?id=beginning.php?id=beginning.php?id=beginning.php?id=beginning.php?id=
  13. thanks .. I'll google Switch. I'm sorry... that was just a snip. The script itself works (the complete script where the id is set) but all "ids" play on the same page. I'm trying to set a "page" variable so that the content doesn't have to play on one set page, rather a "level specific" page base on the row[level_text]
  14. Hello, I'm trying to set a variable based on a word that is pulled out of the DB in an array. What is the correct what of doing this? Currently I'm trying this without success: while($row = mysql_fetch_array($result)) { if ($row['level_text'] = "beginning") { $page = "beginning.php?id="; } elseif ($row['level_text'] = "low_intermediate") { $page = "low_intermediate.php?id="; } elseif ($row['level_text'] = "intermediate") { $page = "intermediate.php?id="; } elseif ($row['level_text'] = "high_intermediate") { $page = "intermediate.php?id="; } if ($tdcount == 1) $content .= "<li><div> <a href=\"$page" . $row['id'] ."\"></a> </div></li>"; }
  15. You are right -- fortunately this is a completely isolated incident. I got around it by moving the "favorite" processing script to a separate success page, which is working well (no random inserts) without sacrificing user experience. I really appreciate the help, and took as advice to try a different way. Thanks again, Ryan
  16. Hi and thank you again for your help. "It would certainly help if you told us if the first row or the last row is the correct one and posting the complete code for the page would help as that would allow someone to either confirm or eliminate the code as the cause of the problem." Looks like the first row -- but it's not consistent. Testing I see sometimes one row is added (correct), then again 2, then again 3 --random. "Do you have any URL rewriting or unusual domain forwarding/add-on domain that might be causing your page to be requested multiple times?" no I have an "id" field in the database set to autoincrement -- could that have anything to do with it?
  17. thanks. I put this: if ($favoritequiz) { $favqtitle = mysql_real_escape_string($_GET['favorite_title']); $favqusername = mysql_real_escape_string($_GET['favorite_usern']); $favqphoto = mysql_real_escape_string($_GET['favorite_photo']); $query = "INSERT INTO favorites (favuser_id, favquiz_id, favtitle, favusername, favphoto) VALUES ('$session_userid', '$favoritequiz', '$favqtitle', '$favqusername', '$favqphoto')"; mysql_query( $query ); } echo $query; and get this: INSERT INTO favorites (favuser_id, favquiz_id, favtitle, favusername, favphoto) VALUES ('38', '8638', 'Compound words', 'Joseba', '1308040816-compound words.jpg')
  18. regarding loop... I don't think so... here's how I have this set up: ... includes.inc etc called then.... $sql = "SELECT * FROM video, registered_users WHERE video.id = '$get_id' AND video.user_id = registered_users.id"; $query_result = mysql_query($sql); $row = mysql_fetch_array($query_result); if ($session_userid) { $favtitle = $row['title']; $favusername = $row['user_name']; $favphoto = $row['photo']; $favorite = "<a style=\"position: relative; left: 310px; top: -43px; height: 0px; width: 100px; padding: 0;\" href=\"thispage.php?favorite_id=$get_id&id=$get_id&favorite_title=$favtitle&favorite_usern=$favusername&favorite_photo=$favphoto\" onClick=\"return confirm('click OK to add to favorites message');\"><img src='images/favorite_button.gif' alt='favorite button' width='90' height='40' border='0'></a>"; }else{ $favorite = "<a style=\"position: relative; left: 310px; top: -43px; height: 0px; width: 100px; padding: 0;\" href=\"thispage.php?id=$get_id\" onClick=\"return confirm('need to log in message');\"><img src='images/favorite_button.gif' alt='favorite button' width='90' height='40' border='0'></a>"; } .. rest of the code that makes up "thispage.php" where that same sql query works to display content on this page: for example: $tags = "$row[tags_text]"; ... the page ends exactly like this (no close brackets removed)... $favoritequiz = (int) $_GET['favorite_id']; if ($favoritequiz) { $favqtitle = mysql_real_escape_string($_GET['favorite_title']); $favqusername = mysql_real_escape_string($_GET['favorite_usern']); $favqphoto = mysql_real_escape_string($_GET['favorite_photo']); mysql_query("INSERT INTO favorites (favuser_id, favquiz_id, favtitle, favusername, favphoto) VALUES ('$session_userid', '$favoritequiz', '$favqtitle', '$favqusername', '$favqphoto')"); } include_once ("template.php"); ?> so basically, the user is on a page -- if he/she clicks "favorite" the important details are passed back to that same page and inserted into the database. I don't know where the sql is getting direction to enter or try to enter the data 4 times (as explained below). thank you again for your help,
  19. Hi all, This is a first for me... the code below is inserting 4 rows instead of 1. In one row everything is inserted, but in the 3 others, all but the $session_userid is inserted (it's inserted as 0). I don't want those 3 other rows, just the 1. Can you help point out what's going on here? $favoritequiz = (int) $_GET['favorite_id']; if ($favoritequiz) { $favqtitle = mysql_real_escape_string($_GET['favorite_title']); $favqusername = mysql_real_escape_string($_GET['favorite_usern']); $favqphoto = mysql_real_escape_string($_GET['favorite_photo']); mysql_query("INSERT INTO favorites (favuser_id, favquiz_id, favtitle, favusername, favphoto) VALUES ('$session_userid', '$favoritequiz', '$favqtitle', '$favqusername', '$favqphoto')"); } thanks,
  20. That helped, Mjdamato. Thank you. I got it working now.
  21. I'm freaking on this... I'm trying to say with this code: if the user is logged in, $favorite = this_image. else, $favorite = that_image. Then later do, $fav = "$favorite"; / echo "$fav" in the template. The problem I'm having is that two images are displayed. Two if logged in. Two if logged out. Can you help me get this working right? if ($session_userid === true) { $favorite = "<a href = \"this_page.php?favorite_id=$get_id\" onClick=\"return confirm('you sure message');\"><img src='images/favorite_button.gif' alt='favorite button' width='90' height='40' border='0'></a>"; }else{ $favorite = "<img src='images/favorite_button_not-logged-in.gif' alt='log in to favorite this page' width='90' height='40' border='0'>"; } $fav = <<<EOD $favorite EOD; The $fav variable is echoed in the template. Thanks!
  22. My code checks to see if the session userid is set, and if not throws an error. So.. which header best does this: - check to see if session has timed out - if not, perform the query - if so, the query is not performed and the "$sorry_error" is thrown thanks again for your advice..
  23. Hi All, I have a question regarding headers. Currently I'm using a php function that creates the html header: "Cache-control: private" on pages inserting or retrieving content from the database. I don't think this is the correct header to be using and I'm confused about which is the best fit. The site I'm working on relies solely on session variables. No cookies are ever set. There are quizzes -- the users' selected answers are compared to actual answers in the DB when the user clicks to see the results. I've noticed that when a quiz sits in a browser for 15 to 30 minutes before the user clicks to see the results, that sometimes totally random results appear -- as if the site had timed out, then sent a random "hey show me some results" request to the server, but the server didn't know which quiz we were on. I'm googling myself in circles over these: cache control: No-store cache control: max-age cache control: must-revlidate cache control: proxy-revalidate cache control: max-age or should I instead use the "session_cache_limiter()" function? If you have advice on which is the best fit and how/why -- Please let me know. Thank you very much for your help. Ryan
  24. Hi, This query works without any trouble: SELECT video_id FROM `quiz` GROUP BY video_id HAVING count( question ) <4 ORDER BY video_id ASC LIMIT 0 , 3000 And I'd like to work the "Having Count ()" part into this query below. Note -- without this part: HAVING count (quiz.question) >4 :: this query works perfectly. SELECT DISTINCT video.id, title, description_text, category_text, level_text, pass_text, user_name, quiz.video_id, quiz.question, DATE_FORMAT(date, '%M %D, %Y') as date FROM video, registered_users, quiz WHERE video.user_id = registered_users.id AND video.category_text = 'English' AND video.pass_text = 'new_quiz' AND quiz.video_id = video.id HAVING count( quiz.question ) >4 ORDER BY id DESC Can you help me with the syntax needed to smoothly incorporate "HAVING count (quiz.question) >4" into the above query? I know I have a long way to go to understand how to best optimizing queries -- but I'm getting there. Thank you very much for your help! Ryan
  25. Thanks guys. This works for what I needed. And now I'm on to my next speed bump.... Having (count)... which I'll start in a new thread. thank you both so much for your help! I'm learning a lot as I check and google my way through your input. Ryan
×
×
  • 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.