Jump to content

Search the Community

Showing results for tags 'PHP'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Calendars

  • Community Calendar

Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 857 results

  1. I’m facing problem in downloading two combined images on div where the code should be in html format. I want to download the div images in a local computer in the image format. Even, I want to take the screenshot of the two combined images simultaneously, please post me any proper solution for that.
  2. why is strcmp not working?

    I cant understand why this is not working.. I compare two strings, if they match then do something.. I'm getting values 1 for the first and 8 for the second?? carquest-clearvape carquest-carquest if (strcmp($_SESSION['username'],$username)==0) echo $this->amount($offer['amount'], $listing['currency']); else echo $this->amount("*****", $listing['currency']);
  3. GREETING: I hope that everyone who celebrated the American holiday of Thanksgiving this past week spent a wonderful holiday full of cheer, good food and drink, and restored family ties and friendships. My celebration was short, alone, but very well spent. And, in the quiet of the office, abandoned by nearly everyone for the holiday break, I was able to finish nearly three weeks of study, investigation, and experimentation with the grammar of the MySQL database. You may discover the results by clicking on any direct reference to a specific podcast on the Grammar Captive Weekly Podcast webpage that is itself not a referenced podcast. This includes requests for a specific podcast coming from remote third parties. Not only do the referenced podcasts appear, where before they did not, but only that number of podcasts actually referenced fills the page. Important in your regard is that I have W3Schools to thank for helping me to realize what for me has been a major feat. Many thanks! BACKGROUND: In the same spirit of good coding practice I have another question related to coding strategy. All of the Click and Listen panels are created from a subsection of the same HTML template that is included into a PHP template generator before being dumped into the host HTML webpage as a dynamically filled <div> of the Grammar Captive Weekly Podcast page. QUESTION: Where, how, and, of course, when is the best place and time to enter the CSS styling? On the HTML template, the final hosting page, or dynamically via PHP before the page is dumped into the host page. In answering these question please explain your logic for recommending the strategy that you do. Roddy
  4. Two Forms, Two Actions, Same Page

    BACKGROUND: Good ideas are sometimes like luck, they come in streaks. Thanks to the experiential wisdom of this forum and those around me in the Galvanize collective workspace, I have decided to tarry a little longer with the reconstruction of my data base. Indeed, I have learned a new term -- normalization. What before I intended to achieve with row duplication I hope now to achieve with simple updates. In order to achieve this important structural change and still retain the benefits of the old structure, I must disengage one of my form's <fieldset>s and create from it a new form that is submitted manually and only occasionally. It would appear that the small changes to the separate table that this fieldset previously replenished with each new form submission can now be achieved with MySQL TRIGGER and UPDATE statements. This strategy has led to the following two questions: QUESTION ONE: Under the assumption that one can have only one $_POST variable per page how does one typically go about using the same $_POST variable for multiple forms on the same page? If I were to implement this task on my own, without the advice of others, I would create a bivariate if-. else if-, else- statement that tests for the present of one of two variables and then handles only that data associated with the form submitted. Is there another, perhaps more thorough, separation that does not include the creation of a separate form page? QUESTION TWO: When executing a MySQL TRIGGER that updates a single row value of a single column of a table different from the one that executes the trigger, will the DEFAULT setting for the UPDATE statement trigger a timestamp with the ON UPDATE CURRENT_TIMESTAMP? As always your wisdom would be well-appreciated. Roddy
  5. form validation

    <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php /** * Note that the salt here is randomly generated. * Never use a static salt or one that is not randomly generated. * * For the VAST majority of use-cases, let password_hash generate the salt randomly for you */ // define variables and set to empty values $usernameErr = $passwordErr = $firstnameErr = $emailErr = $genderErr = $websiteErr = ""; $username = $password = $firstname = $email = $gender = $comment = $website = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["username"])) { $usernameErr = "UserName is required"; } else { $username = test_input($_POST["username"]); if (!preg_match("/^[a-zA-Z ]*$/",$username)) { $usernameErr = "Only letters and white space allowed"; } } if (empty($_POST["password"])) { $passwordErr = "password word is required"; } else { $password = test_input($_POST["password"]); if (!preg_match("/^(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])\S{8,}/",$password)) { $passwordErr = "<br>Password must be a mixure of <br>no# and letters containing <br>upper & lower case letters <br>at least 8 charecters<br>long"; } } if (empty($_POST["firstname"])) { $firstnameErr = "FirstName is required"; } else { $firstname = test_input($_POST["firstname"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) { $firstnameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation Example</h2> <p><span class="error">* Required Fields</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Username:<br/> <input type="text" name="username" value="<?php echo $username;?>"> <span class="error">* <?php echo $usernameErr;?></span> <br><br> Password:<br/> <input type="password" name="password" value="<?php echo $password;?> ?> "> <span class="error">* <?php echo $passwordErr;?></span> <br><br> Firstname:<br/> <input type="text" name="firstname" value="<?php echo $firstname;?>"> <span class="error">* <?php echo $firstnameErr;?></span> <br><br> E-mail:<br/> <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Website:<br/> <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Comment:<br/> <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> Gender:<br/> <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type = "reset" name = "reset"/> | <input type="submit" name="submit" value="Submit"> </form> <h2><?php echo "WELLCOM!";?> <?php echo $username;?></h2> <?php $options = [ 'cost' => 9, 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM), ]; echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options); echo "<br>"; echo $firstname; echo "<br>"; echo $email; echo "<br>"; echo $website; echo "<br>"; echo $comment; echo "<br>"; echo $gender; ?> </body> </html> Hello I need some advise on this need to make sure this is correct . I took this form from w3shools a long time ago. I modified it with regular expressions went to php.net, pick the hash function manipulated the code a little bit just need to make sure it gonna fly thank you in advance
  6. What does this code do?

    Hello All, This is my first post as I am new to PHP. I am learning how to develop web apps for education using PHP, CSS and HTML. I dont know any of those languages. My question is what does the following code do/mean?: $page = ($_GET['page'])
  7. Small Group Projects

    I think it would be great to have small group projects .We could build login system; with air tight state of the art security, photo gallary's, audio gallery's. I think it would be a great tool for learning web development . Just a thought.
  8. Auto Registering Files

    Im wondering if there is a way to to automaticly register a php file , so it wont show up when reading a directory. Doing this || $file == "somefile.php" after ten or twenty time gets to be grievious
  9. I've been using HTML_CodeSniffer to do accessibility testing of web pages. I have been successful reducing errors to 0 but I get lots of warnings about color ratio, text on background images. My page is primarily white background with black or blue (links) text. Is there something I can do to get rid of the warning? If you are familiar with accessibility test, do warnings count against you? Basically, I'm ignoring warnings.
  10. Hello I need to remove a certain part on my page. Here is the link of the page. http://communityofsol.gr/?page_id=139 You see a brown canvas. In the canvas it says "Παροχές υπηρεσιών σε απόρους" , Below it, it says Home / Παροχές υπηρεσιών σε απόρους. I need to remove everything after Home ( what you see in bold). PLEASE assist me because I have a deadline and I need to do it! Thank you in advance!
  11. This script shows the fetched data in a modify form. In the old situation I used rec_num wich was corresponding to the record number in the database.table For security reasons I added a uniqid column to the table. So not like under with an input hidden attribute for uniqid. If possible I would like it to be stored in a session variable. This is doable like above, but outside the foreach loop only the last value is stored. How to connect every single uniqid value (for multiple records!) to the separated rec_num without users being able to see the uniqid? $value = $_POST['checkbox_values']; $i=0; foreach ($value as $values) { if (++$i > 10) break ; $element = explode(" / " , $values); $_SESSION['uniqid'] = $element[1]; var_dump($_SESSION['uniqid']); ?> <form action = "" method="post"> <input type ="hidden" name="rec_num[]" value="<?php echo $element[0] ;?>" > <!--<input type ="hidden" name="uniqid[]" value="<?php echo $element[1] ;?>" >--> <input type ="text" name="value1[]" value="<?php echo $element[5] ;?>" > <input type ="text" name="value2[]" value="<?php echo $element[6] ;?>" > <input type ="text" name="value3[]" value="<?php echo $element[7] ;?>" > <input type ="text" name="value3[]" value="<?php echo $element[8] ;?>" > <br> <?php } ?><br> <input type="submit" name="send" value="Modify "> </form>
  12. NOTE: The rooster has come home to rest. BACKGROUND: My recent ventures in SESSION variables and AJAX calls has opened up whole new worlds in the life of this unaspiring, inspired web developer. So, far I have used each to satisfy different, but similar tasks -- namely, fill differently the same section of my podcast host page with data from the same data base using both external ($_GET and $_SESSION variables) and internal $.ajax( ) triggers. It is now time to combine the results of these two procedures in the achievement of a third task. At the top of my podcast host page is a PHP if-statement that checks for the receipt of two $_GET variables. It cares not about the source of these variables and performs the same way whether they are received from an external HTTP request using a fully specified URL or my newly acquired knowledge of the href='?..." query specification. Both cause the page load. Neither method cares whether the page has already been loaded or not. QUESTION: How do I suppress the reload function of a HTTP request without sacrificing the other features commonly associated with HTTP requests. BY WAY OF ILLUSTRATION: In the event that more clarity is required. 1) EXTERNAL REQUEST: Click on the following link: http://www.grammarcaptive.com/podcast_dev_copy.php?hash=30a6836a3f7c5fc57751a61098e5c221&podcast_no=21 View the center section of the page that opens. The contents of this section is inserted using a PHP script located at the top of the opened page. The difference between a normal loading and what you observe when you click the above link can be easily seen by by omitting the query string -- namely, http://www.grammarcaptive.com/podcast_dev_copy.php. 2) INTERNAL REQUEST: What I would like to do is open similarly generated content using different data, from the same page. To observe this please do the following: Click on the word Chronology in the navigation bar of the opened page. Click on the phrase Podcast Index ... Click on any of phrase that reads Discover more ... Click on the phrase Click and Listen. Look at the result and you will discover similarly formatted, but different content in the center section of the page. I would like to achieve the same without having to reload the page. Could this be achieved with an event object such as event.preventDefault() PLEASE ADVISE. Roddy
  13. echo("<HTMLstuff>"); not working?

    Harrow fellow campaigners, no idea what is going wrong here. Maybe anybody has a solution: Assume $logged_in being true. check_account_status() not firing. Also tried to change the attribute to onclick, onmousedown etc. The HTML (.php): <div id="wrapper-secondnav" class=""> <ul id="secondnav"> <li><a target="_blank" href="">Stuff</a></li> <li><a href="">Things</a></li> <li><a target="_blank" href="">Somestuff</a></li> <li><a href="">Anything</a></li> <?php if ($logged_in != true) { echo('<li><a id="register">Nooo</a></li>'); } else { echo('<li><a id="register" onload="check_account_status();">Yay</a></li>'); } ?> </ul> </div> And then there is the function in JS: function check_account_status() { alert("I like cookies"); } Thank you very much!
  14. Text to Image Conversion

    Text to image conversion in php A string from db have to be converted into image but it is not working. If the string is not taken from the db and defined in the file itself text is getting converted into image properly Can anyone help to sort it out Attaching the code used for the same Thanks in advance <?php //error_reporting(E_ALL); include('connect.php'); $res = mysql_query("select * from imgtext")or die(mysql_error()); $arr = mysql_fetch_array($res); $data = $arr['data']; $textval = str_replace('\r\n',"<br>",$data); $textcolor = '666666'; //$string = preg_replace( "/\r|\n/", "", $textval); //echo $string;die; // $font="fonts"; $font="DidactGothic-Regular"; $size = 9; $padding= 1; $bgcolor= "ffffff"; $transparent = 0; $antialias = 0; $fontfile = $font; $box= imageftbbox( $size, 0, $fontfile, $textval, array()); $boxwidth= $box[4]; $boxheight= abs($box[3]) + abs($box[5]); $width= $boxwidth + ($padding*2) + 1; $height= $boxheight + ($padding) + 0; $textx= $padding; $texty= ($boxheight - abs($box[3])) + $padding; // create the image $png= imagecreate($width, $height); $color = str_replace("#","",$bgcolor); $red = hexdec(substr($bgcolor,0,2)); $green = hexdec(substr($bgcolor,2,2)); $blue = hexdec(substr($bgcolor,4,2)); $bg = imagecolorallocate($png, $red, $green, $blue); $color = str_replace("#","",$textcolor); $red = hexdec(substr($textcolor,0,2)); $green = hexdec(substr($textcolor,2,2)); $blue = hexdec(substr($textcolor,4,2)); $tx = imagecolorallocate($png, $red, $green, $blue); //print_r(imagettftext( $png, $size, 0, $textx, $texty, $tx, $fontfile, $textval )); //die; imagettftext( $png, $size, 0, $textx, $texty, $tx, $fontfile, $textval ); header("content-type: image/jpeg"); imagejpeg($png); imagedestroy($png); exit; ?> check.php
  15. Update The PHP Tutorial To Use PHP 7 And It's Features
  16. BACKGROUND: I have created a PHP routine that gathers data from a MySQL database. The data that it gathers depends on the value of an HTTP request that uses the $_GET superglobal as its transfer mechanism. The routine further organizes the retrieved information into a nested array such that each element of the array corresponds to a different table row, and each element of each nested array corresponds to a subset of the table fields. Once the nested array has been completed the json_encode() function converts the array into a JSON string and readies it for transport. The PHP <?php if(isset($_GET['podType']) { define('_HOST_NAME','...'); define('_DATABASE_NAME','...'); define('_DATABASE_USER_NAME','...'); define('_DATABASE_PASSWORD','...'); $mysqli_obj = new MySQLi(_HOST_NAME,_DATABASE_USER_NAME,_DATABASE_PASSWORD,_DATABASE_NAME); if($mysqli_obj->connect_errno) { die("ERROR : -> ".$mysqli_obj->connect_error); } $tbl_name = 'rss2_podcast_item'; $podcast_items = []; $result_obj = $mysqli_obj->query("SELECT * FROM " . $tbl_name); while($row = $result_obj->fetch_assoc()) { foreach($row as $key => $value) { $item_arr[$key] = $value; } $items[] = $item_arr; } //Creates a nested array whose subarrays consist of the four indicated elements. foreach ($items as $sub_arr => $element) { $podcast_item[] = $element['podcast_no_item']; $podcast_item[] = $element['item_title']; $podcast_item[] = $element['item_description']; $podcast_item[] = $element['item_pubdate']; $podcast_items[] = $podcast_item; $podcast_item = []; } echo json_encode($podcast_items, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK); } ?> The Javascript <script> $(document).ready(function() { $('li.podDex').each(function(){ var podType = $(this).attr('id'); //Causes the weight of the font to change when the mouse passes over the text. $('#'+podType).mouseover(function() { $(this).css({"cursor": "pointer", "font-weight":"800"}); }) .mouseout(function() { $(this).css("font-weight", "normal"); }); //Causes the weight of the font to change, displays the hidden text to appear in the #main <div> element, and brings about a change in color. $('#'+podType).mouseover(function() { $(this).css({"cursor": "pointer", "font-weight":"800"}); }) .click(function() { $.getJSON({ url: "../exp1/ajax_data.php", data: podType, success: function(json_data){ var data_array = $.parseJSON(json_data); alert(data_array[0]['podcast_no_item']); } }); }) .mouseup(function() { $(this).css({"color": "#fadb9d","font-weight": "normal"}); $('body, html').animate({scrollTop: $('#main').offset().top},800); }); }); }); </script> The HTML <ul> <li id='linear' class='podDex'>Linear Analysis</li> <li id='clausal' class='podDex'>Clausal Analysis</li> <li id='inversion' class='podDex'>Socratic Inversion</li> <li id='chronology' class='podDex'>Chronology</li> </ul> The Console Error Message is You are welcome to try it yourself. Please go to Grammar Captive and click on any of the four designated <li> elements. QUESTION: What might be causing the $.getJSON() call to fail? NOTE: A similar, but not identical, result occurs on my local test server.
  17. Path to Downloading Attachment

    Hello, I have a problem with my code.. I cant do download attachments, when I click in attachment "image.jpg", the link appears this way "www.site.com/image.jpg" but the link doesn't existed, and go to automatically to my home page without download the file.. $id = $_POST['id']; $pdo = new PDO("sqlite:mydb.db"); $email = $pdo->query("SELECT * FROM `myemails` WHERE `id`='$myid'")->fetch(PDO::FETCH_ASSOC); $email_body = base64_decode($email['message']); $letter_html = ""; $op_getKey = preg_match_all("/boundary=\"(.*)\"/", $email_body, $getKey); $has_attachment = preg_match_all("/multipart\/mixed/", $email_body, $attachment); if ($op_getKey) { if ($has_attachment) { $mailParts = explode("--" . $getKey[1][1], $email_body); $attachParts = explode("--" . $getKey[1][0], $email_body); $get_attach_name=preg_match_all("/filename=\"(.*?)\"/", $attachParts[2], $attach_name); $get_attach_type=preg_match_all("/Content-Type: (.*?);/", $attachParts[2], $attach_type); $pure_code = explode("\n\n",$attachParts[2]); $pure_code = str_replace("\r","",$pure_code[1]); $pure_code = str_replace("\n","",$pure_code); }else{ $mailParts = explode("--" . $getKey[1][0], $email_body); } Can you give me some help implementing this code in my code? $savedir = __DIR__ . '/attachment/'; $myemail = $email->search('ALL'); if ($myemail ) { rsort($myemail ); foreach ($myemail as $my2email) { foreach ($my2email->getAttachments() as $attachment) { $savepath = $savedir . $attachment->getFilename(); file_put_contents($savepath, $attachment); } } } So that it is possible, whenever you receive an email, that the file go to the "attachment" folder and can download the image or file .. When I click in attachment and I just wanted that's possible to download the image, pdf, txt, zip, rar, etc.. once they are saved in the attachment folder. I already called the attachment of these two forms, but nothing.. PHP Code: <a target="_blank" href="https://site.com/<?=$attach_name[1][0]?>" data-target="<?=$id?>"><?=$attach_name[1][0]?></a> <a target="_blank" href="data:<?=$attach_type[1][0]?>;base64,<?=$pure_code?>"> <?=$attach_name[1][0]?> </a> I don't know if u understand my problem. Best Regards
  18. Hello folks, I want to hide a text inside a image(users given image using file upload). Thanks in advance
  19. Read Multiple Rows Sequentially

    QUESTION ONE: What is it called when you traverse an entire table in equal multiples of records? (I ask this question, because I have been fraught with frustration in my google searches.) QUESTION TWO: Do you know a routine that I can copy and modify? (This would greatly simply my search.) BACKGROUND: Surely there must be a standard routine for performing the following procedure: 1) Use PHP to read and display the first ten records of a MySQL table. 2) Read and display the next ten records of the same data table. 3) Either return to the previously read ten records and display these or continue on to the following ten unread records and display them. 5) When you have reached the end of the table display only the remaining records. GOAL: Ultimately I would like to read and display 10 records in a list format. At the bottom of the list I would place two buttons. One that displays the previously 10 records and one that displays the next ten unread records. WHAT I HAVE ACHIEVED SO FAR: <?php $col_name = 'item_pubdate'; $result_obj = $mysqli_obj->query("SELECT * FROM rss2_podcast_item ORDER BY '$col_name' LIMIT 0, 10"); while($row=$result_obj->fetch_array()) { ?> <div class='table_row podcast_item'> <div class='flex_item num_div'><?php echo $row['podcast_no_item'] . '&nbsp'; ?></div> <div class='flex_item date_div'><?php echo $row['item_pubdate']; ?></div> <div class='flex_item title_div'><?php echo $row['item_title']; ?></div> </div><!-- end div.table_row --> <div class='table_row discover_div'> <div class='flex-item'>Discover more ...</div> </div><!-- end div.table_row --> <div class='table_row'> <div class='flex-item details_div'> <?php echo $row['item_description']; ?> </div><!-- end div.table_row --> </div><!-- end div.table_row --> <?php } ?> With a little additional CSS and Javascript I have been able to achieve the following display. Clicking on the phrase "Discover more ..." reveals the hidden detail obtained from $row['item_description]. No. Publication Date|Time Podcast Title 60 2017-06-19 17:26:41 Title Ten Discover more ... 59 2017-06-18 09:50:37 Title Nine Discover more ... . . . 51 2017-09-24 11:00:17 Title One Discover more ... DESIRE: If I can only achieve the above stated goal, I can likely figure out a way to get AJAX to allow users to select podcast items by the week, month, year, and later category. But, this is already much too far into the future. For the moment, I would simply like to achieve my above stated goal. Any ideas? Roddy
  20. Please consider the following two sets of code. Are they not identical in their functionality? BACKGROUND: I am troubled by the following set of code, for it intertwines PHP and HTML in a way that, for me, is neither intuitive, nor reasonable based on my limited knowledge of how PHP and HTML work. This said, it appears to work. <?php if(isset($_GET['edit'])) { ?> <button type="submit" name="update">update</button> <?php } else { ?> <button type="submit" name="save">save</button> <?php } ?> ANALYSIS: Had I written the code I would have felt compelled to enter the <button> elements as part of PHP echo statements. QUESTION: Is this proper coding technique? Roddy
  21. From PHP to JavaScript with Node.js

    Hi! I'm Vincent from Matters. I am transitioning from PHP to JavaScript. I wanted to give back to the community so I wrote an article about it: https://blog.matters.tech/migrating-from-php-to-javascript-with-node-js-155534498b58 I hope it will be useful to some! Feedback warmly welcome https://twitter.com/cold_lestat
  22. The CodexWorld DB Class

    <?php /* * DB Class * This class is used for database related (connect, insert, update, and delete) operations * @author CodexWorld.com * @url http://www.codexworld.com * @license http://www.codexworld.com/license */ class DB{ private $dbHost = "..."; private $dbUsername = "..."; private $dbPassword = "..."; private $dbName = "..."; public function __construct(){ if(!$this->db){ // Connect to the database $conn = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName); if($conn->connect_error){ die("Failed to connect with MySQL: " . $conn->connect_error); }else{ $this->db = $conn; } } } /* * Returns rows from the database based on the conditions * @param string name of the table * @param array select, where, order_by, limit and return_type conditions */ public function getRows($table,$conditions = array()){ $sql = 'SELECT '; $sql .= array_key_exists("select",$conditions)?$conditions['select']:'*'; $sql .= ' FROM '.$table; if(array_key_exists("where",$conditions)){ $sql .= ' WHERE '; $i = 0; foreach($conditions['where'] as $key => $value){ $pre = ($i > 0)?' AND ':''; $sql .= $pre.$key." = '".$value."'"; $i++; } } if(array_key_exists("order_by",$conditions)){ $sql .= ' ORDER BY '.$conditions['order_by']; } if(array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){ $sql .= ' LIMIT '.$conditions['start'].','.$conditions['limit']; }elseif(!array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){ $sql .= ' LIMIT '.$conditions['limit']; } $result = $this->db->query($sql); if(array_key_exists("return_type",$conditions) && $conditions['return_type'] != 'all'){ switch($conditions['return_type']){ case 'count': $data = $result->num_rows; break; case 'single': $data = $result->fetch_assoc(); break; default: $data = ''; } }else{ if($result->num_rows > 0){ while($row = $result->fetch_assoc()){ $data[] = $row; } } } return !empty($data)?$data:false; } } $test = new DB(); if ($test instanceof DB) { echo 'Instantiated'; } else { echo 'Uninstantiated. Include failed.'; } $conditions = []; $tbl_name = 'rss2_podcast_item'; $test->getRows($tbl_name, $conditions); function getRows($mysqli_obj, $table,$conditions = array()){ $sql = 'SELECT '; $sql .= array_key_exists("select",$conditions)?$conditions['select']:'*'; $sql .= ' FROM '.$table; if(array_key_exists("where",$conditions)){ $sql .= ' WHERE '; $i = 0; foreach($conditions['where'] as $key => $value){ $pre = ($i > 0)?' AND ':''; $sql .= $pre.$key." = '".$value."'"; $i++; } } if(array_key_exists("order_by",$conditions)){ $sql .= ' ORDER BY '.$conditions['order_by']; } if(array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){ $sql .= ' LIMIT '.$conditions['start'].','.$conditions['limit']; }elseif(!array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){ $sql .= ' LIMIT '.$conditions['limit']; } $result = $mysqli_obj->query($sql); if(array_key_exists("return_type",$conditions) && $conditions['return_type'] != 'all'){ switch($conditions['return_type']){ case 'count': $data = $result->num_rows; break; case 'single': $data = $result->fetch_assoc(); break; default: $data = ''; } }else{ if($result->num_rows > 0){ while($row = $result->fetch_assoc()){ $data[] = $row; } } } return !empty($data)?$data:false; } ?> <?php $tbl_name = 'rss2_podcast_item'; $conditions = []; print_r(getRows($mysqli_obj,$tbl_name,$conditions)); ?> Please find above two sets of code and a quoted error message from the first set. The first set of code is a portion of a PHP class called DB. The second set of code is extracted from the first and modified in order to test the integrity of the function. At the bottom of each block of code is included the code necessary to call the getRows() method/function. Whereas the method of the class fails, the extracted function does not. In both cases the same database and table are accessed with success. I am suspicious of the way in which the class is constructed. I have tried several modifications, but none of them appear to work. Roddy
  23. BACKGROUND: Please go to the following webpage and note four different ways to fill the center section. 1) The center section is loads with the rest of the page as the content of <div id='main'> 2) The center is replaced with hidden content already on the page using jQuery's html( ) function. (Click in the navigation panel on the phrase "Form, Use, and Meaning'.) 3) The center is replaced with a portion of content from another page using jQuery's load( ) function. (Click in the navigation panel on the phrase "Words, Phrases, and Clauses".) 4) The center will be replaced with its original content, but without having to reload the page. The principle is the same as in Item 2, but the link mechanism is different. (Click on the host's image.) DILEMMA: I want to fill the same section with an HTML-formatted template filled with information from a data base that opens simultaneously with the page. CONSTRAINTS: 1) The host page for the content -- namely, podcasts_dev_copy.php is structurally complete. Any changes that I make to it should be minor. 2) The content of the middle section must be filled invisibly before the host page opens, or it must fill simultaneously with the host page. RESOURCES: 1) I have developed a PHP page that takes information sent to it from a 3rd party HTTP request, downloads data from a database that is based on the request, and opens to the host page with a portion of the processed information using a $_SESSION superglobal and the PHP header( ) function and location property. (This page has not been posted.) 2) A template engine that generates the replacement content from the same $_SESSION superglobal Have you got any ideas? Roddy
  24. $SERVER['QUERY_STRING']

    QUESTION: What does it mean when the value of the QUERY_STRING looks like the following without end? &width=1920&height=1200&width=1920&height=1200&... Roddy
  25. How to auto create a new page based on inputs

    My school asked me for a website where they can post their pictures on. Pictures from camp/city trips etc. I said that I never build a website before, but I would like to try it. So I googled and googled, then almost a week later I have this (code is below the text) I still have one problem: I have a login page which can be accessed by the teachers, I have a upload button and a name field, so every time when they have new pictures they can upload them and choose a name. But there isn't happening anything with the data. Is it possible that it automatically creates a page based on a tamplate with the before indicated input? I read something about get and post, but I have no idea how I could use that. I also read something about MySQL, but I have absolutely no idea how I could use something like that. So my question: How can I automatically create a new page, based on the input from another page. This is the website: http://thorbeckefotos.tk/ In the top right corner is a small login button, if you press the botton, you go to the login page (username: user password: password) if you continu you see the page that can be accessed by the teachers. Tamplate code: <!DOCTYPE html> <html> <head> <title>Thorbecke foto's</title> </head> <link rel="icon" href="images/logos/thorbecke.png"> <body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <img src="images/Banner.png"> <a href="https://twitter.com/ThorbeckeSG"> <img src="images/logos/twitter.png" style="position:absolute; top: 5px; right: 153px;"></a> <a style="position:absolute; top: 12px; right: 20px;" href="https://twitter.com/ThorbeckeSG">Thorbecke Twitter</a> <a href="http://www.thorbecke-zwolle.nl"> <img src="images/logos/thorbecke.png" style="position:absolute; top: 37px; right: 163px"></a> <a style="position:absolute; top: 42px; right: 40px;" href="https://www.thorbecke-zwolle.nl">Thorbecke Site</a> <a href="https://www.youtube.com/channel/UCcGO0gpLrWdWMxmycPjh7Bg"> <img src="images/logos/youtube.png" style="position:absolute; top: 70px; right: 153px"></a> <a style="position:absolute; top: 72px; right: 5px;" href="https://www.youtube.com/channel/UCcGO0gpLrWdWMxmycPjh7Bg">Thorbecke YouYube</a> <a href="contact/index.php"> <img src="images/logos/contact.png" style="position:absolute; top: 92px; right: 153px"></a> <a style="position:absolute; top: 100px; right: 92px;" href="../contact/index.php">Contact</a> <br> <br> <br> </body> <link href='style.css' rel='stylesheet'> <ul> <li><a href="../index.htm">Home</a></li> <li><a>2017/18</a> <ul> <li><a href="Examenreis_Berlijn.htm">Examenreis Berlijn</a></li> <li><a href="Examenreis_Londen.htm">Examenreis Londen</a></li> <li><a href="Examenreis_Parijs.htm">Examenreis Parijs</a></li> <li><a href="Disco.htm">Disco klas 1</a></li> <li><a href="Biodag.htm">Biodag 3M</a></li> <li><a href="Introductie.htm">Introductie klas 3/4M</a></li> </ul> </li> <li><a>2016/17</a> <ul> <li><a href="../2016,17/Werkweek.htm">Werkweek</a></li> <li><a href="../2016,17/Grote_Avond.htm">Grote Avond</a></li> <li><a href="../2016,17/Skiereis.htm">Skireis</a></li> <li><a href="../2016,17/Diploma_uitreiking_Atheneum.htm">Diploma uitreiking Atheneum</a></li> <li><a href="../2016,17/Diploma_uitreiking_Havo.htm">Diploma uitreiking Havo</a></li> <li><a href="../2016,17/Diploma_uitreiking_Mavo.htm">Diploma uitreiking Mavo</a></li> <li><a href="../2016,17/Galaklas2.htm">Gala klas 2</a></li> <li><a href="../2016,17/Examenreizen.htm">Examenreizen</a></li> <li><a href="../2016,17/Brugklasdisco.htm">Brugklasdisco</a></li> <li><a href="../2016,17/Introductie.htm">Introductie klas 1M/H/A 3M 4A</a></li> <li><a href="../2016,17/Open_Dag.htm">Open Dag</a></li> </ul> </li> <li><a>2015/16</a> <ul> <li><a href="../2015,16/Diploma_uitreiking_Atheneum.htm">Diploma uitreiking Atheneum</a></li> <li><a href="../2015,16/Diploma_uitreiking_Havo.htm">Diploma uitreiking Havo</a></li> <li><a href="../2015,16/Diploma_uitreiking_Mavo.htm">Diploma uitreiking Mavo</a></li> <li><a href="../2015,16/Ijsverkoop_onioth.htm">Ijsverkoop Onioth</a></li> <li><a href="../2015,16/Onioth_kamp.htm">Onioth kamp</a></li> <li><a href="../2015,16/Werkweek.htm">Werkweek</a></li> <li><a href="../2015,16/Talendorp.htm">Talendorp</a></li> <li><a href="../2015,16/Skiereis.htm">Skireis</a></li> <li><a href="../2015,16/Going_Global.htm">Going Global</a></li> <li><a href="../2015,16/Open_Dag.htm">Open Dag</a></li> </ul> </li> <li><a>2014/15</a> <ul> <li><a href="../2014,15/kerstdinner.htm">Kerstdinner 4/5H</a></li> <li><a href="../2014,15/Munster.htm">Münster</a></li> <li><a href="../2014,15/Gala_klas_2.htm">Gala klas 2</a></li> <li><a href="../2014,15/Grote_Avond.htm">Grote Avond</a></li> <li><a href="../2014,15/Lisabon.htm">Lissabon</a></li> <li><a href="../2014,15/Londen.html">Londen</a></li> <li><a href="../2014,15/parijs.htm">Parijs</a></li> <li><a href="../2014,15/Barcelona.htm">Barcelona</a></li> <li><a href="../2014,15/Auditie_Grote_Avond.htm">Auditie Grote Avond</a></li> <li><a href="../2014,15/Stadshangenrun.htm">Stadshagenrun</a></li> </ul> </li> </ul> <br> <br> <br> <br> <center> <h1>Disco klas 1 2017/18</h1> <img src="images/Disco/breed001.jpg"> <img src="images/Disco/breed002.jpg"> <img src="images/Disco/breed003.jpg"> <img src="images/Disco/breed004.jpg"> <img src="images/Disco/breed005.jpg"> <img src="images/Disco/breed006.jpg"> <img src="images/Disco/breed007.jpg"> <img src="images/Disco/breed008.jpg"> <img src="images/Disco/breed009.jpg"> <img src="images/Disco/breed010.jpg"> <img src="images/Disco/breed011.jpg"> <img src="images/Disco/breed012.jpg"> <img src="images/Disco/breed013.jpg"> <img src="images/Disco/breed014.jpg"> <img src="images/Disco/breed015.jpg"> </center> <footer><h2><a font color="white" href="*download_url*">Download</h2></font></a> <h5>Gemaakt door Martijn Schuman</h5> <h5> Copyright 2017 All rights reserved. </h5> </footer> </html> Upload page code: <?php // Start the session ob_start(); session_start(); // Check to see if actually logged in. If not, redirect to login page if (!isset($_SESSION['loggedIn']) || $_SESSION['loggedIn'] == false) { header("Location: index.php"); } ?> <html> <head> <title>Thorbecke fotos upload</title> </head> <link rel="icon" href="images/logos/thorbecke.png"> <link href='style.css' rel='stylesheet'> <body> <img src="images/Banner.png"> </body> <form method="post" action="logout.php"> <input type="submit" value="Logout"><br> </form> <h2>Op deze pagina kan u een nieuwe activiteit aanmaken en foto's uploaden.</h2> <label for="activiteit">Activiteit:</label><br/> <input type="activiteit" placeholder="Activiteit"><br/> <br> <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="files[]" multiple> <input type="submit" value="Upload"> </form> </html>
×