Hi,
I am trying to make a job board.
I have made two search boxes:
1/ Job Title
2/ Location
I have made a mockup form for the recruiters to input their job data into my database.
How do I link up two of the fields from the table so the job title when searched is matched up with the location?
The table consists of
msg_id | name | location | msg
Name is the table field for 'Job Title' by the way
The code is below:
Thanks!
James -
-
<html>
-
<Head>
-
<title>Contact form</title>
-
<style type="text/css">
-
table{
-
border:1;
-
border-collapse:collapse;
-
font: normal 12px 'Lucida Grande',Verdana,sans-serif;
-
}
-
td{
-
color:#663333;font-family:verdana;
-
border-bottom: 1px solid #666;
-
padding-left:10px;
-
background-color:#F0F8FF;
-
}
-
#sub{ text-align:center;}
-
</style>
-
</Head>
-
<body>
-
James' New Site
-
<br>
-
<h2> FeedBack/Contact Form</h2>
-
<form action="contact_insert.php" method="POST" id="insert">
-
<table>
-
<tr>
-
<td >Name*</td>
-
<td ><input type="text" size=40 name="name"></td>
-
</tr>
-
<tr>
-
<td >location</td>
-
<td ><input type="text" size=40 name="location"></td>
-
</tr>
-
<tr>
-
<td >Comments/Suggestions*</td>
-
<td ><textarea name="msg" cols=40 rows=7></textarea> </td>
-
</tr>
-
<tr>
-
<td colspan=2 id="sub"><input type="submit" name="submit" value="submit" ></td>
-
</tr>
-
</Table>
-
</form>
-
<br>
-
<br>
-
<form action="seaside.php" method="post">
-
<input type="text" name="search">
-
<input type="text" name="search2">
-
<input type="submit">
-
</form>
-
<hr width="100%"></hr>
-
</body>
-
</html>
-
<?php
-
if(strlen(trim($_POST['search'])) > 0) {
-
//all of your php code for the search
-
-
$search = "%" . $_POST["search"] . "%";
-
-
mysql_connect ("", "", "");
-
mysql_select_db ("");
-
if (!empty($_POST["search_string"]))
-
{
-
// then perform your queries and stuff here.
-
}
-
$query = "SELECT name,msg FROM contact WHERE name LIKE '$search'";
-
$result = mysql_query ($query);
-
if ($result) {
-
while ($row = mysql_fetch_array ($result)) {
-
echo "<br>$row[0]</br>";
-
echo $row[1];
-
}
-
}
-
}
-
?>
-
-
25 8165
Do you mean match Job Title in the name field and Location in the location field? You can use AND in the SQL's where clause to use two criteria.
Hi there,
Yes so say for instance someone searches:
"Receptionist" in the Job title search box and "Kent" in the location search box and click submit, the only results that show is data that involves "receptionist" and "kent" in its table row
Thanks!
James
Also do I have to so anything to the search boxes so each one refers to its certain properties so one only answers to name and one to location?
You don't have to do anything to the search boxes. You just need to modify the query to account for both criteria using the key word AND.
Thanks,
So will it literally look like this? -
$query = "SELECT name AND location FROM contact WHERE name LIKE '$search'";
-
how can I also include my field msg to show its data in results?
Cheers!
You keep the same SELECT clause as before. You just need to modify your WHERE clause. The WHERE clause is the place where you put criteria.
If you're having trouble with SQL, you should look into a SQL tutorial. It will save you countless hours.
Also, I noticed that in your PHP, you're referring to a POST field named 'search'. I can only assume on the page before the search results, your name textbox is named 'search'. If this is not the case, then that is wrong as well.
Also, there's nothing in your SQL connection. That's just to protect confidential information correct? Otherwise, you're not actually connecting to anything.
Yeah that's just to protect confidential information. I searched for SQL Where tutorials and all the posts seem to be like this example:
SELECT *
FROM Customers
WHERE LastName = 'Smith'
How do I do it so people are entering what they want to search in that field not going by what I have written into the script like the example above?
Thanks for the help so far!
James
I'm not sure what you mean by your third paragraph.
But bouncing off your SQL example, if I wanted to find someone a LastName of Smith and a FirstName of John, I would do this - SELECT *
-
FROM Customers
-
WHERE LastName = 'Smith'
-
AND FirstName = 'John'
That should be enough to fix the SQL syntax.
I mean as you are stating in the script, referring to the example above, to only show John Smith so the users freedom to search whatever last name cannot happen?
Ok from looking at the tutorials I did the same to my script but it returns all posts with the word trainee disregarding if kent is in its row's data. How do I do it so the only data that shows in my results are entries where BOTH trainee and kent are present in the same row in my table? -
-
$query = "SELECT name,location,msg FROM contact WHERE name = 'trainee' AND location = 'kent' LIKE '$search'";
-
$result = mysql_query ($query);
-
if ($result) {
-
while ($row = mysql_fetch_array ($result)) {
-
echo "<br>$row[0]</br>";
-
echo $row[1];
-
echo "<br>$row[2]</br>";
-
-
That's because you have the LIKE predicate in there. Take that out and it'll work.
The user is free to search whatever they want. The example was only to show how to combine two criteria, which is what you were asking about.
Ok I got rid of the LIKE and when i entered in my search boxes nothing appears now..
and then I got this message:
Parse error: syntax error, unexpected '>' in /websites/123reg/LinuxPackage21/fo/ur/wa/fourwaysdp.co.uk/public_html/seaside.php on line 67
it refers to the <br> part below, why is it not working still? -
$query = "SELECT name,location,msg FROM contact WHERE name ='shannon' AND location = 'bexleyheath';
-
$result = mysql_query ($query);
-
if ($result) {
-
while ($row = mysql_fetch_array ($result)) {
-
echo "<br>$row[0]</br>";
-
echo $row[1];
-
echo "<br>$row[2]</br>";
-
}
-
}
-
}
-
?>
-
</body>
-
</html>
-
You didn't close off your sql string; you have an open double quote. Also, there is no such thing as </br>. Either <br> or <br />.
Ah right my mistake sorry!
Ok now I have updated the same section BUT now only 'shannon' and 'bexleyheath' are returned from the search box. No matter what I type in the search box the only results are shannon and bexleyheath.
How is this part fixed?
Thank you so much for the help! Nearly there!
James -
$query = "SELECT name,location,msg FROM contact WHERE name = 'shannon' AND location = 'bexleyheath' ";
-
$result = mysql_query ($query);
-
if ($result) {
-
while ($row = mysql_fetch_array ($result)) {
-
echo "<br>$row[0]<br/>";
-
echo $row[1];
-
echo "<br>$row[2]<br/>";
-
}
-
}
-
}
-
?>
-
</body>
-
</html>
-
One tutorial said to do this: -
$query = "SELECT name,location,msg FROM contact WHERE name = '$searchname' AND location = '$searchlocation' ";
-
AND:
One tutorial said to do this: -
$query = "SELECT name,location,msg FROM contact WHERE name = '$name' AND location = '$location' ";
-
But that also hasn't worked...
Those are just variables, you can call them whatever you want. The important part is to populate that variable with the correct POST data.
You have an example of that in line 57 of your original post. But I suspect you didn't use the correct POST variable name. I don't know what you named your inputs so I can't tell you what that's supposed to be.
I have submitted examples into my database like the one above:
name: shannon
location: bexleyheath
So I am typing the correct text in. What kind of coding am I needing/missing instead of -
$query = "SELECT name,location,msg FROM contact WHERE name = '$name' AND location = '$location' ";
-
The post parts of my script are parts another web developer told me to put in to stop blank searches retreiving all data in my search results and to stop search results appearing when space bar is put in the search box with nothing else.
[deleted post deleted post deleted post]
Referring back to POST
this is the script I use for posting information to my database: -
<?php
-
-
// contact to database
-
$connect = mysql_connect("", "", "") or die ("Error , check your server connection.");
-
mysql_select_db("");
-
-
//Get data in local variable
-
$v_name=$_POST['name'];
-
$v_location=$_POST['location'];
-
$v_msg=$_POST['msg'];
-
-
// check for null values
-
if ($v_name=="" or $v_msg=="")
-
echo "All fields must be entered, hit back button and re-enter information";
-
else{
-
$query="insert into contact(name,location,msg) values('$v_name','$v_location','$v_msg')";
-
mysql_query($query) or die(mysql_error());
-
echo "Your message has been received";
-
}
-
-
-
?>
-
<html>
-
<body>
-
<a href="seaside.php">Back</a>
-
</body
-
</html>
-
Lines 8 and 9 are how you get information out of POST. Line 16 is how you use the information you got out of POST. Do the same thing for the search.
I have tried to include this but I am so confused as where to put it
<?php
if(strlen(trim($_POST['search'])) > 0) {
//all of your php code for the search
$search = "%" . $_POST["search"] . "%";
mysql_connect ("", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
// then perform your queries and stuff here.
}
$query = "SELECT name,location,msg FROM contact WHERE name='$v_name'' AND location='$v_location'";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) {
echo "<br>$row[0]<br/>";
echo $row[1];
echo "<br>$row[2]<br/><br><br/>";
}
}
}
?>
This failed to work so what do I put instead of that?
From post #21, you only did the second part, you still have to do the first part.
I have tried to put it all the places i think it could be but It still returns no results...
Is it a case of just copying lines 8 and 9 and placing them? Or does it involve including more code?
Sorry to be a pain! I have only started using php since Sunday!
Thanks again! - <?php
-
if(strlen(trim($_POST['search'])) > 0) {
-
//all of your php code for the search
-
$v_name=$_POST['name'];
-
$v_location=$_POST['location'];
-
$v_msg=$_POST['msg'];
-
$search = "%" . $_POST["search"] . "%";
-
-
mysql_connect ("cust-mysql-123-03", "ufou_576458_0001", "trotman1");
-
mysql_select_db ("fourwaysdpcouk_576458_db1");
-
if (!empty($_POST["search_string"]))
-
{
-
// then perform your queries and stuff here.
-
}
-
$query = "SELECT name,location,msg FROM contact WHERE name='$v_name'' AND location='$v_location'";
-
$result = mysql_query ($query);
-
if ($result) {
-
while ($row = mysql_fetch_array ($result)) {
-
echo "<br>$row[0]<br/>";
-
echo $row[1];
-
echo "<br>$row[2]<br/><br><br/>";
-
-
}
-
}
-
}
-
?>
-
That depends on if you actually named your inputs with those names on the form. You also have two single quotes in your select query after the name variable. And you're checking for a search_string variable in your post which I doubt is in the input form.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Powell |
last post by:
The table already has a fulltext index and from there I can use the
MySQL fulltext search query to get results as well as the relevancy
score.
The problem I have is that MySQL has a default...
|
by: Richard |
last post by:
Hi
I have a PHP script which parces a mySQL table and shows which
sections meet on which day by using an array containing (mon,...Fri)
and another lisitng sections. I then have the PHP do to...
|
by: Google Mike |
last post by:
This has been discussed before back in 2002, and then in Feb of 2003
when I did a search on Google Groups for MySQL Table Sizes. Back then,
people said go here:
...
|
by: jaks |
last post by:
How can I export a MySQL table with a different name using phpmyadmin?
I want to export
nuke_bbsearch_wordmatch
and all it contents to
phpbb_search_wordmatch
This table in a different db. ...
|
by: l3vi |
last post by:
I have a new system Im building that stores entries of what people are
searching for on my sites.
I want to be able to keep records of how many times a keyword was
searched for daily, and from...
|
by: whitemoss |
last post by:
Hi,
I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors:
client.c: In function senddata:...
|
by: djdarpan |
last post by:
Hi,
Can anyone help me!
I have multiple auto generated input fields(e.g. values are 1 to 10) in a form and I want to insert all input fields data in one column of MySQL table. Is there any way...
|
by: mantrid |
last post by:
Hello
Can anyone point me in the right direction for the way to read a text file a
line at a time and separate the fields on that line and use them as data in
an INSERT to add a record to a mysql...
|
by: mramsay |
last post by:
Hi,
I'm having a real problem creating a dynamic hyperlink for my website.
I want to pull the field name from mysql table. Field name is description.
I would like this to be a hyperlink on my...
|
by: cardeal |
last post by:
Hi!
I have a long field on a mysql table and I would like to create a new table (from the old one) with the (new) content distributed into several fields.
Example:
oldField:
1. pace paz...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |