Jump to content

Recommended Posts

Php Folks,

I started learning php originally from 2015. On & off. Part time.

Started getting into it seriously around 2017. From home. No classes. From forums and php manual and tutorial sites.

Still at oop & mysqli. Had ups & downs as first learnt a lot of old stuffs then found out they been deprecated. For example, if I had originally known pdo is modern over mysqli then I would started on pdo from beginning. Got no real guidance anywhere. Just learnt things the hard way, coming across obstacles and bugging forums. Half-way learning mysqli I come across pdo. So you see, if I had taken school classes then they would have started me on the new stuffs. But because I learning from home, I came across a lot of old tutorials and started from there without knowing they are sort of outdated stuffs. Anyway, I don't like quitting half-way and so did not quit mysqli for pdo when a lot of programmers advised me to dump mysqli for pdo. Thought,  since I "wasted time" on mysqli then might aswell build a few sites with it before ditching it.

Part time study. Full time working on projects for 3yrs now. projects are own "hobby sites" so to speak and not for clients. I am not the freelancer type or professional type. layman type. Never really have launched any sites. I finish one site/project then move onto another project for learning purpose. So I learn very little then moving onto building sites based on what little I learnt.

When I learnt how to use the SELECT, INSERT. DELETE, UPDATE in sql, I jumped into learning to build my own membership site (reg, log-in, logout, etc. pages) to deal with mysql db.

So far, built membership parts (login, logout, account homepage, pagination). All by copying codes from tutorials and forums from people like you and changing here and there according to my needs. And when I get stuck. I bug programmers like you. I do have a conscious and do not like plagiarism even while learning and so everytime I copy paste codes from tutorials or forums (where I get help), I retype every line and then delete the copy-pasted lines and leave my typed lines in the file. that way, I feel good I atleast made some effort to build the site rather than copy & paste. Then, I change the codes here and there to suit my purpose.

Don't you like me ? ;). You probably chuckling inside reading this.

Here's an example of how I copy-paste then re-write the lines.

	<?php
//Code from: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_login_form
?>
	<!DOCTYPE html>
<!DOCTYPE html>
<html>
<html>
<head>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
<style>
body {font-family: Arial, Helvetica, sans-serif;}
body {font-family: Arial, Helvetica, sans-serif;}
form {border: 3px solid #f1f1f1;}
form {border: 3px solid #f1f1f1;}
	input[type=text], input[type=password] {
input[type=text], input[type=password] {
  width: 100%;
  width: 100%;
  padding: 12px 20px;
  padding: 12px 20px;
  margin: 8px 0;
  margin: 8px 0;
  display: inline-block;
  display: inline-block;
  border: 1px solid #ccc;
  border: 1px solid #ccc;
  box-sizing: border-box;
  box-sizing: border-box;
}
}
	button {
button {
  background-color: #4CAF50;
  background-color: #4CAF50;
  color: white;
  color: white;
  padding: 14px 20px;
  padding: 14px 20px;
  margin: 8px 0;
  margin: 8px 0;
  border: none;
  border: none;
  cursor: pointer;
  cursor: pointer;
  width: 100%;
  width: 100%;
}
}
	button:hover {
button:hover {
  opacity: 0.8;
  opacity: 0.8;
}
}
	.cancelbtn {
.cancelbtn {
  width: auto;
  width: auto;
  padding: 10px 18px;
  padding: 10px 18px;  
  background-color: #f44336;
  background-color: #f44336;
}
}
	.imgcontainer {
.imgcontainer {
  text-align: center;
  text-align: center;
  margin: 24px 0 12px 0;
  margin: 24px 0 12px 0;
}
}
	img.avatar {
img.avatar {
  width: 40%;
  width: 40%;
  border-radius: 50%;
  border-radius: 50%;
}
}
	.container {
.container {
  padding: 16px;
  padding: 16px;
}
}
	span.psw {
span.psw {
  float: right;
  float: right;
  padding-top: 16px;
  padding-top; 16px;
}
}
	/* Change styles for span and cancel button on extra small screens */
/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
@media screen and (max-width: 300px) {
  span.psw {
  span.psw {
     display: block;
     display: block;
     float: none;
     float: none;
  }
  }
  .cancelbtn {
  .cancelbtn {
     width: 100%;
     width: 100%;
  }
  }
}
}
</style>
</style>
</head>
</head>
<body>
<body>
	<h2>Login Form</h2>
<h2>Login Form</h2>
	<form action="/action_page.php" method="post">
<form action="/action_page.php" method="post">
  <div class="imgcontainer">
  <div class="imgcontainer">
    <img src="img_avatar2.png" alt="Avatar" class="avatar">
    <img src="img_avatar2.png" alt="Avatar" class="avatar">
  </div>
  </div>
	  <div class="container">
  <div class="container">
    <label for="uname"><b>Username</b></label>
    <label for="uname"><b>Username</b></label>
    <input type="text" placeholder="Enter Username" name="uname" required>
    <input type="text" placeholder="Enter Username" name="uname" required>
    <label for="psw"><b>Password</b></label>
    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" name="psw" required>
    <input type="password" placeholder="Enter Password" name="psw" required>    
    <button type="submit">Login</button>
    <button type="submit">Login</button>
    <label>
    <label>
      <input type="checkbox" checked="checked" name="remember"> Remember me
      <input type="checkbox" checked="checked" name="remember"> Remember me
    </label>
    </label>
  </div>
  </div>
	  <div class="container" style="background-color:#f1f1f1">
  <div class="container" style="background-color:#f1f1f1">
    <button type="button" class="cancelbtn">Cancel</button>
    <button type="submit" class="cancelbtn">Cancel</button>
    <span class="psw">Forgot <a href="#">password?</a></span>
    <span class="psw">Forgot <a href="#">password?</a></span>
  </div>
  </div>
</form>
</form>
	</body>
</body>
</html>
</html>
	

One thing I gain from this type of re-writings is that, typing the same thing over and over again sort of gets codes sink into my subconscious. Helps to memorise the codes.

Ok. So now you know a little about me.

As you can see, I always start on somebody else's skeleton, be it from a tutorial forum or a tutorial site or php manual.

I have completed 3 websites, so to speak, in that way. 2 days ago I thought, I been doing this for 3yrs now. Let's test and see how well I can code without working on somebody else's skeleton. No copy-pasting from forums or tutorial sites or php manual.

And so, look what I did. I coded all the following from my own memory. let me know how well I did. That repetition of lines re-writing has done me some good to memorise codes.

I did make 2 mistakes. Note the comments in the code. You will notice "MY CODE ..." and then a correction "WHAT IT SHOULD BE ...". Compare the 2 and see how close or far away I was from the correction. And then give me score from 1-10 (where 10 is best) how well I did as a home study middle aged guy. Hard learning things at middle age. I think, if I had toild you I started learning a month ago then you'd give 9/10 but because it's been 3 yrs, you'll give 1/9 or 0. Just bear in mind it's not easy to learn things at middle age and remember them without forgetting. I learn fast but forget double fast. Lol!

One thing though. My codes are not working. They do not INSERT data into db nor extract & display data from db. What is wrong ?

TEST NUMBER 1:

On this one, I first tried displaying data rows from mysql using mysqli_stmt_get_result(). That failed and so I tried with mysqli_stmt_bind_result() afterwards and so bear that in mind and don't ask me why I used both instead of one.

Clicking the "search" button gives no response. Nothing happens on page. I did search for a ketywords that exist in each mysql tbl columns.

	<?php
include('error_reporting.php');
require('conn.php');
//require('search_form.php');
?>
	<form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="keywords">Keywords:*</label>
<input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required>
<br>
<label for="search_column">Search in ... ?</label>
<select name="search_column" id="search_column">
<option value="page_url">Page Url</option>
<option value="link_anchor_text">Link Anchor Text</option>
<option value="page_description">Page Description</option>
<option value="keyphrase">Keyphrase</option>
<option value="keywords">Keywords</option>
</select>
<br>
<label for="tos_agreement">Agree to TOS or not ? *</label>
<select name="tos_agreement" id="tos_agreement" required>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
<input type="button" name="search_links" id="search_links" value="Search Links!">
<br>
<input type="reset">
<br>
</form>
	<?php
	if($_SERVER['REQUEST_METHOD'] === 'POST')
{
    if(ISSET($_POST['search_links']))
    {
        $_POST['page_url'];
        $_POST['link_anchor_text'];
        $_POST['page_description'];
        $_POST['keyphrase'];
        $_POST['keywords'];
        
        //I WROTE 2 QUERIES HERE AS I WASN'T SURE HOW IT SHOULD BE. FINALLY, STUCK TO THE LATTER. HOWEVER, ON TESTS NONE OF THEM WORK!
        //QUERY 1. $query = "SELECT FROM links (page_url,link_anchor_text,page_description,keyphrases,keywords) WHERE keywords = ?";
        //QUERY 2...
        $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE page_url = ?, link_anchor_text = ?, page_description = ?, keyphrases = ?, keywords = ?";
	        $stmt = mysqli_stmt_init($conn);
	        if(mysqli_stmt_prepare($stmt,$query))
        {
            mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrase'],$_POST['keywords']);
            
            //WRONG: FORGOT TO ADD "$result = " ...
            //mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords);
            
            //CORRECTION: WHAT IT SHOULD BE ...
            $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords);
            //mysqli_stmt_execute($stmt);WRONG! THIS LINE SHOULDN'T EXIST UNLESS IT'S mysqli_stmt_get_result().
            
            mysqli_stmt_fetch($stmt);
            
            //WASN'T SURE WHICH OF THE 3 FOLLOWING LINES ARE CORRECT REGARDING THE WHILE LOOP. FINALLY, STUCK TO THE 1ST LINE ...
            //1)...
            while(mysqli_stmt_fetch($stmt))
            //2)...
            //while(mysqli_fetch_array($stmt,mysqli_assoc))
            //3)...
            //while(mysqli_fetch($stmt))
            {
                echo "url"; echo "<br>";
                echo "anchor_text"; echo "<br>";
                echo "description"; echo "<br>";
                echo "keyphrases"; echo "<br>";
                echo "keywords"; echo "<br>";
                echo "|";
                echo "<br>";
            }
            
            mysqli_stmt_close($stmt);//CORRECTION: THIS SHOULD BE OUTSIDE THE "WHILE LOOP"
            mysqli_close($conn);//CORRECTION: THIS SHOULD BE OUTSIDE "IF"
        }
        else
        {
            echo "1. QUERY failed!";
        }
	        if(mysqli_stmt_prepare($stmt,$query))
        {
            mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']);
            mysqli_stmt_execute($stmt);
            
            //CORRECTION: FORGOT TO ADD "$result = "
            $result = mysqli_stmt_get_result($stmt);
            
            /* MY CODE
            WRONG! TRIED ECGHOING THE ARRAY "$row[]"!
            while($row = mysqli_fetch_array($result,mysqli_assoc))
            {
                echo $row['page_url']; echo "<br>";
                echo $row['link_anchor_text']; echo "<br>";
                echo $row['page_description']; echo "<br>";
                echo $row['keyphrases']; echo "<br>";
                echo $row['keywords']; echo "<br>";
                echo "|";
                echo "<br>";
            }
            */
            //CORRECTION: HOW IT SHOULD BE:
            //$VARIABLE SHOULD BE ECHOED. NOT THE ARRAY $row[]
            while($row = mysqli_fetch_array($result,mysqli_assoc))
            {
                $page_url = $row['page_url']; echo $page_url; echo "<br>";
                $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>";
                $page_description = $row['page_description']; echo $page_description; echo "<br>";
                $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>";
                $keywords = $row['keywords']; echo $keywords; echo "<br>";
                echo "|";
                echo "<br>";
            }
            
            mysqli_stmt_close($stmt);
            mysqli_close($conn);
        }
        else
        {
            die("2. QUERY failed!");
        }
    }
}
	
?>
	

 

TEST NUMBER 2:

On this one, clicking the "submit links" button gives no response atall!.

	<?php
include('error_reporting.php');
require('conn.php');
//equire('link_submission_form.php');
?>
	<form name = "submit_link" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="domain">Domain:</label>
<input type="text" name="domain" id="domain" placeholder="Input Domain">
<br>
<label for="domain_email">Domain Email:</label>
<input type="email" name="domain_email" id="domain_email" placeholder="Input Domain Email">
<br>
<label for="url">Url:</label>
<input type="url" name="url" id="url" placeholder="Input Url">
<br>
<label for="link_anchor_text">Link Anchor Text:</label>
<input type="text" name="link_anchor_text" id="link_anchor_text" placeholder="Input Link Anchor Text">
<br>
<textarea rows="10" cols="20">Page Description</textarea>
<br>
<label for="keywords">Keywords:</label>
<input type="text" name="keywords" id="keywords" placeholder="Input Keywords related to Page">
<br>
<label for="tos_agreement">Agree to TOS or not ?</label>
<select name="tos_agreement" id="tos_agreement">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<br>
<input type="button" name="submit_link" id="submit_link" value="Submit Link!">
<br>
<input type="reset">
<br>
</form>
	<?php
	if($_SERVER['REQUEST_METHOD'] === 'POST')
{
    if(ISSET($_POST['submit_link']))
    {
        $query = "INSERT into links (domain,domain_email,url,link_anchor_text,page_description,keywords) VALUES ?,?,?,?,?,?";
	        $stmt = mysqli_stmt_init($conn);
	        if(mysqli_stmt_prepare($stmt,$query))
        {
            mysqli_stmt_bind_param($stmt,'ssssss',$_POST['domain'],$_POST['domain_email'],$_POST['url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keywords']);
            
            mysqli_stmt_close($stmt);
            mysqli_close($conn);
        }
        else
        {
            die("INSERT failed!");
        }
    }
}
	
?>
	

What is wrong ? Why both codes don't work ?

 

Edited by 2020
Link to comment
https://forums.phpfreaks.com/topic/311083-rate-my-php-studied-work/
Share on other sites

@2020, my long lost twin 😀

It sounds like you're just like me, but quite a bit more advanced than what I know.

I learned PHP code back in the late 90's... right after I learned how to fix people's broken Sony Walkmans. I'm still good at both: 90's PHP code, and fixing broken walkmans :-)

Debugging code is the fun part. Just make sure you have ALL error reporting turned on, both PHP and mySQL, then start at the top few lines and comment everything out below and keep echoing stuff. When you uncomment the next block of code and you get errors, or a blank page, then that's where your first error is.

This is a no-no, by the way: <?php echo $_SERVER['PHP_SELF']; ?>" (injection issues)

And for your require('conn.php'), at least keep your conn.php up one level above public_html, like this:  require("../conn.php");

And for housekeeping sake, I wouldn't have my form named the same as my button (both named "submit_link").

What the heck is mysqli_stmt_init.... I gotta look that one up. I'll learn something new today.

Edited by StevenOliver
  • Haha 1
On 7/14/2020 at 6:54 PM, Barand said:

Yeah, must be tough. I was only in my 50s when I started learning PHP.

And, I am over 40 now. Guess if mid 40's or early or late. :)

I learn fast and forget triple fast! That is why you will be teaching me the same stuff over and over again on different threads of mine. Plus, i got high cholesteral, high blood pressure, blood clot issue and gull bludder issue. And a whole lot of others but these ones are troubling me the most. Always got headache. Right now sitting infront of my pc under a fan, wetting my body with wet cloth to remain cool. Very hot.

Not well. Shouldn't discuss private stuffs. But hey, not that I'm flashing my id or contact details!

If your body don't feel good nor your head, especially at mid-age, or worst at old age, then you become a little "thick in the head" or 'dense" as the yanks would put it (no offense to USA people here!). ;)

And, you can forget about managing to stick to plans to carry-out your studying or working plans that you have for the next day. I always make plans but can't be punctual. Atall. Let's see if I can finish sorting the issues I am having now here without getting a headache and quitting for the day to have coffee. ;)

Have coffee when you get a headache. Tea, capuccino, etc. doesn't really help. And chew garlic! ;) ThatEven though I'm a Brit like you. Currently in Asia. Long holiday. And it's "bleeming hot here" as we Brits would put it! helps rid the cholesteral and headache or blood pressure a little!

Anyway, I won't say anymore or people like Benanamen would be complaining this is a programming forum. And Mac Guyver will ban me. ;)

 

Edited by 2020
8 hours ago, StevenOliver said:

@2020, my long lost twin 😀

It sounds like you're just like me, but quite a bit more advanced than what I know.

I learned PHP code back in the late 90's... right after I learned how to fix people's broken Sony Walkmans. I'm still good at both: 90's PHP code, and fixing broken walkmans 🙂

Debugging code is the fun part. Just make sure you have ALL error reporting turned on, both PHP and mySQL, then start at the top few lines and comment everything out below and keep echoing stuff. When you uncomment the next block of code and you get errors, or a blank page, then that's where your first error is.

This is a no-no, by the way: <?php echo $_SERVER['PHP_SELF']; ?>" (injection issues)

And for your require('conn.php'), at least keep your conn.php up one level above public_html, like this:  require("../conn.php");

And for housekeeping sake, I wouldn't have my form named the same as my button (both named "submit_link").

What the heck is mysqli_stmt_init.... I gotta look that one up. I'll learn something new today.

Again writing from memory and I have a bad memory ...

You want to knwo what mysqli_stmt_init() is ?

Forget it as it's a long version of mysqli prepared statement. i first learnt the shorter way and now sticking to the longer way.

Short way was something like this ...

	$conn = //Mysql Connection details.
	$query =// Mysql Query.
	mysqli_prepared($conn,$query);
	mysqli_bind_param($conn,'ss',$_POST[first_name'],$_POST[surname']);
	mysqli_stmt_execute($conn,$query);
	

 

Long version ...

	$conn = //Mysql Connection details.
	$query =// Mysql Query.
	$stmt = mysli_stmt_init($conn);
	mysqli_stmt_prepared($stmt,$query);
	mysqli_stmt_bind_param($stmt,'ss',$_POST[first_name'],$_POST[surname']);
	mysqli_stmt_execute($stmt,$query);
	

 

Compare the 2. Look at the 1st params of each line. On the short version it is "$conn".

On the long version it is "$stmt" which actually points to "$conn" though the "mysqli_stmt_init($conn)" function.

So, why am I sticking to the long version ? Have you noticed the short version doesn't have "stmt" on the 2 functions ?

	mysqli_prepared($conn,$query);
	mysqli_bind_param($conn,'ss',$_POST[first_name'],$_POST[surname']);
	

I don't feel safe without the "stmt" as it feels sort of unprepared statement. Yeah, I know stupid reason.

Hence, sticking to the long version:

	mysqli_stmt_prepared($stmt,$query);
	mysqli_stmt_bind_param($stmt,'ss',$_POST[first_name'],$_POST[surname']);
	

 

Remember, don't take my word for it and do your own research as I just wrote the 2 above samples from memory and like I mentioned earlier I am not fit in the head. Sort of. ;)

 

I am starting to like you. You give me responses. Stick with me. But hold your breath and grab some patience as I can be really annoying when I forget things and ask the same again on another thread of mine. :D

 

Edited by 2020
8 hours ago, StevenOliver said:

@2020, my long lost twin 😀

It sounds like you're just like me, but quite a bit more advanced than what I know.

I learned PHP code back in the late 90's... right after I learned how to fix people's broken Sony Walkmans. I'm still good at both: 90's PHP code, and fixing broken walkmans 🙂

Debugging code is the fun part. Just make sure you have ALL error reporting turned on, both PHP and mySQL, then start at the top few lines and comment everything out below and keep echoing stuff. When you uncomment the next block of code and you get errors, or a blank page, then that's where your first error is.

This is a no-no, by the way: <?php echo $_SERVER['PHP_SELF']; ?>" (injection issues)

And for your require('conn.php'), at least keep your conn.php up one level above public_html, like this:  require("../conn.php");

And for housekeeping sake, I wouldn't have my form named the same as my button (both named "submit_link").

What the heck is mysqli_stmt_init.... I gotta look that one up. I'll learn something new today.

You know what. Ignore my previous post as the short version prepared statement sample is in full error. Sorry!

>>This is a no-no, by the way: <?php echo $_SERVER['PHP_SELF']; ?>

Oh! How so ? Care to show an example how injection will take place if I code like that ?

Here is tutorial for you to learn the long version I was talking about using mysqli_stmt_init():

https://www.w3schools.com/php/func_mysqli_stmt_init.asp

And here is the short version not using the mysqli_stmt_init():

https://www.php.net/manual/en/mysqli.prepare.php

 

Note on the long version it is:

mysqli_stmt_prepare();

While in short version it is:

mysqli_prepare().

 

Note also that, on the short version, mysqli_prepare(), the 1s param is "$conn" or "$link" (connection to mysql), while on the long version mysqli_stmt_prepare(), 1st param is $stmt which points to $conn anyway. Like so:

	$stmt = mysqli_stmt_init($conn);
	

Hence, I call this last one "long version".

 

Long Version sample:

	// Create a prepared statement
$stmt = mysqli_stmt_init($con);

if (mysqli_stmt_prepare($stmt, "SELECT District FROM City WHERE Name=?")) {
  // Bind parameters
  mysqli_stmt_bind_param($stmt, "s", $city);

  // Execute query
  mysqli_stmt_execute($stmt);

  // Bind result variables
  mysqli_stmt_bind_result($stmt, $district);

  // Fetch value
  mysqli_stmt_fetch($stmt);
	

 

Short version sample:

	if ($stmt = mysqli_prepare($link, "SELECT District FROM City WHERE Name=?")) {

    /* bind parameters for markers */
    mysqli_stmt_bind_param($stmt, "s", $city);

    /* execute query */
    mysqli_stmt_execute($stmt);

    /* bind result variables */
    mysqli_stmt_bind_result($stmt, $district);

    /* fetch value */
    mysqli_stmt_fetch($stmt);
	

Edited by 2020
42 minutes ago, 2020 said:

>>This is a no-no, by the way: <?php echo $_SERVER['PHP_SELF']; ?>

Oh! How so ? Care to show an example how injection will take place if I code like that ?

Google is my friend: https://stackoverflow.com/questions/6080022/php-self-and-xss

 

44 minutes ago, 2020 said:

Here is tutorial for you to learn the long version I was talking about using mysqli_stmt_init():

I read about that last night, very interesting. I also read this article.

Whenever I see two or more ways to do something, I'll google search using "vs" as a search term. For example I'll type into google:
mysqli_stmt_init vs
...and then I get to read articles where people argue about which way is best.

Another thing I do (for fun) is speedtest my whole PHP page ($startime at beginning of page, $endtime at bottom of page), and figure out where the slow points are. I remember spending a whole week getting my page load time from 885ms down to 665ms. That was exciting. And, yes, from this you can infer that I don't do real PHP work, I just like learning and messing with PHP.

Regarding mySQLi, Barand is the forum expert here.... (his code is a work of art; he writes code that even the PHP inventors haven't invented yet), and he uses PDO. I'd like to learn PDO. PDO does seem to benchmark a tad bit slower, but it looks way cooler! One of these days....

  • Like 1

@StevenOliver,

 

Here you go. Without all the comments you asked for.

Why is not this working ?

	<?php
//include('error_reporting.php');
ini_set('error_reporting','E_ALL');//error_reporting(E_ALL);
ini_set('display_errors','1');
ini_set('display_startup_errors','1');
require('conn.php');
?>
	<form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="keywords">Keywords:*</label>
<input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required>
<br>
<label for="search_column">Search in ... ?</label>
<select name="search_column" id="search_column">
<option value="page_url">Page Url</option>
<option value="link_anchor_text">Link Anchor Text</option>
<option value="page_description">Page Description</option>
<option value="keyphrase">Keyphrase</option>
<option value="keywords">Keywords</option>
</select>
<br>
<label for="tos_agreement">Agree to TOS or not ? *</label>
<select name="tos_agreement" id="tos_agreement" required>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br>
<input type="button" name="search_links" id="search_links" value="Search Links!">
<br>
<input type="reset">
<br>
</form>
	<?php
	if($_SERVER['REQUEST_METHOD'] === 'POST')
{
    if(ISSET($_POST['search_links']))
    {
        $_POST['page_url'];
        $_POST['link_anchor_text'];
        $_POST['page_description'];
        $_POST['keyphrase'];
        $_POST['keywords'];
        
        $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE page_url = ?, link_anchor_text = ?, page_description = ?, keyphrases = ?, keywords = ?";
	        $stmt = mysqli_stmt_init($conn);
	        if(mysqli_stmt_prepare($stmt,$query))
        {
            mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrase'],$_POST['keywords']);
            
            $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords);
            mysqli_stmt_execute($stmt);
            
            mysqli_stmt_fetch($stmt);
            
            while(mysqli_stmt_fetch($stmt))
            {
                echo "url"; echo "<br>";
                echo "anchor_text"; echo "<br>";
                echo "description"; echo "<br>";
                echo "keyphrases"; echo "<br>";
                echo "keywords"; echo "<br>";
                echo "|";
                echo "<br>";
            }
            
            mysqli_stmt_close($stmt);
            mysqli_close($conn);
        }
        else
        {
            echo "1. QUERY failed!";
        }
	        if(mysqli_stmt_prepare($stmt,$query))
        {
            mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']);
            mysqli_stmt_execute($stmt);
            
            $result = mysqli_stmt_get_result($stmt);
            
            while($row = mysqli_fetch_array($result,mysqli_assoc))
            {
                $page_url = $row['page_url']; echo $page_url; echo "<br>";
                $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>";
                $page_description = $row['page_description']; echo $page_description; echo "<br>";
                $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>";
                $keywords = $row['keywords']; echo $keywords; echo "<br>";
                echo "|";
                echo "<br>";
            }
            
            mysqli_stmt_close($stmt);
            mysqli_close($conn);
        }
        else
        {
            die("2. QUERY failed!");
        }
    }
}
	
?>
	

25 minutes ago, StevenOliver said:

Google is my friend: https://stackoverflow.com/questions/6080022/php-self-and-xss

 

I read about that last night, very interesting. I also read this article.

Whenever I see two or more ways to do something, I'll google search using "vs" as a search term. For example I'll type into google:
mysqli_stmt_init vs
...and then I get to read articles where people argue about which way is best.

Another thing I do (for fun) is speedtest my whole PHP page ($startime at beginning of page, $endtime at bottom of page), and figure out where the slow points are. I remember spending a whole week getting my page load time from 885ms down to 665ms. That was exciting. And, yes, from this you can infer that I don't do real PHP work, I just like learning and messing with PHP.

Regarding mySQLi, Barand is the forum expert here.... (his code is a work of art; he writes code that even the PHP inventors haven't invented yet), and he uses PDO. I'd like to learn PDO. PDO does seem to benchmark a tad bit slower, but it looks way cooler! One of these days....

You don't know pdo yet ? We're in the same boat. We can start a race to see who learns faster! Lol!

Stick with me, I put a project on hold, you can check it out once the current project is complete. I think you will enjoy it as it seems we sort of think alike. As I too mess about with php to experiment and that project I put on hold is just exactly that.

Edited by 2020

@2020, good, you have PHP error reporting turned on.... but where is your mySQL error reporting? Just yesterday there is a whole important thread here on this (I think if you implement it, you'll find what's going wrong):

p.s. Okay, let's do a PDO race. But I should be given a head start, considering my old age 😀

Edited by StevenOliver
  • Like 1
6 minutes ago, StevenOliver said:

@2020, good, you have PHP error reporting turned on.... but where is your mySQL error reporting? Just yesterday there is a whole important thread here on this (I think if you implement it, you'll find what's going wrong):

 

Thanks for the stackoverflow.com link. learnt something. When I come across a malfunction problem, i will just inistialise it mysqli_stmt_init() and problem should vanish!

 

As for my own thread! I guess I haven't visited lately! Running there now.

One question: If I come across a good project idea, would you like to work together just for the fun of it ? Experimenting, fiddling, messing with php etc. ? I'll probably do most of the work (structure), you can deal with the security parts as you're better at that compared to me. I think best I PM you when I thinkup any unique or simple good ideas for you to review the ideas. I don't start on any project to build a website just for furn of it. My motto: It should be unique & must have viral money making & viral traffic building features. Else, not my worth while. :)

Wanna get google, youtube & facebook stand on their 2 feet shivering when I walk their paths. Lol!

If you can't kill them (big guys), atleast try maiming them before they kill you!

Edited by 2020
1 hour ago, StevenOliver said:

@2020, good, you have PHP error reporting turned on.... but where is your mySQL error reporting? Just yesterday there is a whole important thread here on this (I think if you implement it, you'll find what's going wrong):

p.s. Okay, let's do a PDO race. But I should be given a head start, considering my old age 😀

Ok. But only after I have finished my current project. Then I go for pdo over mysqli.
The sooner I sort the current messes out the sooner I finish this simple project.

My stumbling blocks are in this thread plus this:

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.