search query doesnt work in firefox but does in other browsers? - php

i have a search query script that works fine in firefox, safari etc but not in chrome.
for whatever reason once the user types in the query and hits submit im noticing the urls are very different.
in chrome i get this which works and is right
http://localhost/ptb1/home.php?query=london&submit.x=0&submit.y=0&submit=Start+Search
but in firefox i get this (notice that stat+search is missing and i dont know why
http://localhost/ptb1/home.php?query=london&submit.x=12&submit.y=10
please can anyone show me why i am getting this problem and how to put it right, thanks.
here's my code:
<form method="get" action="">
<input type="text" id="text" name="query" class="searchbox" placeholder="Search Name/Location" style="width:120px;"/>
<input type="image" src="../PTB1/assets/img/icons/search.png" height="19" width="20" class="searchbutton" name="submit" value="Start Search" />
</form>
<?php
//PHP CODE STARTS HERE
if(isset($_GET['submit'])){
// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
$db_password="";
$db_name="";
$db_tb_atr_name="display_name";
//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");
$query=mysql_real_escape_string($_GET['query']);
$query_for_result=mysql_query("SELECT *,MATCH(display_name, location, sex, ethnicity, hobbies, station, age, weight_st, weight_lb, height_ft, height_in, build) AGAINST ('$query' IN BOOLEAN MODE) AS relevance FROM ptb_stats WHERE MATCH(display_name, location, sex, ethnicity, hobbies, station, age, weight_st, weight_lb, height_ft, height_in, build) AGAINST('$query' IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT 5");
echo "<div class=\"search-results\">";
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo "<div class=\"text\"><a href=\"profile.php?id={$data_fetch['user_id']}\" class=\"search\">";
echo "<div class=\"spacing\"><img width=35px height= 30px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\" class=\"boxgridsearch\"/> ";
echo substr($data_fetch[$db_tb_atr_name], 0,160);
echo "</a></div></div>";
}
echo "<div class=\"morebutton-search\">+ view more results</div>";
mysql_close();
}
?>
<style type="text/css">
.boxgridsearch{
width: 35px;
height: 30px;
margin-top:-3px;
margin-left:0px;
margin-right:10px;
float:left;
background:#161613;
border:4px solid #000 .8;
-moz-box-shadow: 0px 0px 8px #CCC;
-webkit-box-shadow: 0px 0px 0px #CCC;
box-shadow: 0px 3px 10px #030303;
}
.suggestionsBox {
position: relative;
left: 12px;
margin: 10px 0px 5px 0px;
width: 172px;
background-color: #FFF;
border: 1px solid #CCC;
color: #fff;
z-index:99;
}
.searchbutton {
padding-top: 2px;
padding-left:5px;
position:absolute;
z-index:70;
}
.spacing {
padding-top: 12px;
padding-bottom:12px;
border-bottom: solid #CCC 1px;
border-top: solid #CCC 1px;
text-align:left;
margin-left:0px;
margin-top:5px;
width:160px;
}
.text {
text-align:left;
margin-left:20px;
margin-top:0px;
width:200px;
}
.search-results {
width: 200px;
height:218px;
float: left;
margin-bottom: 20px;
margin-left: 0px;
margin-top:10px;
text-align: center;
/* [disabled]margin-left: 30px; */
overflow: hidden;
padding-top: 0px;
padding-bottom: 10px;
}
.searchbox {
margin-left: -25px;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
a.search {
color: #646464;
text-decoration: none;
}
a.search:visited {
color: #646464;
}
a.search:hover {
color: #646464;
text-decoration: none;
}
a.search:active {
color: #646464;
}
</style>

You can try using $_SERVER['REQUEST_METHOD'] to determine if the page has been submitted, rather than isset($_GET['submit']) so basically instead:
if(isset($_GET['submit'])){
// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
you do:
if($_SERVER['REQUEST_METHOD'] == 'GET'){
// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";

Browsers will interpret how that form gets submitted differently. The behavior you're seeing with Firefox is actually the drafted standard:
http://www.whatwg.org/specs/web-apps/current-work/multipage/
Where we could delve into styling buttons vs using images (submit, vs image input type, vs button) - the easiest fix is to just add a hidden input value to your form:
<form method="get" action="">
<input type="hidden" name="dosearch" value="1">
<input type="text" id="text" name="query" class="searchbox" placeholder="Search Name/Location" style="width:120px;"/>
<input type="image" src="../PTB1/assets/img/icons/search.png" height="19" width="20" class="searchbutton" name="submit" value="Start Search" />
</form>
Then just tweak the condition for processing in your PHP:
if(isset($_GET['dosearch'])){
Quick patch.
You should consider a framework if you're going to do lots of this; you get lots of this kind of logic for free, in very clean and stratified code (MVC).

Related

form only submits a post when form is empty problem

Hello im trying to make a form that uploads a video file with images, tags and video name (vn stands for video name). which would upload all of this with a press of a button with post. while this worked in the past currently it isnt working and instead stops without uploading the data through post, however when i present the form with empty inputs it decides to go through with the post but then gets caught with the check if the forms are filled.
below is the code
<form method="post" action="" enctype="multipart/form-data">
<div class="btn">
<label>
Choose Your Video <input type="file" id="file" name="file" hidden="">
</label><br><br><br><br></div>
<div class="btn1">
<label>
Choose Your cover image <input type="file" id="images" name="image" hidden="">
</label></div>
<input type="text" placeholder="tags" onclick="" name="tags" id="tags" class="textbox">
<input type="text" placeholder="video name" name="vn" class="textbox1">
<div class="ca">
<label>
upload <input type="submit" name="submit2345" hidden="">
</div></label>
</form>
php (not all of it just the bits you need, im not showing all of it because it spreads across many lines). The check for the video file is lower and i haven't implemented a cover image yet because of this problem
<?php
if(isset($_POST["submit2345"]))
{
header1("eee");
If(rtrim($_POST['tags'])!="#" && rtrim($_POST['vn']!= "" )){
css if it matters
#vupb{
background-color: white;
box-shadow: 2px 4px 10px rgb(0 0 0 / 40%), 8px 2px 16px rgb(0 0 0 / 40%);
border-radius: 20px;
padding-top: 30vh;
width: 30vw;
margin-left: 30vw;
margin-top: 2vh;
padding-bottom: 10vh;
}
.ca{
width: 20vw;
overflow-x: hidden;
overflow-x: hidden;
border-radius: 5px;
border: 0px solid lightgrey;
background-color: limegreen;
color:white;
font-weight: 1000;
font-size: large;
margin-left: 5vw;
margin-top: 5vh;
padding-top: 2vh;
padding-bottom: 2vh;
}
.ca:hover{
background-color: #2bb32b;
color: lavender;
cursor: pointer;
}
.login input[type=file]{
display:none;
}
.btn{
width: 7vw;
height: 5vh;
padding-top: 1vh;
padding-bottom: 1vh;
border-radius: 5px;
border: 0px solid black;
background-color: #1877f2;
color:white;
font-weight: 1000;
font-size:medium;
margin-left: 18vw;
margin-top: -33.5vh;
}
.btn:hover{
background-color: #186edf;
color: lavender;
cursor: pointer;
}
.vfi {
border: 1px solid black;
width: 12vw;
height: 14vh;
overflow-x: hidden;
overflow-x: hidden;
text-align: center;
background-repeat: no-repeat;
background-size: 100% 100%;
margin-left: 5vw;
margin-top: -20vh;
font-weight: bold;
z-index: 90;
}
.textbox {
width: 20vw;
height: 7vh;
font-size: medium;
border-radius: 5px;
border: 1px solid lightgrey;
margin-top: 15vh;
}
.textbox1 {
width: 20vw;
height: 7vh;
font-size: medium;
border-radius: 5px;
border: 1px solid lightgrey;
margin-top: 2vh;
}
.btn1{
width: 7vw;
height: 5vh;
padding-top: 1vh;
padding-bottom: 1vh;
border-radius: 5px;
border: 0px solid black;
background-color: #1877f2;
color:white;
font-weight: 1000;
font-size:medium;
margin-left: 18vw;
margin-top: 12.5vh;
}
.btn1:hover{
background-color: #186edf;
color: lavender;
cursor: pointer;
}
.vfi1 {
border: 1px solid black;
width: 12vw;
height: 14vh;
overflow-x: hidden;
overflow-x: hidden;
text-align: center;
background-repeat: no-repeat;
background-size: 100% 100%;
margin-left: 5vw;
margin-top: 5vh;
font-weight: bold;
z-index: 91;
}
Your HTML isn't valid. Most likely your POST isn't working because there are several syntax errors. Try again by using valid HTML like this
<form method="post" action="" enctype="multipart/form-data">
<div class="btn">
<label>
Choose Your Video
<input type="file" id="file" name="file" hidden=""/>
</label>
<br/>
<br/>
<br/>
<br/>
</div>
<div class="btn1">
<label>
Choose Your cover image
<input type="file" id="images" name="image" hidden=""/>
</label>
</div>
<input type="text" placeholder="tags" onclick="" name="tags" id="tags" class="textbox"/>
<input type="text" placeholder="video name" name="vn" class="textbox1"/>
<div class="ca">
<label>
upload
<input type="submit" name="submit2345" hidden=""/>
</label>
</div>
</form>

PHP form displays on anchor click and jumps to right place in ie but not chrome. No JS

I have built a working form that does what I want in IE an upon cross testing I have found that it jumps to the lower id= in Chrome instead of the upper name= as in IE. I know the name tag has been depreciated but I for the life of me cannot get this to open and move the form to the top any other way. I need this to work without JS. I have never used PHP before and have built this around a template for a php form. Im not sure how to hack this one any further. I have put in a lot of work to get this functional and any changes I make just break it completely.
So far I have changed names and id's but everything breaks it. I know it has to do with having both a name and an id but I'm not sure how to fix this without JS. I am testing on IE 11 and Chrome 77. I don't so much care about "old browsers" but would like to get most of the stuff being used on win 7 and up, so legacy support is not an issue but I do want to follow best practices. I am new to forms so I'm not sure where to go from here. As I said, it works, just not everywhere.
#quotejump {
display: none;
}
#quotejump:target {
display: block;
}
.form-style{
max-width: 400px;
margin: 10px auto;
padding: 0px;
background: #a0a0a0;
font-family: inherit;
border-top-left-radius: 50px;
border-top-right-radius: 50px;
border-bottom-left-radius: 50px;
border-bottom-right-radius: 50px;
text-align: center;
}
.form-style a, .form-style h1{
text-decoration: none;
display: inline-block;
background: linear-gradient(45deg, #00f, #0ff);
padding: 20px 0;
font-size: 30px;
font-weight: 300;
width: 100%;
color: #fff;
margin: 0;
border-radius: 50px;
}
.form-style input[type="text"],
.form-style input[type="date"],
.form-style input[type="datetime"],
.form-style input[type="email"],
.form-style input[type="number"],
.form-style input[type="search"],
.form-style input[type="time"],
.form-style input[type="url"],
.form-style textarea,
.form-style select {
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
outline: none;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
width: 92%;
background: #fff;
margin-bottom: 4%;
border: 1px solid #ccc;
padding: 3%;
color: #;
font-family: inherit;
border-radius: 30px;
}
.form-style input[type="text"]:focus,
.form-style input[type="date"]:focus,
.form-style input[type="datetime"]:focus,
.form-style input[type="email"]:focus,
.form-style input[type="number"]:focus,
.form-style input[type="search"]:focus,
.form-style input[type="time"]:focus,
.form-style input[type="url"]:focus,
.form-style textarea:focus,
.form-style select:focus
{
box-shadow: 0 0 5px #43D1AF;
padding: 3%;
border: 1px solid #43D1AF;
}
.quotebutton {
text-decoration: none;
border: none;
background: linear-gradient(45deg, #00f, #0ff);
border-radius: 30px;
text-align: center;
line-height: 60px;
color: #fff;
font-size: 30px;
margin: 0 2px;
transition: 0.25s;
}
.form-style a:hover {
-webkit-transform:scale(1.25);
-moz-transform:scale(1.25);
-ms-transform:scale(1.25);
-o-transform:scale(1.25);
transform:scale(1.25);
-webkit-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-moz-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-ms-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-o-box-shadow: 0 3px 6px rgba(0,0,0,.5);
box-shadow: 0 3px 6px rgba(0,0,0,.5);
position:relative;
z-index:5;
}
.quotebutton:hover {
-webkit-transform:scale(1.25);
-moz-transform:scale(1.25);
-ms-transform:scale(1.25);
-o-transform:scale(1.25);
transform:scale(1.25);
-webkit-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-moz-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-ms-box-shadow: 0 3px 6px rgba(0,0,0,.5);
-o-box-shadow: 0 3px 6px rgba(0,0,0,.5);
box-shadow: 0 3px 6px rgba(0,0,0,.5);
position:relative;
z-index:5;
}
<h1>Top of Page</h1>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>some filler text to move the page down</p>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<a name="quotejump"> </a>
<div class="calltoaction">
<h1>Contact us today for a quote!</h1>
<p>Due to the nature of the customization process all prices are figured for each specific job. This allows us to ensure the quality of your products while maintaining the lowest prices possible for you. You won't find this quality cheaper anywhere else! We guarantee it! </p>
</div>
<div class="form-style">
<a href="#quotejump" >Get Your FREE Quote Here!</a>
<div id="quotejump">
<span id="quoteform"><br />Learn How We Can Save You Money On Quality Produts Today!
<form method="post" action="send_mail.php">
<p><input type="text" name="first_name" placeholder="Your Name" required></p>
<p><input type="email" name="email_address" placeholder="Email Address" required></p>
<p><textarea name="comments" placeholder="Type your message" maxlength="1000" ></textarea></p>
<p><button class="quotebutton">Submit Form</button></p>
</form>
</span>
</div>
</div>
It should jump to the name tag and it does in IE 11 but jumps to the id tag in chrome. Any idea how to fix this without messing up the php and the display hidden until clicked on? I tried a check box but couldn't make it jump. I don't want it to be able to toggle as I want it to stay open once clicked on. Any help would be greatly appreciated.
IE11 What it should do
Chrome What it does in chrome when opened
Image of form before opening

Duplicating Empty Data in SQL when refreshing

I've been working on a system that allows a user to insert data, which will pass into a MySql database using SQL querieshowever, I've noticed that every time the page is refreshed, empty data is inserted into the database. Connection, queries, PHP, HTML and every other code works. The redirection works as intended but I realise my system just needs a slight correction. Am I doing something wrong?
<?php
$con = mysqli_connect("localhost","root","","system");
$error = 0;
$errormessage = "";
if( isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_GET['email'];
$password = $_POST['password'];
$password = hash('sha256' , $password);
}else{
$errormessage = $errormessage . "Please Fill all Fields";
$error++;
}
if($errors == 0){
$sql = "INSERT INTO User
(name, email, password)
VALUES
('$name','$email','$password')";
mysqli_query($con, $sql) or die (mysqli_error($con));
$errormessage = "Data Successfully Entered";
}
?>
<!DOCTYPE html>
<html>
<body>
<header>
<div style="background-color:black"><div style="text-align:center;"> <h1><style="color:Black;">Register</h1></div></div> </header>
<style>
input[type=text], select {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 5px solid magenta;
border: 5px solid magenta;
border-radius: 4px;
box-sizing: border-box;
align:center;
}
input[type=button] {
width: 50%;
background-color: #4CAF50;
color: white;
padding: 14px 40px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
align:center;
}
input[type=password], select {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 5px solid magenta;
border: 5px solid magenta;
border-radius: 4px;
box-sizing: border-box;
align:center;
}
input[type=email], select {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 5px solid magenta;
border: 5px solid magenta;
border-radius: 4px;
box-sizing: border-box;
align:center;
}
input[type=submit] {
width: 50%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
align:center;
}
input[type=submit]:hover {
background-color: green;
}
div {
margin-left:auto;
margin-right:auto;
width: 90%;
border: 5px solid lime;
border-radius: 5px;
background-color: #ECF0F1;
padding: 20px;
}
</style>
</nav>
<div>
<form method="Post">
<label for="name">
<div style="text-align:center;"><input type= "button" id="RegisterPage" value = "Go to Register Page" onclick="document.location.href='example.php'">
<input type= "button" id="LoginPage" value = "Go to Login Page" onclick="document.location.href='http://localhost/example2.php'"><p>Your Name</label><br>
<input type="text" id="name" name="name" placeholder="Enter Name" required><br>
<label for="email">E-Mail:</label><br>
<input type="email" id="email" name="email" placeholder="Your e-mail" required><br>
<label for="password">Password:</label><br>
<input type="password" name="password" placeholder="At least 6 characters" required><br>
<input type="submit" name = "submit" value="Create your Account ">
</form></div>
<footer><div style="background-color:aqua; border: 5px solid black;">
</form></div>
</footer>
</nav>
</body>
</html>
You can do a ON DUPLICATE KEY UPDATE with your insert statement to update the database records instead of entering more. Also, make sure to setup your primary keys in your DB.
$sql = "INSERT INTO User
(name, email, password)
VALUES
('$name','$email','$password')
ON DUPLICATE KEY UPDATE
name = `$name`, email = `$email`, `$password`";

Stack overflow solutions are not working for me what i'm I doing wrong?

This question has been asked alot so I found this article Allowing users to Refresh browser without the "Confirm Form Resubmission" pop-up
And I follow what it said but now i'm getting this message 500: Internal Error.
So what i'm I doing wrong here? I basically want be able to refresh a page with out getting greeted with this message
Confirm For Resubmission
The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?
because of a form and I all so checked this out to Preventing form resubmission
I try to understand these guys answers but i'm still not getting something right if any one can show me the two so called poplar methods mentioned in the links by using the PHP method or the AJAX with jQuery method to prevent that confirm for resubmission message I will really appreciate that. Please I prefer code solutions based on my code as answers because I personally learn best that way thank you.
GIF Screenshot
code
index.php
<!DOCTYPE html>
<html>
<head>
<style>
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'Nunito', sans-serif;
color: #384047;
}
form {
max-width: 300px;
margin: 10px auto;
padding: 10px 20px;
background: gold;
border-radius: 8px;
}
h1 {
margin: 0 0 30px 0;
text-align: center;
}
input[type="text"] {
background: rgba(255,255,255,0.1);
border: none;
font-size: 16px;
height: auto;
margin: 0;
outline: 0;
padding: 15px;
width: 100%;
background-color: white;
color: black;
box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
margin-bottom: 30px;
}
button {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: blue;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid blue;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
cursor: pointer;
}
label {
display: block;
margin-bottom: 8px;
}
label.light {
font-weight: 300;
display: inline;
}
</style>
</head>
<body>
<form action='x.php' method='POST'>
<h1>Form</h1>
<label for='name'>Name</label>
<input type='text' id='name' name='name' value='Tom'>
<label for='age'>Age</label>
<input type='text' id='age' name='age' value='20'>
<button type='submit'>Send</button>
</form>
</body>
</html>
x.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){ header('x.php'); }
$name = $_POST['name'];
$age = $_POST['age'];
?>
<p><?php echo $name; ?></p>
<p><?php echo $age; ?></p>
I changed your code a bit, but should produce the result that you want
<?php
if(isset($_POST['submit'])){
header('Location: x.php?successfulRedirect');
exit;
}
?>
<form action='' method='POST'>
<h1>Form</h1>
<label for='name'>Name</label>
<input type='text' id='name' name='name' value='Tom'>
<label for='age'>Age</label>
<input type='text' id='age' name='age' value='20'>
<input type='submit' name='submit' value='Send' />
</form>
This will make sure that you will be redirected to x.php after clicking Send, with a GET parameter it in, just to see that the redirection works

Comment System CSS text gets out of box

I have recently coded a simple comment system using PHP.
http://runescapepvp.net/jony/index.php
As you see in the following link I posted, if the comment is long, it will get out of the box.
Im not to sure why it happens when I've set max width for text.
Im using this to call the boxes
function showComments() {
$query = mysql_query("SELECT * FROM `comments` ORDER BY `comment_id` DESC LIMIT 5") or die (mysql_error());
$allcomments = mysql_query("SELECT * FROM `comments` ORDER BY `comment_id`") or die (mysql_error());
if (mysql_num_rows($query) == 0) {
echo '<br /><br />';
handleAlerts("noComments");
} else {
while ($row = mysql_fetch_assoc($query)) {
echo "
<br />
<br />
<div class='comments'>
<div class='title'><span class='author'>Posted by: ".$row['comment_guest']."</span><span class='date'>At ".$row['comment_time'].", ".$row['comment_date']."</span></div>
<div class='comment'>
<span class='message'>
".$row['comment']."
</span>
<br />
<a href='index.php?delete=comment&id=".$row['comment_id']."'><div class='button_delete'>Delete</div></a>
</div>
</div>
";
}
}
echo '<br /><br /><br />';
}
CSS:
.title {
background-image: url("../img/header.png"); background-repeat: repeat-x;
width: 100%;
height: 56px;
border: solid 1px #a8a8a8;
line-height: 56px;
font-size: 17px;
color: grey;
text-align: left;
display: block;
}
.comments {
position: relative;
top: 50px;
}
.comment {
width: 640px;
height: auto;
display: block;
min-height: 100px;
background-color: #e6e6e6;
border-left: solid 1px #a8a8a8;
border-right: solid 1px #a8a8a8;
border-bottom: solid 1px #a8a8a8;
}
.message {
width: 600px;
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 10px;
}
Why is it happening?
I am not really sure if the error is related to PHP.
Thanks a lot!
You can try adding this CSS to your .comment class:
word-break: break-all;
Or
overflow: auto;
You can solve this in css:
To hide what is not part of the box:
.comment {
overflow: hidden;
}
To use the new css3 property to break the long word:
.comment {
word-break: break-all;
}

Categories