473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Space bar + Submit button returns all data. HELP!

Hi,

When I press the space bar and click submit in my search bar it returns all data with a space in it, how can I stop this from happening so nothing happens?

Thank you very much, please find the code below

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <body>
  4. James' New Site
  5. <form action="seaside.php" method="post">
  6. <input type="text" name="search"><br>
  7. <input type="submit">
  8. </form>
  9. <hr width="100%"></hr>
  10. </body>
  11. </html>
  12. <?php
  13. if(strlen($_POST['search']) > 0) {
  14. //all of your php code for the search
  15.  
  16.   $search = "%" . $_POST["search"] . "%";
  17.  
  18.   mysql_connect ("", "", "");
  19.   mysql_select_db ("");
  20.  if (!empty($_POST["search_string"])) 
  21.    { 
  22.       // then perform your queries and stuff here. 
  23.    }  
  24.   $query = "SELECT name,msg FROM contact WHERE name LIKE '$search'";
  25.   $result = mysql_query ($query);
  26.   if ($result) {
  27.     while ($row = mysql_fetch_array ($result)) {
  28.       echo "<br>$row[0]</br>";
  29.       echo $row[1];
  30.     }
  31.   }
  32. }
  33. ?>
  34.  
  35.  
Aug 16 '11 #1
1 1620
Rabbit
12,516 Expert Mod 8TB
You could use the trim function to strip off the whitespace.
Aug 17 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Daniel | last post by:
For an odd reason that I cannot figure out on my own, when a user attempts to log-in on my Log-In page, they must press the submit button twice. They fill out their credentials (username,...
3
by: Nick | last post by:
Should be a quickie but I just can't get it to work. I have a form where my users can submit their football picks, when they click submit I would like another sized window to appear...
5
by: Jimbo | last post by:
I am trying to right a script so that the "submit button" only appears when certain criteria has been met. I have tried putting it in an IF statement, without any luck. Maybe a function would allow...
15
by: JR | last post by:
Hi. I hope someone out there who is more versed with JavaScript than I can help me with the following annoying problem. Here's the problem. I have a form with the following layout: Column A...
3
by: Isabel | last post by:
hi all, *****short version of my problem**** I used this code... <input type="button" name="btn1" onClick="document.location.reload (true)" value="Reload"> but it only works once! After...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
2
by: dipesh10 | last post by:
I am doing one project with asp net 2.0 and c# ,i have master page and content page , in content page i have 10 text box and one submit button , when submit will click those text box need to...
3
by: kavithadevan | last post by:
Hi, Here i have pasted 2 scripts first one is design and next one is country.php in the below code is working nicely. ----------------------design.php------ <form name="form1" method="post"...
1
by: kumar85 | last post by:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using...
1
by: jan reiner | last post by:
good day everyone.. i am doing a project for my school i am having difficulties in inserting data in mysql and also inserting multiple data in just a submit button.. can anyone help me in this?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.