473,326 Members | 2,173 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,326 software developers and data experts.

I want to display just the state with last, first, areacode and phone number

No code errors jsut I displaqy all the states when the just state submit button is selected?
Expand|Select|Wrap|Line Numbers
  1.  <?php
  2. if(isset($_POST['state'])){$state = $_POST['state'];}
  3. if(isset($_POST['allrecords'])){$allrecords = $_POST['allrecords'];}
  4. if(isset($_POST['sort'])){$sort = $_POST['sort'];}
  5. if(isset($_POST['ascdsc'])){$ascdsc = $_POST['ascdsc'];}
  6.  
  7. $Connection = mysqli_connect("localhost", "jmcgoff", "jmcgoff", "dennis");
  8.  
  9. if(isset($_POST["state"])) {    
  10.     $query = "SELECT lastName, firstName, areaCode, phoneNumber FROM `contact` WHERE state = '$state'";
  11.  
  12.           if(isset($sort)) {
  13.                $query .=" ORDER BY $sort $ascdsc";
  14.             }
  15.     $result1 = mysqli_query($Connection, $query);
  16. }
  17.  while ($data = mysqli_fetch_array($result1)) { 
  18.  echo "<table>";
  19.  echo "<tr><td>$data[state]</td></tr>";
  20. echo "</table>";
  21.     }
  22. if (isset($_POST["state"])) {
  23.     $query = "SELECT * FROM `contact`";
  24.  
  25.         if(isset($sort)) {
  26.             $query .=" ORDER BY $sort $ascdsc";
  27.             }
  28.     $result = mysqli_query($Connection, $query);
  29. }
  30.  
  31. while ($data = mysqli_fetch_array($result)) { 
  32. echo "<table border='1'>
  33.     <tr>
  34.     <th>ID</th>
  35.     <th>Lastname</th>
  36.     <th>Firstname</th>
  37.     <th>Address</th>
  38.     <th>City</th>
  39.     <th>State</th>
  40.     <th>Zip Code</th>
  41.     <th>Area Code</th>
  42.     <th>Phone Number</th>
  43.     </tr>";
  44.  
  45.     echo "<tr>";
  46.     echo "<td>" . $data['contactID'] . "</td>";
  47.     echo "<td>" . $data['lastName'] . "</td>";
  48.     echo "<td>" . $data['firstName'] . "</td>";
  49.     echo "<td>" . $data['address'] . "</td>";
  50.     echo "<td>" . $data['city'] . "</td>";
  51.     echo "<td>" . $data['state'] . "</td>";
  52.     echo "<td>" . $data['zipCode'] . "</td>";
  53.     echo "<td>" . $data['areaCode'] . "</td>";
  54.     echo "<td>" . $data['phoneNumber'] . "</td>";
  55.     echo "</table>";
  56. }
  57.  echo '<br /><a href="retrieve.html">Retrieve Data</a>';
  58.  echo '<br /><a href="contact.html">Contact Form</a>';
  59. mysqli_close($Connection);
  60.  
  61. ?>
  62.  
Nov 11 '10 #1
1 1298
JKing
1,206 Expert 1GB
You have two blocks of code that query the database. One with a WHERE clause and one with the wildcard * to select all records. You execute and print both result sets.

I'm going to guess here that you want the if block on line 22 to be checking $_POST['allrecords'] not state again.

Also you should use mysql_real_escape_string() on variables you pass to the database to avoid sql injection attacks.
Nov 12 '10 #2

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

Similar topics

4
by: William Morris | last post by:
Our application tracks contact information. One of our clients, a car dealership, has asked about being able to enter a lastname and phone number and getting as much of the main form filled out as...
2
by: Dman | last post by:
Having trouble in Access XP. I want to display the customers name, city and phone number in a Combo Box but the but the formatting is lost – eg (123) 456-7890 is displayed as 1234567890. Any...
0
by: Brian Davis | last post by:
The problem is in the word boundary \b. A leading "(" will match as a word boundary before it gets to the test for a "(". Changing the expression to: (?n)(\b|\()1??\(?(?<areaCode>\d\d)?\)??(?...
5
by: Kamaluokeakua | last post by:
I have to write an application that deals with clients in multiple countries. The addresses, phone numbers, country id and currency information has to be stored into a database that allows for the...
4
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
8
by: Brigitte Behrmann | last post by:
The question goes like this: The following code contains errors, find and correct the errors. <html> <head> <title>Project2-3</title> </head> <body> <SCRIPT LANGUAGE="JavaScript"> <!--HIDE...
9
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
3
by: ryushinyama | last post by:
I am wanting to remove 1's that Canadian customers put in front of their numbers because when FedEx imports them for shipping they leave the 1 and cut off the last number. Other countries numbers...
1
by: jhansi | last post by:
hi... I have created a form it's working properly.... but i want to consider phone number and STD code in two different text field for a single lable phone number..... and I have considered...
4
by: luke noob | last post by:
This is my HTML... <head> <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script> <script type="text/javascript" src="js/script.js"></script> </head> <body>
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
1
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...
1
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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.