/    Sign up×
Community /Pin to ProfileBookmark

How To Fix So Chars “on” And “search=+” Not Appear On Url ?

Why Chars “On” And “search=+” Appears On My Url After Submitting GET Method Form ?

This my form:

<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
</head>
<body>
<div align=’center’>
<form method=”GET” action=”<?php echo $_SERVER[‘PHP_SELF’];?>?col=<?php echo “$col&search=$search&limit=$limit&page=1″;?>”>
<label for=”search”>Search</label>
<input type=”text” name=”search” id=”search” required>
<br>
<label for=”col”>Search Type</label>
<input type=”radio” name=”col” id=”keywords” required>Keywords
<input type=”radio” name=”col” id=”keyphrase” required>Keyphrase
<br>
<label for=”limit”>Limit</label>
<select name=”limit” id=”limit”>
<option value=””></option>
<option value=”1″>1</option>
<option value=”10″>10</option>
<option value=”50″>50</option>
<option value=”100″>100</option>
<option value=”500″>500</option>
<option value=”1000″>1000</option>
</select>
<br>
<button type=”submit” name=”search_links” id=”search_links” value=” “>Search Links</button>
<br>
<button type=”reset”>Reset</button><br>
<br>
<br>
</form>

After submission I need form to send user to:
http://localhost/test/pagination_2.php?search=$search&col=$col=limit=$limit&page=1

eg:
http://localhost/test/pagination_2.php?search=heman&col=keywords&limit=2&page=1

search= keywords go here
col= the mysql tbl column to query
limit= search result per page

Problem is, I get sent to:
http://localhost/test/pagination_2.php?search=heman&col=on&limit=&search_links=+

Note the “col=on”. There is no mysql tbl column called “on”, hence getting error:

>

Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘on = ?’ at line 1 in C:xampphtdocstestpagination_2.php:90 Stack trace: #0 C:xampphtdocstestpagination_2.php(90): mysqli_stmt_prepare(Object(mysqli_stmt), ‘SELECT COUNT(su…’) #1 {main} thrown in C:xampphtdocstestpagination_2.php on line 90

Q1. Why browser shows “col=on” and not “col=$col” (in this case “col=keywords”) ?

Q2. Also, why in url gets added: “search=+” ? How to rid it ?
My code:

““
<?php

if(ISSET($_SESSION[‘user_id’]))
{
$user_id = $_SESSION[‘user_id’];
$user_type = ‘member’;
}
elseif(ISSET($_COOKIE[‘guest’]))
{
$user_id = $_COOKIE[‘guest’];
$user_type = ‘guest’;
}
else
{
die(“Error 1: Invalid User!”);
}

if(ISSET($_GET[‘search’]) && is_string($_GET[‘search’]))
{
$search = $_GET[‘search’];
}
else
{
die(“Type your single Keyword or single Keyphrase!”);
}

if(ISSET($_GET[‘col’]) && is_string($_GET[‘col’]))//’col=search_type’. ‘search_type’ options: 1). Mysql Column:keywords; 2. Mysql Column:keyphrase.
{
$col = $_GET[‘col’];
}
else
{
echo “Select Checkbox!”;
die(“Select your search type to indicate whether you are searching for a single Keyword or a single Keyphrase!”);
}
““

On the form, I selected “keywords” as the “col” to be queried:

<input type=”radio” name=”col” id=”keywords” required>Keywords
<input type=”radio” name=”col” id=”keyphrase” required>Keyphrase

Q3. How to fix this following line to solve the issue ?

<form method=”GET” action=”<?php echo $_SERVER[‘PHP_SELF’];?>?col=<?php echo “$col&search=$search&limit=$limit&page=1″;?>”>

Q4. Need to add security in the url so no hacker can injection in url. Do I need to add urlencode in the above-mentioned code ?

NOTE:
This is part of pagination code where you keyword search in the database. Hence, need to use $_GET method to have params in the url.

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorOct 27.2020 — @Sempervivum

You may not know about Cookies but I suppose you do know about $_GET.
Copy linkTweet thisAlerts:
@developer_webauthorOct 27.2020 — @NogDog,

Any chance you can amend following to solve the 4 issues ?

<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>?col=<?php echo "$col&search=$search&limit=$limit&page=1";?>">

I give-up.

Never saw printf in such circumstance. Well, you're the printf expect so est take what you throw this way.
Copy linkTweet thisAlerts:
@NachfolgerOct 27.2020 — Do you know how HTML forms work with the method set to GET? I can recall DISTINCTLY you bringing up this exact issues in the months past.

Search through your plethora of posts and find the answer in your thread. I dare not repeat my answer from that thread because it obviously didn’t get read.
Copy linkTweet thisAlerts:
@pikachu88Oct 28.2020 — Thank you for sharing this good post, I am very impressed with your post, the information given is meticulous and easy to understand. I will follow your next post regularly. [shell shockers](https://shell-shockers.online)
Copy linkTweet thisAlerts:
@developer_webauthorOct 30.2020 — @Nachfolger#1624622

POST doesnt send params to url. GET does. I think you gonna say GET sends all values of form items into the url as params. So, if form has these IDs: name=nachfolger,age=35,gender=male, then GET method will dump "age=35,gender=male" into the url.

Q1.

Atleast explain to me where the col=on, tbl=on comes from in the url. Why the "on" ? What's it mean "on" ?

It should be:

col=$col

tbl=$tbl

col=keyword

($col=keyword)

tbl=links

(tbl=links)


Now, you gonna say to use POST method. But I can't do that as I need data (params) in the url.

Q2.

Do you suggest I switch to POST now ? In past I worked on a pagination where form used POST method. Just hate grabbing params with $_SESSIONs. $_GET seems easier. Do you get my point or not ?

Glad you chimed in without me having to bug you with an @NachFolger! (Now this is gonna trigger an alert and ring you here!).
Copy linkTweet thisAlerts:
@developer_webauthorOct 30.2020 — Folks,

After form submission url is:

http://localhost/test/pagination_2.php?search=heman&tbl=on&col=on&limit=&search_links=+

A.

I want removed:

search_links=+

B.

I want to change:

col=on

tbl=on

to:

col=$keywords

tbl=$links

col=keywords

tbl=links

html looks like this:

<label for="tbl">Query Type</label>
<input type="radio" name="tbl" id="keywords" required>Links
<input type="radio" name="tbl" id="keyphrases" required>Browsing History
<br>
<label for="col">Search Type</label>
<input type="radio" name="col" id="keywords" required>Keyword
<input type="radio" name="col" id="keyphrases" required>Keyphrase

Removing the "id=" or "name=" didn't work.




And so amended the submission button from:

<button type="submit" name="search_links" id="search_links" value=" ">Search Links</button>

to:

http://localhost/test/pagination_2.php?search=heman&tbl=on&col=on&limit=

Got what I want. Now form submits to:

http://localhost/test/pagination_2.php?search=heman&tbl=on&col=on&limit=

"&search_links=+" is no longer in url.

Now, show me how to get rid
Copy linkTweet thisAlerts:
@NachfolgerOct 30.2020 — > @developer_web#1624724 Atleast explain to me where the col=on, tbl=on comes from in the url. Why the "on" ? What's it mean "on" ?

I encourage you to look at the HTML docs on the radio element. The answer to your question will be contained there.
Copy linkTweet thisAlerts:
@developer_webauthorOct 30.2020 — @Nachfolger

Above post had errors on my radio button. Correction post:


Folks,

After form submission url is:

http://localhost/test/pagination_2.php?search=heman&tbl=on&col=on&limit=&search_links=+

A.

I want removed:

search_links=+

B.

I want to change:

col=on

tbl=on

to:

col=$keywords

tbl=$links

col=keywords

tbl=links

html looks like this:

<label for="tbl">Query Type</label>
<input type="radio" name="tbl" id="links" required>Links
<input type="radio" name="tbl" id="browsing_history" required>Browsing History
<br>
<label for="col">Search Type</label>
<input type="radio" name="col" id="keywords" required>Keyword
<input type="radio" name="col" id="keyphrases" required>Keyphrase

Removing the "id=" or "name=" didn't work. Note the "required" on the html. Due to it, cannot remove the "name=". Remoing it on your end and try submitting the form and see what happens.

Full form:

<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>?col=<?php echo "$col&search=$search&limit=$limit&page=1";?>">
<label for="search">Search</label>
<input type="text" name="search" id="search" required>
<br>
<label for="tbl">Query Type</label>
<input type="radio" name="tbl" id="links" required>Links
<input type="radio" name="tbl" id="browsing_history" required>Browsing History
<br>
<label for="col">Search Type</label>
<input type="radio" name="col" id="keywords" required>Keyword
<input type="radio" name="col" id="keyphrases" required>Keyphrase
<br>
<label for="limit">Limit</label>
<select name="limit" id="limit">
<option value=""></option>
<option value="1">1</option>
<option value="10">10</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
<br>
<button type="submit" id="search_links" value=" ">Search Links</button>
<br>
<button type="reset">Reset</button><br>
<br>
<br>
</form>
Copy linkTweet thisAlerts:
@developer_webauthorOct 30.2020 — @Nachfolger#1624727

Thanks for the hint. "value="" was missing on my radio buttons. Now, fixed:

<label for="tbl">Query Type</label>
<input type="radio" name="table" id="links" value= "links" required>Links
<input type="radio" name="table" id="browsing_history" value="browsing_history" required>Browsing History
<br>
<label for="col">Search Type</label>
<input type="radio" name="column" id="keywords" required>Keyword
<input type="radio" name="column" id="keyphrases" required>Keyphrase
<br>


Problemo fixed.

Just one issue.

I now get forwarded to following after form submission:

http://localhost/test/pagination_2.php?search=heman&tbl=links&col=keywords&limit=

In url, is missing:

limit=(value missing)

Also, in url, is missing:

"page=1".


<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>?col=<?php echo "$col&search=$search&limit=$limit&page=1";?>">


How to solve this ?
Copy linkTweet thisAlerts:
@developer_webauthorOct 30.2020 — @NogDog,

Which is better from following in terms of security ?

A.

<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>?col=<?php echo "$col&search=$search&limit=$limit&page=1";?>">

B.

<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>?col=<?php echo "$col"?>?search=<?php echo "&search"?>&limit=<?php echo "$limit"?>&page=<?php echo "1";?>">


Which you like ?

urlencode() is not needed here since not echoing any url ut redirecting to it. Right ? Or, wrong ?
Copy linkTweet thisAlerts:
@NogDogOct 31.2020 — Put them into hidden form fields instead of the form tag's action, and then you don't have to worry about what does or does not need to be url-encoded. However, since the form method is "get", _everything_ is going to end up in the target page's URL, because that's what GET does. If there's a reason you do not want them in the displayed URL, then use the POST method, instead.

Generally you want to use GET for read-only requests (which makes the link something that can be saved or bookmarked), while you should use POST for form submissions that will have a side effect (update/insert/delete in the DB, for instance).
Copy linkTweet thisAlerts:
@developer_webauthorNov 02.2020 — @NogDog#1624733

In other words, if I use POST method here then I won't need to use urlencode() since the form's destination urls' params will not be visible to users through the url for them to manipulate them in any vicious ways. I am aware POST method dumps the params direct to the db in a concealment way.

Let me know whether I understood you or not.
Copy linkTweet thisAlerts:
@developer_webauthorNov 02.2020 — @NogDog#1624733
Copy linkTweet thisAlerts:
@NogDogNov 02.2020 — As far as URL-encoding, it's not that it's post or get, but simply that it's a form field, and the browser software handles all of it for you. The difference between post/get is that get will transmit the form fields as part of the URL, while a post request puts all of them into a separate part of the HTTP request data that is not displayed in the URL.
Copy linkTweet thisAlerts:
@ByrgersunNov 03.2020 — Do you know how HTML forms work with the method set to GET?
Copy linkTweet thisAlerts:
@developer_webauthorNov 03.2020 — @Byrgersun#1624805

Yes.
Copy linkTweet thisAlerts:
@Greg13MyNov 09.2020 — Thanks for info!
×

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.26,
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,
)...