473,511 Members | 14,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble with PHP script that searches a database... Please help.

8 New Member
Here is my form:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <form name="zipcode_search" id="form" class="form" method="post" action="process.php">
  3. <input name="zip" id="zip" type="text" placeholder="Zip Code" maxlength="5"/>
  4. <button name="submit" id="search" type="submit"> Search </button>
  5.  
  6.  
  7. </form>
and script

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. $host="localhost";
  4. $base="mydb";  
  5. $user="myusername";
  6. $pass="mypassword"; 
  7.  
  8. $connect=mysql_connect($host, $user, $pass) or die("Could not connect to database!!!!");
  9. mysql_select_db($base,$connect) or die("Count not find database table!");
  10.  
  11. if(isset($_POST['zip'])){
  12.     $zip=htmlspecialchars(mysql_real_escape_string($_POST['zip']));
  13.     $res=mysql_fetch_assoc(mysql_query("SELECT url FROM redirect WHERE zip='$zip'"));
  14.     header('Location: '.$res['url']);
  15.     exit;
  16. }
  17.  
  18. else{ 
  19.     header('Location: http://www.bettercabletv.com/not-listed.html');
  20. }
  21. ?>
  22.  
I get these errors

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home3/spizz/public_html/bettercabletv.com/process.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at /home3/spizz/public_html/bettercabletv.com/process.php:12) in /home3/spizz/public_html/bettercabletv.com/process.php on line 13

Any pointers?
Feb 4 '15 #1
5 1433
Rabbit
12,516 Recognized Expert Moderator MVP
I don't see anything that jumps out at me as wrong with the code. But I would follow the template in the PHP manual just to make sure every error is covered. http://php.net/manual/en/function.mysql-fetch-assoc.php

The header information error is caused by something being output to the client before the header. In this case, it is probably because the SQL error is output before the header. It should go away once you figure out the SQL error.
Feb 5 '15 #2
Jpizzolato
8 New Member
Rabbit - thanks for your assistance. I figured out what the issue was and it was simply just a letter typed wrong in the table. Thanks for your help.
Feb 5 '15 #3
Rabbit
12,516 Recognized Expert Moderator MVP
No problem
Feb 5 '15 #4
Jpizzolato
8 New Member
Rabbit - would there be any reason that above script isn't going to the else function when say I type a zip code that is not on the list?
Feb 6 '15 #5
Rabbit
12,516 Recognized Expert Moderator MVP
We try to limit it to one question per thread so it makes it easier for other people to find answers. I assume the new thread you made is for this latest issue. If not, please create a new one for this new question.
Feb 6 '15 #6

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

Similar topics

1
2574
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
1
1787
by: Lauren Wilson | last post by:
I'm having trouble with the Access VBA help on my installation of A2K with Dev tools. Every time I try to retrieve help for items listed in the Object Browser (and SOME other items as well),...
2
4522
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk =...
0
1521
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server...
1
5125
by: MLH | last post by:
Am having trouble with the filter property setting below. Would like to filter the listing to car makes beginning with "D". I'm blowing it on the filter spec somehow??? Sub OpenRecordsetX() ...
0
1835
by: harry12 | last post by:
Hello- I'm fairly new at using Microsoft Access and I'm having trouble getting a couple of things to work in my database. The first is that I have yet to find a way to get an append query to...
47
2822
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
1
2663
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
3
1494
by: jaesik | last post by:
Hi all, I've been working on my personal portfolio website and been struggling a lot because of J-query. Since my j-query level is not like master.. I usually modify existing j-query plugins to...
1
1847
by: BarbQb | last post by:
Hi All, I am having trouble filtering a report with a multiselect list box. The report is generated, but it is not filtered based on the selections of the list box: lstVehID Multi Select...
0
7245
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
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7427
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...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.