/    Sign up×
Community /Pin to ProfileBookmark

Why No Result Displayed From DB ?

Folks,

This is starting to get on my nerves now.
What on earth do you think is wrong with my code that when I click the SEARCH button I get error number:
**Error: . Error: 0.**

I added 2 buttons coding it differently. To test both buttons which works at all times and which doesn’t and so bear this in mind and don’t ask why I got 2 buttons.
I searched for the keyword “heman”. The ‘links’ tbl has a column “keywords” and it has the first entry in that column “heman”. The 2nd entry is “she-ra”.
Typing “heman” in the form shows no result. Nor “she-ra” shows any result.
Notice in the comments, i got my QUESTIONS in CAPITALS. I’d appreciate their answers.

Thanks!

[code]
<?php
require ‘error_reporting.php’;
require ‘conn.php’;

if($_SERVER[‘REQUEST_METHOD’] === ‘GET’)
{
if(ISSET($_GET[‘search’]))//THERE WILL BE MORE THAN ONE BUTTON ON THIS PAGE. HENCE THIS LINE.
{
if(ISSET($_GET[‘keywords’]))
{
$keywords = $_GET[‘keywords’];
}

$query = “SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ?”;

$stmt = mysqli_stmt_init($conn);

if(mysqli_stmt_prepare($stmt,$query))
{
mysqli_stmt_bind_param($stmt,’s’,$keywords);


//1ST SET OUT OF 2 SETS REGARDING mysqli_stmt_execute. QA. WHICH SET TO KEEP ?
if(mysqli_stmt_execute($stmt) === FALSE)
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}

//2ND SET OUT OF 2 SETS REGARDING mysqli_stmt_execute. QA. WHICH SET TO KEEP ?
$stmt_execute = mysqli_stmt_execute($stmt);
if($stmt_execute === FALSE)
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}



//1ST SET OUT OF 2 SETS REGARDING mysqli_stmt_bind_result. QB. WHICH SET TO KEEP ?
if($bind_result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords)); //SHOULD I KEEP THIS IF OR THE IF BEFORE THIS ONE ?
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}

//2ND SET OUT OF 2 SETS REGARDING mysqli_stmt_bind_result. QB. WHICH SET TO KEEP ?
$bind_result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords);
if($bind_result === FALSE) //Q7. SHOULD I KEEP THIS IF OR THE NEXT IF AFTER THIS ONE ?
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}



//1ST SET OUT OF 2 SETS REGARDING mysqli_stmt_fetch. QC. WHICH SET TO KEEP ?
if($stmt_fetch = mysqli_stmt_fetch($stmt)) //Q11. SHOULD I KEEP THIS IF OR THE IF THAT COMES BEFORE THIS IF ?
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}

//2ND SET OUT OF 2 SETS REGARDING mysqli_stmt_fetch. QC. WHICH SET TO KEEP ?
$stmt_fetch = mysqli_stmt_fetch($stmt);
if($stmt_fetch === FALSE) //Q11. SHOULD I KEEP THIS IF OR THE IF THAT COMES AFTER THIS IF ?
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}



while(mysqli_stmt_fetch($stmt))
{
//QD. IS IT OK TO ECHO OR SHOULD I PRINTF INSIDE THE WHILE LOOP HERE ? I SEE NO DIFFERENCE.
echo “$page_url”; echo “<br>”;
echo “$link_anchor_text”; echo “<br>”;
echo “$page_description”; echo “<br>”;
echo “$keyphrase”; echo “<br>”;
echo “$keywords”; echo “<br>”;
echo “|”;
echo “<br>”;
}
mysqli_stmt_close($stmt); //QE. 2 EXPERTS TELL ME NOT TO KEEP THIS LINE BUT TUTORIAL SITES SHOW ME TO KEEP IT. WHY TUTORIALS SHOW ME TO KEEP IT ? MANUAL ALSO SHOWS TO KEEP IT: https://www.php.net/manual/en/mysqli-stmt.bind-result.php
mysqli_close($conn); //QE. 2 EXPERTS TELL ME NOT TO KEEP THIS LINE BUT TUTORIAL SITES SHOW ME TO KEEP IT. WHY TUTORIALS SHOW ME TO KEEP IT ? MANUAL ALSO SHOWS TO KEEP IT: https://www.php.net/manual/en/mysqli-stmt.bind-result.php
}
else
{
die(“QUERY failed in Line 96!”);
}

$query = “SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ?”;

$stmt = mysqli_stmt_init($conn);

if(mysqli_stmt_prepare($stmt,$query))
{
mysqli_stmt_bind_param($stmt,’s’,$keywords);

$stmt_execution = mysqli_stmt_execute($stmt);
if($stmt_execution === FALSE)
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}

$get_result = mysqli_stmt_get_result($stmt);

if($get_result === FALSE)
{
printf(“Error: %s.n”, mysqli_stmt_error($stmt));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt));
die;
}

while($row = mysqli_fetch_array($get_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(“QUERY failed in line 139!”);
}
}
}

?>

<form name = “search” method = “GET”>
<label for=”keywords”>Keywords:*</label>
<input type=”text” name=”keywords” id=”keywords” placeholder=”Input Keywords” required>
<br>
<button name=search value=” “>Search</button><br>
<button type=”submit” name=”search” value=”search”>Search</button>
<br>
<input type=”reset”>
<br>
</form>
[/code]

What is wrong ? Beats me! Beats you too ?

to post a comment
PHP

28 Comments(s)

Copy linkTweet thisAlerts:
@sibertJul 30.2020 — "keywords" indicates multiple keyword search. True?
Copy linkTweet thisAlerts:
@NogDogJul 30.2020 — Start by putting something into those different printf() statements so you can tell exactly which one you triggered.
Copy linkTweet thisAlerts:
@daveyerwinJul 30.2020 — @developer_web#1621506 said ...

I told the doctor it hurts when I do this

``<i>
</i>$stmt_fetch = mysqli_stmt_fetch($stmt);
if($stmt_fetch === FALSE) //Q11. SHOULD I KEEP THIS IF OR THE IF THAT COMES AFTER THIS IF ?
{
printf("Error: %s.n", mysqli_stmt_error($stmt));
printf("Error: %d.n", mysqli_stmt_errno($stmt));
die;
} <i>
</i>
`</CODE>
The doctor said ...<br/>
Don't do that !

<CODE>
`<i>
</i>
&lt;?
//require 'error_reporting.php';
//require 'conn.php';
$servername = "localhost";
$username = "u308145272_daVey";
$password = "!?Dav!?2468!?";
$dbname = "u308145272_daBase";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}else{
printf("Connect suckedseed&lt;br&gt;");
}
$sql = "CREATE TABLE IF NOT EXISTS TestE (
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
$result=mysqli_query($conn, $sql);
echo mysqli_errno($conn)."&lt;br&gt;";
$stmt = mysqli_stmt_init($conn);

if(ISSET($_GET['keywords'])){
$keywords = $_GET['keywords'];
if(array_key_exists('search1',$_GET)){
echo $keywords."&lt;br&gt;";
$query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM TestE WHERE keywords = ?";
if(mysqli_stmt_prepare($stmt,$query)) echo "prepare aok&lt;br&gt;";
mysqli_stmt_bind_param($stmt,'s',$keywords);
if(mysqli_stmt_execute($stmt) === FALSE){
printf("Error: %s.n", mysqli_stmt_error($stmt));
printf("Error: %d.n", mysqli_stmt_errno($stmt));
die();
}
// $stmt_execute = mysqli_stmt_execute($stmt);
// if($stmt_execute === FALSE){
// printf("Error: %s.n", mysqli_stmt_error($stmt));
// printf("Error: %d.n", mysqli_stmt_errno($stmt));
// die;
// }
// if(!mysqli_stmt_execute($stmt)){
// printf("Error: %s.n", mysqli_stmt_error($stmt));
// printf("Error: %d.n", mysqli_stmt_errno($stmt));
// die;
// } all three ways are functionally equivalent !

if(!mysqli_stmt_bind_result(
$stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords)
){
printf("Error: %s.n", mysqli_stmt_error($stmt));
printf("Error: %d.n", mysqli_stmt_errno($stmt));
die();
}
while(mysqli_stmt_fetch($stmt)) {
echo "$page_url"; echo "&lt;br&gt;";
echo "$link_anchor_text"; echo "&lt;br&gt;";
echo "$page_description"; echo "&lt;br&gt;";
echo "$keyphrase"; echo "&lt;br&gt;";
echo "$keywords"; echo "&lt;br&gt;";
echo "|";
echo "&lt;br&gt;";
}
}


if(array_key_exists('search2',$_GET)){
echo $keywords."xxxxxx&lt;br&gt;";
$query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM TestE WHERE keywords = ?";
if(!mysqli_stmt_prepare($stmt,$query))die("UnPrepared");
if(!mysqli_stmt_bind_param($stmt,'s',$keywords))die("UnBound");
if(!mysqli_stmt_execute($stmt))die("UnExecuted");
if(!$result=mysqli_stmt_get_result($stmt))die("NotGot");
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
$page_url = $row['page_url']; echo $page_url; echo "&lt;br&gt;";
$link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "&lt;br&gt;";
$page_description = $row['page_description']; echo $page_description; echo "&lt;br&gt;";
$keyphrases = $row['keyphrases']; echo $keyphrases; echo "&lt;br&gt;";
$keywords = $row['keywords']; echo $keywords; echo "&lt;br&gt;";
echo "|";
echo "&lt;br&gt;";
}
}
}

if (array_key_exists('insert',$_GET)){
$data = $_GET[data];
echo var_dump($_GET[data])."&lt;br&gt;";
$sql ="insert into TestE values (?,?,?,?,?)";
if(mysqli_stmt_prepare($stmt,$sql)) echo "prepare ok"."&lt;br&gt;";
echo $data."&lt;br&gt;";
mysqli_stmt_bind_param($stmt, "sssss", $data[0], $data[1], $data[2], $data[3], $data[4]);
if(!mysqli_stmt_execute($stmt)){echo "exe Failed";}
}


?&gt;
&lt;form&gt;
page_url&lt;input name=data[]&gt;&lt;br&gt;
link_anchor_text&lt;input name=data[]&gt;&lt;br&gt;
page_description&lt;input name=data[]&gt;&lt;br&gt;
keyphrases&lt;input name=data[]&gt;&lt;br&gt;
keywords&lt;input name=data[]&gt;&lt;br&gt;
&lt;input type="reset"&gt;&lt;br&gt;
&lt;button name=insert&gt;send&lt;/button&gt;&lt;/form&gt;
&lt;form&gt;
&lt;label for="keywords"&gt;Keywords:*&lt;/label&gt;
&lt;input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required&gt;
&lt;br&gt;
&lt;button name=search2&gt;Search2&lt;/button&gt;&lt;br&gt;
&lt;button name=search1&gt;Search1&lt;/button&gt;&lt;br&gt;
&lt;input type="reset"&gt;
&lt;br&gt;
&lt;/form&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@daveyerwinJul 31.2020 — @DaveyErwin#1621532

there was a couple of typos

and some bad code

some bad logic

compare what I did

to your code
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621537

Last night, I switched from $_POST to $_GET and it's working. Someone pointed it out.

I see you using $_GET too. Thank you both! I am checking out your code now. I will bug you later as I do not understand a lot of intermediate stuffs in your code. But still thanks for it. Gonna learn something new after hassling you with tonnes of questions. Let me do a combing operation on your code. Then, I'm bugging you. Be prepared for a lot of questions that will seem silly as I am still not an intermediate.
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

<i>
</i>$sql = "CREATE TABLE IF NOT EXISTS TestE (
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
$result=mysqli_query($conn, $sql);
echo mysqli_errno($conn)."&lt;br&gt;";


You asked it to echo error. What if there is no error ? Then would it not show error that there is no error to echo ?

Should there not be an IF here to check if there is an error or not ?

<i>
</i>$sql = "CREATE TABLE IF NOT EXISTS TestE (
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
$result=mysqli_query($conn, $sql);
echo mysqli_errno($conn)."&lt;br&gt;";


Or Php 7 smart enough to automatically assume there is an IF there, even though you wrote it not, and it will only echo error if there is one otherwise it will dismiss the echo line. Right ?

echo mysqli_errno($conn)."<br>";
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532
<i>
</i>if(ISSET($_GET['keywords'])){
$keywords = $_GET['keywords'];
if(array_key_exists('search1',$_GET)){
echo $keywords."&lt;br&gt;";


I do not understand this line:

if(array_key_exists('search1',$_GET)){


What are you doing here ? Checking for 'search1' against what ?

Where did 'search1' come from ? What is it ? Typo ?

Or did you mean to do this ....

if(array_key_exists('search',$_GET)){

if so, what does that line mean ?

I guessing you are seeing if there is a param called 'search' in the url to make use of the $_GET['search'] here. Yes or not ?

Meaning, if url looks something like this:

domain.com/?search=keywords

then grab the value of:

search=

Else ignore it.

Right or wrong ?

So your short version:

if(array_key_exists('search',$_GET)){

is a substitute of my long version:

if(ISSET($_GET['search']))
{
$search=$_GET['search'];
}

Yes or no ?
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

Ok. Even the the 3 are same. Can you still rank according to preference giving the reasons to your rankings ?

if(mysqli_stmt_execute($stmt) === FALSE){
printf("Error: %s.n", mysqli_stmt_error($stmt));
printf("Error: %d.n", mysqli_stmt_errno($stmt));
die();
}
// $stmt_execute = mysqli_stmt_execute($stmt);
// if($stmt_execute === FALSE){
// printf("Error: %s.n", mysqli_stmt_error($stmt));
// printf("Error: %d.n", mysqli_stmt_errno($stmt));
// die;
// }
// if(!mysqli_stmt_execute($stmt)){
// printf("Error: %s.n", mysqli_stmt_error($stmt));
// printf("Error: %d.n", mysqli_stmt_errno($stmt));
// die;
// } all three ways are functionally equivalent !


That way, I can see if any option would spit error or not by malfunctioning on some occassions. Want to learn which occasions they would malfunction. in which environment.
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

I always have to printf the error ? No way to get mysqli to echo it ?

if (mysqli_connect_errno()) {
echo "Connect failed: " . mysqli_connect_error());

Is not the above the same as:

if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());


or maybe there is an advantage somewhere to use the printf ? I see tutorials use the printf here. I do not know why. Care to enlighten me ?
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

I really like this:

if(!mysqli_stmt_prepare($stmt,$query))die("UnPrepared");
if(!mysqli_stmt_bind_param($stmt,'s',$keywords))die("UnBound");
if(!mysqli_stmt_execute($stmt))die("UnExecuted");
if(!$result=mysqli_stmt_get_result($stmt))die("NotGot");
````

Your's shorter and neater than mine! Thanks!

But at StackOverFlow they keep telling me not to check manually if statement got prepared or not. If parameters got bound or not. If result got bound ot not. if result got executed or not. If result got fetched or not. I ask them then how am I supposed to know on which part of the code there is a problem if I don;t check each step!

This is not my question but they keep referring me to it:

https://stackoverflow.com/q/58808332/1839439

What you make out of all this ? Should I ignore their advice ? Or, will you now stick to them because you think they are correct ?

Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

Did you forget to check like this on this one:

if(!mysqli_stmt_fetch($stmt)) die("Fetching Failed!");
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

Qa.

You can check if the statement got prepared or not like so since mysql would show non-manual error if it failed:

if(mysqli_stmt_prepare($stmt,$query)) echo "prepare aok<br>";

Right ?

Qb.

However, I think NogDog or someone somewhere else told me you cannot check if it got bound or not because mysqli would show no errors even if it failed to get bound. Correct ? And so, no good checking like this:

if(mysqli_stmt_bind_param($stmt,'s',$keywords)) echo "Param Binding Failed!<br>";

Right ?

Qc.

But, you can check if the result got bound or not as mysqli would show (non-manual) error if it failed. Hence, worth checking like this:

if(!mysqli_stmt_bind_result(
$stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords)
){
printf("Error: %s.n", mysqli_stmt_error($stmt));
printf("Error: %d.n", mysqli_stmt_errno($stmt));
die();
}
````

Right ?


QD.

And you can check if results were gotten or not as mysqli would show non-manual errors if it failed.

if(!$result=mysqli_stmt_get_result($stmt))die("NotGot");

Right ?

QE. But what about stmt_fetch() ? Can you not check whether it got or not where if it did fail then mysqli would show error without us having to manually check for errors ?

while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))

Cannot the above be changed to any of these instead ?

if(!while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)))


if(while(!$row = mysqli_fetch_array($result,MYSQLI_ASSOC)))


if(while($row != mysqli_fetch_array($result,MYSQLI_ASSOC)))


if(while($row = !mysqli_fetch_array($result,MYSQLI_ASSOC)))


if(while($row < mysqli_fetch_array($result,MYSQLI_ASSOC)))
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621532

Sorry dave, but I was too busy in the background with another code when you explained things and so I didn't quite understand you about the data[] part on my other thread(s).



<form>
page_url<input name=data[]><br>
link_anchor_text<input name=data[]><br>
page_description<input name=data[]><br>
keyphrases<input name=data[]><br>
keywords<input name=data[]><br>
<input type="reset"><br>
<button name=insert>send</button></form>
<form>
<label for="keywords">Keywords:*</label>
<input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required>
<br>
<button name=search2>Search2</button><br>
<button name=search1>Search1</button><br>
<input type="reset">
<br>
</form>

On this one:

page_url<input name=data[]>

What exactly are you doing ?

I usually do it like this:

<input type = 'url' name=page_url>

What is the benefit of your way over mine ? Seems like you are doing some kind of auto naming of sort. Sounds interesting. So, if you don;t mind me properly askign you this time, what exactly are you doing here on that particular line ?
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621537

Tell me the bad code.

Tell me the bad logic.

So, I make same mistakes not again.

As for the typo, I know them now.
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621537

I have been recommended these links. Giving them to you incase they be handy.

After reading them, see if you need to update your code or not. As i need to learn from latest format that works without any errors.

https://stackoverflow.com/questions/60741213/how-can-i-get-an-unknown-username-given-an-id

https://stackoverflow.com/questions/13103419/error-when-using-mysqli-select-db-and-mysqli-connect

https://stackoverflow.com/questions/22857402/mysqli-statement-not-displaying-else-for-no-result/59554119#59554119

https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement

https://stackoverflow.com/questions/63174388/what-is-the-best-way-to-get-php-echo-errors-on-prepared-statements

if you ask me, these guys are StackOverFlow seem too much for me. they too advanced and don;t understand my low beginner level and give advice to me as if addressing a graduate. i like your advice as it is atleast intermediate level if not beginner.

Anyway, those link threads were not my questions. I just got told to check them out if I won;t let go of mysqli for a while for pdo.
Copy linkTweet thisAlerts:
@daveyerwinJul 31.2020 — ``<i>
</i>&lt;?
$servername = "localhost";
$username = "u308145272_daVey";
$password = "!?Dav!?2468!?";
$dbname = "u308145272_daBase";
$conn = mysqli_connect($servername, $username, $password, $dbname);

$sql = "CREATE TABLE IF NOT EXISTS TestE (
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
mysqli_query($conn, $sql);

if(ISSET($_GET['keywords'])){
$keywords = $_GET['keywords'];
$stmt = mysqli_stmt_init($conn);
$query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM TestE WHERE keywords = ?";
mysqli_stmt_prepare($stmt,$query);
mysqli_stmt_bind_param($stmt,'s',$keywords);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result(
$stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords);

while(mysqli_stmt_fetch($stmt)) {
echo "$page_url"; echo "&lt;br&gt;";
echo "$link_anchor_text"; echo "&lt;br&gt;";
echo "$page_description"; echo "&lt;br&gt;";
echo "$keyphrase"; echo "&lt;br&gt;";
echo "$keywords"; echo "&lt;br&gt;";
echo "|";
echo "&lt;br&gt;";
}
}

if(ISSET($_GET['data'])){
$data = $_GET[data];
$sql ="insert into TestE values (?,?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt,$sql);
mysqli_stmt_bind_param($stmt, "sssss", $data[0], $data[1], $data[2], $data[3], $data[4]);
mysqli_stmt_execute($stmt);
}

?&gt;
&lt;form&gt;
page_url&lt;input name=data[]&gt;&lt;br&gt;
link_anchor_text&lt;input name=data[]&gt;&lt;br&gt;
page_description&lt;input name=data[]&gt;&lt;br&gt;
keyphrases&lt;input name=data[]&gt;&lt;br&gt;
keywords&lt;input name=data[]&gt;&lt;br&gt;
&lt;input type="reset"&gt;&lt;br&gt;
&lt;button name=insert&gt;send&lt;/button&gt;&lt;/form&gt;
&lt;form&gt;
&lt;label for="keywords"&gt;Keywords:*&lt;/label&gt;
&lt;input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required&gt;
&lt;br&gt;
&lt;button&gt;Search&lt;/button&gt;&lt;br&gt;
&lt;input type="reset"&gt;
&lt;br&gt;
&lt;/form&gt;<i>

</i>
``
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621574

I am still confused about the whole data[]. And so, I having trouble understanding this:

if(ISSET($_GET['data'])){
$data = $_GET[data];
$sql ="insert into TestE values (?,?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt,$sql);
mysqli_stmt_bind_param($stmt, "sssss", $data[0], $data[1], $data[2], $data[3], $data[4]);
mysqli_stmt_execute($stmt);
}


How-about addressing my replies to you in my previous posts ? Then, I will understand what you are trying to achieve with your code.
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — I just been recommended these by stackoverflow.com folks. Listing them incase anyone weak here on mysqli.

https://phpdelusions.net/mysqli_examples/prepared_select

https://phpdelusions.net/mysqli/mysqli_connect

https://phpdelusions.net/articles/error_reporting

https://codereview.stackexchange.com/questions/234405/php-mysqli-connection-file/243749#243749

https://phpdelusions.net/pdo/mysqli_comparison

Even though I get help from there from time to time, i don;t feel comfortable with those folks over there. They are adv level and I don't always understand their language level. hence, I prefer DaveyErwin and NogDog and Sempervivum here.

Glancing at dave's code, I can understand 75% of it and it seems he understands my mind in what I intend to achieve and gives me code samples without asking. As for StackOverFlow, you can ask a hundred times and be lucky if they give you sample code even once!
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621574

See if you can convert your code to pagination so it shows results 10 per page. then once I learn your code, I can start memorising the lines and you can then test me. ;)
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621574

I got this error:

**Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in C:xampphtdocstestpagination.php on line 39**

Your code:

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$conn = mysqli_connect($servername, $username, $password, $dbname);

$sql = "CREATE TABLE IF NOT EXISTS TestE (
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
mysqli_query($conn, $sql);

if(ISSET($_GET['keywords'])){
$keywords = $_GET['keywords'];
$stmt = mysqli_stmt_init($conn);
$query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM TestE WHERE keywords = ?";
mysqli_stmt_prepare($stmt,$query);
mysqli_stmt_bind_param($stmt,'s',$keywords);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result(
$stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords);

while(mysqli_stmt_fetch($stmt)) {
echo "$page_url"; echo "<br>";
echo "$link_anchor_text"; echo "<br>";
echo "$page_description"; echo "<br>";
echo "$keyphrase"; echo "<br>";
echo "$keywords"; echo "<br>";
echo "|";
echo "<br>";
}
}

if(ISSET($_GET['data'])){
$data = $_GET[data];
$sql ="insert into TestE values (?,?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt,$sql);
mysqli_stmt_bind_param($stmt, "sssss", $data[0], $data[1], $data[2], $data[3], $data[4]);
mysqli_stmt_execute($stmt);
}

?>
<form>
page_url<input name=data[]><br>
link_anchor_text<input name=data[]><br>
page_description<input name=data[]><br>
keyphrases<input name=data[]><br>
keywords<input name=data[]><br>
<input type="reset"><br>
<button name=insert>send</button></form>
<form>
<label for="keywords">Keywords:*</label>
<input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required>
<br>
<button>Search</button><br>
<input type="reset">
<br>
</form>


I just modifed the db detail. And username & password. That is all.

Line 39: $data = $_GET[data];


UPDATE:

Working now. With this:

$data = $_GET[data];


How-about adding these 2 columns in the tbl ?

id, date_and_time

How to write code to do it ? Do you mind updating your code ?

Thanks!
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin#1621574

Howabout setting some cols as NOT NULL while others as NULL ?

And let's add id, date_and_time ?

And let's add one col to dump text and another col to dump img and another col to dump video. How to write the code to do all this ?

This is not right. I did my best ...

$sql = "CREATE TABLE IF NOT EXISTS TestE (
id(255),
date_&_time,
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @NogDog,

@Sempervivum,

If this creates tbl:


$sql = "CREATE TABLE IF NOT EXISTS TestE (
page_url VARCHAR(255),
link_anchor_text VARCHAR(255),
page_description VARCHAR(255),
keyphrases VARCHAR(255),
keywords VARCHAR(255))";
mysqli_query($conn, $sql);
````

Then how to write such text code to amend the tbl ? Like add a new column ? Delete a column ? Switch a NULL column to NOT NULL and vice versa ? Show us an example.

Thanks
Copy linkTweet thisAlerts:
@daveyerwinJul 31.2020 — @developer_web#1621577

> @developer_web#1621577 How-about addressing my replies to you in my previous posts ? Then, I will understand what you are trying to achieve with your code.

run the code

enter data

then

search for data
Copy linkTweet thisAlerts:
@daveyerwinJul 31.2020 — @developer_web#1621581

> @developer_web#1621581 Howabout setting some cols as NOT NULL while others as NULL ?

> And let's add id, date_and_time ?


CREATE TABLE Sample

(

sample_id int NOT NULL,

sample_name VARCHAR(20),

sample_ts TIMESTAMP

);
Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 — @DaveyErwin,

Check this link out. Then see if you can amend your code to be more efficient or not (shorter):

https://phpdelusions.net/mysqli/mysqli_connect

I am reading it now. It is doing my head in a little. But StackOverFlow guys suggest I amend my codes according to the links they gave me. (Pissing me off as the links are way over my head).

I am growling here, very grumpy.

https://www.webdeveloper.com/d/390816-error-reporting-the-right-safe-way

I need you to stick with me then with your help, I'll get over this hurdle they are making me go through!

Reading this part now ....

<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
require __DIR__.'/db_credentials.php';
$mysqli = new mysqli($host, $user, $pass, $db, $port);
$mysqli->set_charset($charset);
} catch (mysqli_sql_exception $e) {
throw new mysqli_sql_exception($e->getMessage(), $e->getCode());
} finally {
unset($host, $db, $user, $pass, $charset);
}

function prepared_query($mysqli, $sql, $params, $types = "")
{
$types = $types ?: str_repeat("s", count($params));
$stmt = $mysqli->prepare($sql);
$stmt->bind_param($types, ...$params);
$stmt->execute();
return $stmt;
}

On that link, I mean.

PS - Another link I came across on that above link ...

https://phpdelusions.net/mysqli/simple

Thanks!
Copy linkTweet thisAlerts:
@developer_webauthorAug 01.2020 — @DaveyErwin,

Not gonna give you orders but what did you make out of the links above ?
Copy linkTweet thisAlerts:
@developer_webauthorAug 01.2020 — @DaveyErwin#1621585

@DaveyErwin#1621574

Dave,

Don't mind me call you Dave or should I call you David ?

Anyway, now you kidnly gave me mysqli sample code.

Do you mind converting that to pdo ? That way, I can use your code as one of my learning steps and put an end to programmers whining about me not dumping mysqli and not getting into pdo.

  • 1. Simple INSERT.

  • 2. Simple SELECT.

  • 3. Simple UPDATE.

  • 4. Simple DELETE.

  • 5. Simple Pagination.


  • The above 5 samples should get any beginner on their way.

    I can always find tutorials on the first 4 but not that easy to find a simple code sample for number 4.

    But before you show any of these 5, first convert your above mysqli piece to pdo. If you ain't that busy and are willing. And, it's not too much on my part to ask. ;)

    Thanks
    Copy linkTweet thisAlerts:
    @daveyerwinAug 01.2020 — @developer_web#1621616

    on my drivers license it says Davey 😄

    I answer to any permutation there of

    sorry, I don't do PDO
    ×

    Success!

    Help @developer_web spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.23,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...