Jump to content
Killersites Community

saversites

Member
  • Content count

    43
  • Joined

  • Last visited

Community Reputation

1 Neutral

About saversites

  • Rank
    Member

Recent Profile Visitors

145 profile views
  1. Php Gurus, My following code shows all the results of the "notices" tbl. That tbl has columns: id recipient_username sender_username message This code works but it does not use the PREP STMT. I need your help to convert the code so it uses PREP STMT. On this code, all the records are spreadover 10 pages. On the PREP STMT version, I need 10 records spreadover each page. So, if there is 3,000 records then all records would be spreadover 300 pages. NON-PREP STMT CODE $stmt = mysqli_prepare($conn, 'SELECT id, recipient_username, sender_username, message FROM notices WHERE recipient_username=?'); mysqli_stmt_bind_param($stmt, 's', $recipient_username); mysqli_stmt_execute($stmt); //bind result variables mysqli_stmt_bind_result($stmt, $id, $recipient_username, $sender_username, $message); //Get Data from Tbl "notices" $sql = "SELECT * FROM notices"; $result = mysqli_query($conn,$sql); //Total Number of Records $rows_num = mysqli_num_rows($result); //Total number of pages records are spread-over $page_count = 10; $page_size = ceil($rows_num / $page_count); //Get the Page Number, Default is 1 (First Page) $page_number = $_GET["page_number"]; if ($page_number == "") $page_number = 1; $offset = ($page_number -1) * $page_size; $sql .= " limit {$offset},{$page_size}"; $result = mysqli_query($conn,$sql); ?> <table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> <?php if($rows_num) {?> <tr name="headings"> <td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> <td bgcolor="#FFFFFF" name="column-heading_logging-server-date-&-time">Date & Time in <?php $server_time ?></td> <td bgcolor="#FFFFFF" name="column-heading_username">To</td> <td bgcolor="#FFFFFF" name="column-heading_gender">From</td> <td bgcolor="#FFFFFF" name="column-heading_age-range">Notice</td> </tr> <?php while($row = mysqli_fetch_array($result)){ ?> <tr name="user-details"> <td bgcolor="#FFFFFF" name="submission-number"><?php echo $row['id']; ?></td> <td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php echo $row['date_and_time']; ?></td> <td bgcolor="#FFFFFF" name="username"><?php echo $row['recipient_username']; ?></td> <td bgcolor="#FFFFFF" name="gender"><?php echo $row['sender_username']; ?></td> <td bgcolor="#FFFFFF" name="age-range"><?php echo $row['message']; ?></td> </tr> <?php } ?> <tr name="pagination"> <td colspan="10" bgcolor="#FFFFFF"> Result Pages: <?php if($rows_num <= $page_size) { echo "Page 1"; } else { for($i=1;$i<=$page_count;$i++) echo "<a href=\"{$_SERVER['PHP_SELF']}?page_number={$i}\">{$i}</a> "; } ?> </td> </tr> <?php } else { ?> <tr> <td bgcolor="FFFFFF">No record found! Try another time.</td> </tr> <?php }?> </table> <br> <br> <center><span style="font-weight: bold;"><?php $user ?>Notices in <?php $server_time ?> time.</span></center> <br> <br> </div> <br> </body> </html> The following codes are my attempts to convert the above code to PREP STMT but I see arrays with no records: $query = "SELECT id, recipient_username, sender_username, message FROM notices ORDER by id"; $result = $conn->query($query); /* numeric array */ $row = $result->fetch_array(MYSQLI_NUM); printf ("%s (%s)\n", $row[0], $row[1]); /* associative array */ $row = $result->fetch_array(MYSQLI_ASSOC); printf ("%s (%s)\n", $row["id"], $row["recipient_username"], $row["sender_username"], $row["message"]); /* associative and numeric array */ $row = $result->fetch_array(MYSQLI_BOTH); printf ("%s (%s)\n", $row[0], $row["id"], $row[1], $row["recipient_username"], $row[2], $row["sender_username"], $row[3], $row["message"]); /* free result set */ $result->free(); /* close connection */ $conn->close(); $stmt = "SELECT id,date_and_time,recipient_username,sender_username,message FROM notices WHERE recipient_username = ?"; mysqli_stmt_bind_param($stmt, 's', $username); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); mysqli_stmt_bind_param($stmt, 's', $username); mysqli_stmt_execute($stmt); $result = mysqli_stmt_bind_result($stmt,$db_id,$db_date_and_time,$db_recipient_username,$db_sender_username,$db_message); mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); $query = "SELECT id, recipient_username, sender_username, message FROM notices"; if ($stmt = mysqli_prepare($conn, $query)) { //execute statement mysqli_stmt_execute($stmt); //bind result variables mysqli_stmt_bind_result($stmt, $id, $recipient_username, $sender_username, $message); //fetch values while (mysqli_stmt_fetch($stmt)) { printf ("%s (%s)\n", $id, $recipient_username, $sender_username, $message); } //close statement mysqli_stmt_close($stmt); } close connection mysqli_close($conn); close connection mysqli_close($conn); $stmt = mysqli_prepare($conn, 'SELECT id, recipient_username, sender_username, message FROM notices WHERE recipient_username=?'); mysqli_stmt_bind_param($stmt, 's', $recipient_username); mysqli_stmt_execute($stmt); $notices_row = array(); mysqli_stmt_bind_result($stmt, $notices_row['id'], $notices_row['recipient_username'], $notices_row['sender_username'], $notices_row['message']); while (mysqli_stmt_fetch($stmt)) { echo '<p>' . $notices_row['recipient_username'] . '</p>'; } I give-up. They all show results like the following, even though the tbl rows have data: 28 () 29 () 30 (30) If you know of a simpler way (cut down version) for the tbl to display all rows from all columns using PREP STMT using Precedural Style then be my guest to show a sample. Thanks for your helpS.
  2. Why cURL Fails To fetch Page ?

    I now get error that variable $url is undefined on line 72. Notice: Undefined variable: url in C:\xampp\htdocs\...... If you check line 72, it says between double quotes: $url = "http://devshed.com"; Even if I change the url to a url who's page cURL is able to fetch, I still get the same error. This does not work either, with single quotes: $url = 'http://devshed.com'; This is very very strange! If the $url variable has not been defined then how is cURL able to fetch the page who's url is on the $url variable value ? Even though page gets fetched, I still see the error! Weird!
  3. Why cURL Fails To fetch Page ?

    I added this line today ... echo "$response[http_code]"; Result I get is this: 403. Googling, I see that the page devshed.com is forbidden. Since I can view the page on y browser and not manage to get cURL to fetch it then I'm guessing devshed.com has put a measurement in place to foil proxies. Switched the url to another site and that got fetched. last night, even google did not get fetched and so I suspected maybe I accidently deleted something from my code but could not spot the deletion. Hence, opened this thread to see if anyone else spots it. Now, I understand, both devshed.com and google were foiling the cURL fetch or proxy fetch. How well did I do ?
  4. Why cURL Fails To fetch Page ?

    Folks, Why is cURL failing to fetch the page ? All this time it worked. Echoes "Page fetching problem!" <?php //Required PHP Files. include 'config.php'; include 'header.php'; //1). Set Banned Words. $banned_words = array("asshole", "nut", "bullshit"); $url = "http://devshed.com"; // 2). $curl is going to be data type curl resource. $curl = curl_init(); // 3). Set cURL options. curl_setopt($curl, CURLOPT_URL, "$url"); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 4). Run cURL (execute http request). $result = curl_exec($curl); if (curl_errno($curl)) { echo 'Error:' . curl_error($curl); } $response = curl_getinfo( $curl ); //If page is fetched then replace banned words found on page. if($response['http_code'] == '200' ) { $regex = '/\b'; $regex .= implode('\b|\b', $banned_words); $regex .= '\b/i'; $substitute = 'BANNED WORD REPLACED'; $clean_result = preg_replace($regex, $substitute, $result); //Present the banned words filtered webpage. echo $clean_result; } else { //Show error if page fetching failed. echo "Page fetching problem!"; exit(); } ?>
  5. Php Folks, What is the regex to extract the content of a webpage that is visible to the user in his browser no matter what is visible to the web crawler (searchengine spider or bot)? That means, it should ignore the following and not extract these tags or any data inbetween these tags excluding the <body> & </body> tags as including that in the filter would render the data extraction useless: title title tags meta keywords meta keywords tags meta descriptions meta descriptions tags html tags dhtml tags xml tags javascript tags, etc. tags. If you know of php functions, other than regex that do what I want, then say so by writing: OFF TOPIC. Thanks for your help!
  6. What Is The Regex To Deal With Html Tags ?

    Php Folks, What is the regex to extract the title, meta keywords, meta descriptions and the content text (without all the tags such as html tags, dhtml tags, xml tags, javascript tags, etc.) ? I actually, prefer one regex to extract title, another to extract meta keywords, another to extract meta descriptions and finally another to extract the content text. That way, I can make use of each separately when I don't want to extract all (title, description, etc.). If you know of php functions, other than regex that do what I want, then say so by writing: OFF TOPIC. Thanks for your help!
  7. RegExp Exps (Regular Expression Experts), What is the regex to extract your desired text inbetween 2 tags such as the opening html tag and the closing. Should work for other tags too such as javascript, xml, dhtml, css, etc. Imagine that, I'm on a webpage that looks like this in the source code: <html> <head><title>Article</title></head> <body> Regex is too complicated to learn!<br> Why on earth could not the inventors build it simpler so it is easier to learn ?<br> Oh boy, oh boy!<br> </body> </html>
  8. How To Line Each Word On It's Own Line ?

    Problem is, I don't know how many words there would exist on a page and therefore don't know how many arrays to create for each word. In my example above, I just used 5 words but in reality I won't know how many words would exist on a page. Trying to build a web crawler. So far, getting cURL to fetch the pages found on my db (user submissions). Now, php needs to break each sentence into words found on the fetched page (for my crawler to learn what keywords make-up the page) and line them up one by one. Like so: 1st word 2nd word 3rd word and so on for each and every word.
  9. How come the $words variable contain the value "1" ? <?php $content = "word1 word 2 word3 word 4 word5"; echo "Content: $content<br>"; $words = print_r(explode(" ", $content)); echo "words: $words"; ?> I see this: Content: word 1 word 2 word 3 word 4 word 5 Array ( [0] => word 1 [1] => word [2] => 2 [3] => word 3 [4] => word [5] => 4 [6] => word 5 ) words: 1 Anyway, I am trying to get each word from $content lined up like this: word 1 word 2 word 3 word 4 word 5 How do I do it ? Any code sample appreciated. Replacing the print_r with var_dump not good, either. :chomp: As I see this: Content: word1 word 2 word3 word 4 word5 array(7) { [0]=> string(5) "word1" [1]=> string(4) "word" [2]=> string(1) "2" [3]=> string(5) "word3" [4]=> string(4) "word" [5]=> string(1) "4" [6]=> string(5) "word5" } words: No good: <?php $content = "word1 word 2 word3 word 4 word5"; echo "Content: $content<br>"; $words = var_dump(explode(" ", $content)); echo "words: $words"; ?> Neither no good just echoing the $words value as I see this: Content: word1 word 2 word3 word 4 word5 Notice: Array to string conversion in C:\xampp\htdocs\project\explode.php on line 8 words: Array And, no good this, either: <?php $content = "word1 word 2 word3 word 4 word5"; echo "Content: $content<br>"; $words = (explode(" ", $content)); echo "words: $words"; ?> Thanks
  10. Php Buddies, I'm going to jump into building my own searchengine now. Starting off with the search box, then the index and then finally the crawler. Not too worried about the crawler. Gonna make use of cURL and implode,explode, etc. php functions. It's the Index that I quite can't get my head around. To build the Index, should I have the structure of the mysql tbl like this .... ? Option 1 Columns Url|Keywords Or, should I make the structure like this instead ..... ? Option 2 Columns Keyword|Urls Option 1a Example Columns Url | Keywords ----------------------------------------------------------------------- devshed.com | forum, programming, php Option 1b Example Columns Keyword | Urls -------------------------------------------------------------------------------------------------------------------------- forum | devshed.com, blackhat.com, warriorforum.com --------------------------------------------------------------------------------------------------------------------------- php | devshed.com/forum/php.htm, sitepoint.com/forum/php.php Option 2a Example Columns Urls | Keyword ----------------------------------------------------------------------- devshed.com | forum ----------------------------------------------------------------------- devshed.com | programming ----------------------------------------------------------------------- warriorforum.com | money ----------------------------------------------------------------------- warriorforum.com | forum Option 2b Example Columns Keywords | Urls -------------------------------------------------------------------------------------------------------------------------- forum | devshed.com/forum -------------------------------------------------------------------------------------------------------------------------- forum | blackhat.com/forum --------------------------------------------------------------------------------------------------------------------------- php | devshed.com/forum/php.htm --------------------------------------------------------------------------------------------------------------------------- php | sitepoint.com/forum/php.php Question 1: I have a feeling you won't like Option 1a or 1b atall. But, let's assume you need to do it out of them 2 options. Which one would you choose ? Question 2: I have a feeling you will like Option 2a or 2b. Which one would you choose ? Or, if you don't like any of them 2. Then, let's assume you need to do it out of them 2 options. Which one would you choose ? Question 3: If you don't like the structure of any of the 4 options then which structure would you yourself use or have used ? Best to show an example like I did. Btw, I know that, if I structure my tbl around the way I showed in my examples then users would only be able to make queires for a single keyword and not a phrase. But, dealing with phrases get complicated and so for the time being, as a beginner, let's concentrate one thing at a time. Concentrate on the very first basic of indexing a url. Thanks
  11. How You Would INSERT ?

    Php Masters! I need to know how you do things the way you do things. Let us say, I am building a Social Network (SN). Let us say, my mysql db looks like this in structure: METHOD 1 Tbl: users; Columns: id, username, email, friends. Example: id|username|email|friends 0|uniqueideaman|uniqueideaman@**.com|user1,user500 ,user697 Do you see, how I have crunched-up 3 usernames into a single cell ? Q1. Is this how you would do it to list my friends' usernames ? --------------- METHOD 2: I was told I should do it like this: Anyway, I was told to check these out: https://en.wikipedia.org/wiki/Fourth_normal_form https://www.youtube.com/watch?v=UrYLYV7WSHM Did not bother with the vid as I'm on low bandwidth. Also, googled: https://www.google.com/search?q=what...hrome&ie=UTF-8 And read: https://www.tutorialcup.com/dbms/fourth-normal-form.htm You php pro, do you think I should have a friends list where every member link is recorded in a three column table, the first being an auto_increment ID to keep all records sequential and unique, the 2nd ID is the User ID (UID) and the Friend ID is the FID ? Tbl: Friends ID is auto incremented. UID is User's ID. FID is Friend's ID. Columns ID | UID | FID 1 | 3 | 24 2 | 3 | 399 3 | 55 | 24 4 | 598 | 3 5 | 598 | 55 6 | 6000 | 598 7 | 3 | 598 8 | 24 | 55 9 | 55 | 598 So, you think apart from having the "users" tbl that lists the users during registration, I should have another tbl "friends" ? And you want me to populate the "freinds" tbl like shown above. Right ? Yes or no ? If "yes", then how would you db query to pull-up a user's friends ? Let's say you want to pull-up UID 5's friends. This is my try using PREP STMNT: $stmt = mysqli_prepare($conn, "SELECT FID FROM users WHERE UID = ? "); In the above example you can see that ID's 1 & 2 have two entries for UID 3 who is linked to friend's FID 24 & 399 and is also friends with UID 598. It appears that I am having multiple links here. And therefore, I did not originally want to do it this way to save the db getting populated to much (too many entries) to save it from getting bogged down from doing too many tasks. Q2. Would not it be less resource using and less querying (hence less traffic to the db) if I do it the way I demonstrated in my original post ?
  12. Happy Holiday Php Guys! You know, few yrs back I've fiddled with file cutting software where I cut a file into lots of smaller files. I've also merged lots of files into one. Now, I did all this with a desktop software (.exe). Now, I want to do it with php. Therefore, in order to cut & shorten and merge and enlarge text files, which functions should I look into ? Same question goes for img files. First, I want to cut an img file into many smaller files. For example, look at this img here: Logo Design Tool. Free and Online. The img shows text: Happy New Year. That phrase is displayed using a certain font. Now, I want to have each letter/char on it's own. That means, I need to cut the img file into many smaller files so each file only contain one letter/char. Eg. h.jpeg a.jpeg p.gpeg py.jpeg y.jpeg and so on. So, how do I break an img file into lots of smaller files ? Which function to use to do that ? I can break the file in 3 ways: 1. Cut the file into many smaller files by inserting a number. Like break the big file into 10 smaller files. 2. Cut the file into many smaller files by inserting a percentage. Like break the big file into 20% smaller files. (This would break into 5 files only). 3. Cut the file into many smaller files by inserting a delimiter. The delimiter can be a colour. In this example: Logo Design Tool. Free and Online. If I insert black as the delimiter then each file would be separated using black as the separator. That means, each char would be separated by the black colour (background colour). Result ? I'd get each file containing one char/letter. You do understand what I'm trying to do, right ? From this img in our example, I'm trying to extract all the chars and save each char on a separate file on it's own. In this case, 12 files would be created for 12 chars. Now, I need to do all this with php. And so, how do I do it ? Which functions to use ? Have you experimented with this type of thing ? Erm: I always come-up with good idea projects for a beginner for my learning purpose. Is not that so ? Always adventurous. Yes, I am a different type of student. Unorthodox. A unique student. A unique way of learning student. And, you're going to be the unique type of helper. Where's the fun when every student or teacher does things the orthodox way ? Let's make a change. :cool:
  13. Happy New Year! Folks, Have you seen those online greeting cards, where you choose a template (like a bunch of people holding a big white empty sign board) and whatever you type in the "greetings" text box then that shows-up in the image (your typed text shows up in the sign board) ? How did they program all that with php ? I mean, they did some kind of a text layout on the img, right ? We've done this kind of thing in Adobe Photoshop but how does php manage it ? Does php have some builtin function that deals with overlaying one img or text over another img ? Img overlaying ? if not, then how'd they manage to program it ? If you don't mind, I'd like to see a code sample from your end. That can be my new year gift! I think the programmers do it like the following technique. See if I'm correct or not ... They cut the template img in half. So, in our example, the bunch of people holding the empty white signboard is one whole img. Like: full.jpeg. With phptoshop and the like, the webmaster cut the img in 2. Half half. Like: left_half.jpeg & right_half.jpeg. Now, let's deal with you the user's input text and its img. With a font, let's say Ariel Style, I, the programmer, going to write each letter and save it. Like so: a.jpeg b.jpeg and so on right down to: y.jpeg z.jpeg Then, I'm going to give you, the visitor/greeting mssg creator a text box (in a web form). You will type your word such as: Happy New Year 2018. And, my script will call the required jpeg files and combine them to form your word. Like so: h.peg,a.jpeg,p.peg,p.jpeg,y.jpeg and so on. You get the picture. Gonna put each appropriate img files side by side that will make up your chosen word. Eg. $word = $h = mydomain\h.jpeg.$a = mydomain\a.jpeg; AND SO ON until your word is formed: Happy New year 2018. //combine left half of img with right half of img with greeter's $word inbetween the 2 imgs. echo left_half.jpeg.$word.right_half.jpeg; //concatenation taking place here. Is this how the php programmers build these greeting card sites ? Meaning using the same method I did. Ok, maybe programming slightly differntly by using better codes but the method of adding the greeter's greeting words on the image template is done like so. Right ? Don't forget to PM me your emails so when I get this Greeting Card site of mine up and running then I can give you all a card. Lol!
  14. Happy New Year! Guys, Look at this site: https://cooltext.com/Logos-Ice They have text fonts or something. You type your words/phrase and your chosen letter style (their fonts) writes your words or phrase. How did the site manage to do that ? For example, look at the Ice Cube style: https://cooltext.com/Logo-Design-Ice-Cube Now, type any phrase and their site types your phrase using that style. How'd they program that ? I want to build a site like that. This is how I'm gonna built it .... With a font, let's say Ice Cube Style, I'm going to write each letter and save it. Like so: a.jpeg b.jpeg and so on right down to: y.jpeg z.jpeg Then, I'm going to give you a text box (in a web form). You will type your word such as: Get Lost. And, my script will call the required jpeg files and combine them to form your word. Like so: g.peg,e.jpeg,t.gpeg and so on. You get the picture. Gonna put each appropriate img files side by side that will make up your chosen word. Eg. $a = localhost\a.jpeg $b = localhost\b.jpeg $word = $a = localhost\a.jpeg.$b = localhost\b.jpeg; echo "$word"; Ok, I'm going to do something like that but not quite like that. You do understand what I'm trying to do and how I'm trying to organize things or put the script up. Is this how they usually do it ? Ok, I've shown you a code sample, even though it ain't that good. Now, how-about a sample from your end ?
  15. Folks, I'm creating like a meta engine where you choose which searchengine to use. I'll get to the point where my site will show you search results that have links from all searchengine results. But as for now, let's take things one step at a time. OFF TOPIC: Oh man! Shut the F* Up! (I got a lousy fox howling at the back of my backyard near the woods!). It shut the hell up once I wrote this. maybe, I'm becoming psychic some-how getting my message across to creepy things! Lol! TOPIC: For now, I'm giving user the option to choose which searchengine to use. Right now, I've managed to program where the search results (from your chosen searchengine) is shown on the current window. I want it to show in a new window. So, how to code that part ? I've googled and checked Stack Over Flow and I see a lot of others are searching for the same code but no one is having any luck! Here's my code for now: <?php /* ERROR HANDLING */ declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //Step 2: Check user submitted details. //2A. Check whether user made all the required inputs or not. if (isset($_POST["keywords"]) && isset($_POST["searchengine"])) { //2B. Create variables based on user inputs. $keywords = trim($_POST['keywords']); $searchengine = trim($_POST['searchengine']); if (strlen($searchengine) < 1) { $searchengine = 'mysearchengine'; } elseif ($searchengine = 'google') { $serp = "https://www.google.com/search?q=$keywords"; header("location: $serp"); } elseif ($searchengine = 'yahoo') { $serp = "https://search.yahoo.com/search?p=$keywords"; header("location: $serp"); } elseif ($searchengine = 'msn') { $serp = "https://www.bing.com/search?q=$keywords"; header("location: $serp"); } echo "$searchengine"; echo "$keywords"; } } ?> <!DOCTYPE html> <html> <head> <title><?php $site_name ?>Meta Searcher</title> <meta charset="utf-8"> </head> <body> <form method="post" action=""> <p align="left"><h2>Meta Searcher</h2></p> <fieldset> <label for="keywords_search">Search Keywords:</label> <input type="text" name="keywords" id="kw" value="" placeholder="Keywords"><br> <label for="searchengine">Searchengine:</label> <input type="radio" name="searchengine" value="mysearchengine" <?php if(isset($_POST['mysearchengine'])) { echo 'checked'; }?> required>My Searchengine <input type="radio" name="searchengine" value="google" <?php if(isset($_POST['google'])) { echo 'checked'; }?> required>Google <input type="radio" name="searchengine" value="yahoo" <?php if(isset($_POST['yahoo'])) { echo 'checked'; }?> required>Yahoo <input type="radio" name="searchengine" value="msn" <?php if(isset($_POST['msn'])) { echo 'checked'; }?> required>Msn </fieldset> <div class="SubmitsAndHiddens"> <input type="hidden" name="meta_searcher" id="meta_searcher" /> <br> <button type="submit">Search!</button> <br> </div> </form> </body> </html>
×