Jump to content

Unknown Column and Messy php


aeafisme23

Recommended Posts

I have never bragged about my basic skills of php but i have an error that says:

Unknown column 'station_id' in 'field list'

I have done some research on the forums and google and the only conclusion i can come to is that my Select statements need to have ' or not have " (quotes/single quotes). I am unsure of whether or not my Select statements are right in that sense, i did however to get it to pull some of the information but after so many it just stopped pulling results. Secondly, i know this code can be cleaned up ALOT and was just wondering if there is any insight of logic to do this? I haven't began to format so i know the html is sloppy right now but im more concerned on functionality right now. Much help is appreciated :) See complete code below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>

<body><?php
//DO NOT remove these two lines, if you do, the retrieve file will NOT work!
$station = $_GET['station'];
?>
<table width="950" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td width="150" valign="top">
		<table width="150" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td width="100"><B>Stations</B><br>
				<a href="view_records.php?station=KBCI">KBCI</a><br>
				<a href="view_records.php?station=KCBS">KCBS</a><br>
				<a href="view_records.php?station=KCNC">KCNC</a><br>
				<a href="view_records.php?station=KCTV">KCTV</a><br>
				<a href="view_records.php?station=KDKA">KDKA</a><br>
</td>
			</tr>
		</table>
	</td>
	<td width="800" valign="top"><h1>Station Management System</h1><h2><?php echo $station; ?></h2><br />
		<table width="800" cellpadding="0" cellspacing="0" border="0">
<?php   
// CONTRACT STATUS
					    //Setup connection to the database 
					    $connect = mysql_pconnect("localhost", "user", "pass") 
					    or die(mysql_error()); 

					    //Connect to the database 
						mysql_select_db("dbname", $connect) or die(mysql_error());    

					    // Perform an SQL query on the Address table    
						$sql_address = mysql_query("SELECT station_id, status, notes from contract_status where station_id = '".$station."'") 

					    or die (mysql_error()); 
						   
						// Define the colours for the alternating rows 
						$colour_odd = "#FDFDEA"; 
						$colour_even = "#E0E0C7"; 
					    $row_count = 0;  //To keep track of row number 

					    // Fetch the array of records and Loop through them 
						while($results = mysql_fetch_array($sql_address)){ 
						// Decide which colours to alternate for the rows If Remainder of $row_count divided by 2 == 0. 
						$row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd; 

						//Echo the table row and table data that needs to be looped Check All With selected: over until the end of the recordset     
						echo ' 
						 <tr bgcolor="' . $row_color . '"> 
						  <td width=100 valign=top><p>Contract Status<br>Station: ' .$results['station_id'] . '</p></td> 
						  <td width=300 valign=top><p><br>Contract Status: ' .$results['status'] . '</p></td> 
						  <td width=400 valign=top><p><br>Contract Notes: ' .$results['notes'] . '</p></td>					  
						  </tr>'; 

					   // Increment the row count 
						 $row_count++; } 
					   // Free the MySQL resource 
					   mysql_free_result($sql_address); 
					   // Close the database connection 
					   mysql_close($connect); 
?> 			</table>
<br />	
		<table width="800" cellpadding="0" cellspacing="0" border="0">
<?php   
// Station Information
					    //Setup connection to the database 
					    $connect = mysql_pconnect("localhost", "user", "pass") 
					    or die(mysql_error()); 

					    //Connect to the database 
						mysql_select_db("dbname", $connect) or die(mysql_error());    

					    // Perform an SQL query on the Address table    
						$sql_address = mysql_query("SELECT station_id, station_address, station_phone, station_ownership, network_affiliate, station_launch_date from station_info where station_id = '".$station."' order by station_launch_date") 

					    or die (mysql_error()); 
						   
						// Define the colours for the alternating rows 
						$colour_odd = "#FDFDEA"; 
						$colour_even = "#E0E0C7"; 
					    $row_count = 0;  //To keep track of row number 

					    // Fetch the array of records and Loop through them 
						while($results = mysql_fetch_array($sql_address)){ 
						// Decide which colours to alternate for the rows If Remainder of $row_count divided by 2 == 0. 
						$row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd; 

						//Echo the table row and table data that needs to be looped Check All With selected: over until the end of the recordset     
						echo ' 
						 <tr bgcolor="' . $row_color . '"> 
						  <td width=100 valign=top><p>Station Information<br>Station: ' .$results['station_id'] . '</p></td> 
						  <td width=200 valign=top><p><br>Station Address: ' .$results['station_address'] . '</p></td> 
						  <td width=150 valign=top><p><br>Station Phone #: ' .$results['station_phone'] . '</p></td>
						  <td width=100 valign=top><p><br>Ownership: ' .$results['station_ownership'] . '</p></td>
						  <td width=100 valign=top><p><br>Network Affiliate: ' .$results['network_affiliate'] . '</p></td>
						  <td width=150 valign=top><p><br>Launch Date: ' .$results['station_launch_date'] . '</p></td>					  
						  </tr>'; 

					   // Increment the row count 
						 $row_count++; } 
					   // Free the MySQL resource 
					   mysql_free_result($sql_address); 
					   // Close the database connection 
					   mysql_close($connect); 
?> 			
<br />

		</table>
		<table width="800" cellpadding="0" cellspacing="0" border="0">

<?php   
// Contact Log
					    //Setup connection to the database 
					    $connect = mysql_pconnect("localhost", "user", "pass") 
					    or die(mysql_error()); 

					    //Connect to the database 
						mysql_select_db("dbname", $connect) or die(mysql_error());    

					    // Perform an SQL query on the Address table    
						$sql_address = mysql_query("SELECT station_id, contact_date, contact_person, contact_kv, contact_notes from contact_log where station_id = '".$station."' order by contact_date") 

					    or die (mysql_error()); 
						   
						// Define the colours for the alternating rows 
						$colour_odd = "#FDFDEA"; 
						$colour_even = "#E0E0C7"; 
					    $row_count = 0;  //To keep track of row number 

					    // Fetch the array of records and Loop through them 
						while($results = mysql_fetch_array($sql_address)){ 
						// Decide which colours to alternate for the rows If Remainder of $row_count divided by 2 == 0. 
						$row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd; 

						//Echo the table row and table data that needs to be looped Check All With selected: over until the end of the recordset     
						echo ' 
						 <tr bgcolor="' . $row_color . '"> 
						  <td width=100 valign=top><p>Contact Log<br>Station: ' .$results['station_id'] . '</p></td> 
						  <td width=100 valign=top><p><br>Contact Date: ' .$results['contact_date'] . '</p></td> 
						  <td width=150 valign=top><p><br>Person Contacted: ' .$results['contact_person'] . '</p></td>
						  <td width=150 valign=top><p><br>KinderVision Contact: ' .$results['contact_kv'] . '</p></td>
						  <td width=300 valign=top><p><br>Contact Notes: ' .$results['contact_notes'] . '</p></td>
						  </tr>'; 

					   // Increment the row count 
						 $row_count++; } 
					   // Free the MySQL resource 
					   mysql_free_result($sql_address); 
					   // Close the database connection 
					   mysql_close($connect); 
?> 		
<br />
		</table>
		<table width="800" cellpadding="0" cellspacing="0" border="0">
<?php   
// Station Personnel
					    //Setup connection to the database 
					    $connect = mysql_pconnect("localhost", "user", "pass") 
					    or die(mysql_error()); 

					    //Connect to the database 
						mysql_select_db("dbname", $connect) or die(mysql_error());    

					    // Perform an SQL query on the Address table    
						$sql_address = mysql_query("SELECT station_id, general_manager, news_director, director_sales, community_affairs, kv_contact, email, phone, email2, phone2 from station_personnel where station_id = '".$station."' order by kv_contact") 

					    or die (mysql_error()); 
						   
						// Define the colours for the alternating rows 
						$colour_odd = "#FDFDEA"; 
						$colour_even = "#E0E0C7"; 
					    $row_count = 0;  //To keep track of row number 

					    // Fetch the array of records and Loop through them 
						while($results = mysql_fetch_array($sql_address)){ 
						// Decide which colours to alternate for the rows If Remainder of $row_count divided by 2 == 0. 
						$row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd; 

						//Echo the table row and table data that needs to be looped Check All With selected: over until the end of the recordset     
						echo ' 
						 <tr bgcolor="' . $row_color . '"> 
						  <td width=100 valign=top><p>Station Personnel<br>Station: ' .$results['station_id'] . '</p></td> 
						  <td width=100 valign=top><p><br>General Manager: ' .$results['general_manager'] . '</p></td> 
						  <td width=100 valign=top><p><br>News Director: ' .$results['news_director'] . '</p></td>
						  <td width=75 valign=top><p><br>Director of Sales: ' .$results['director_sales'] . '</p></td>
						  <td width=75 valign=top><p><br>Community Affairs: ' .$results['community_affairs'] . '</p></td>
						  <td width=50 valign=top><p><br>KinderVision Contact: ' .$results['kv_contact'] . '</p></td>
						  <td width=150 valign=top><p><br>Email: ' .$results['email'] . ' Phone: ' .$results['phone'] . '</p></td>
						  <td width=150 valign=top><p><br>Email2: ' .$results['email2'] . ' Phone2: ' .$results['phone2'] . '</p></td>
						  </tr>'; 

					   // Increment the row count 
						 $row_count++; } 
					   // Free the MySQL resource 
					   mysql_free_result($sql_address); 
					   // Close the database connection 
					   mysql_close($connect); 
?> 	
</html>

 

 

Link to comment
Share on other sites

as far as syntax goes, tables and field names go in back ticks "`" which is the one by the number one. values for the tables and fields should go in single quotes " ' ".

 

If that is your error it cannot be much clearer. you don't have that column name in your table. check the spelling, it also may be case sensitive as well depending on the OS.

 

Seems like all your tables contain the field station_id, is that correct?? Also if the tables are all in the same database there is no need to keep connecting to the server.

 

you only need to run these once at the top of the page

						    //Setup connection to the database 
					    $connect = mysql_pconnect("localhost", "user", "pass") 
					    or die(mysql_error()); 

					    //Connect to the database 
						mysql_select_db("dbname", $connect) or die(mysql_error()); 

 

Ray

 

Link to comment
Share on other sites

Sometimes i take people too literal and was wondering what scenario of these you were possibly referring to

 

Are you suggesting that the original code below:

$sql_address = mysql_query("SELECT station_id, station_address, station_phone, station_ownership, network_affiliate, station_launch_date from station_info where station_id = '".$station."' order by station_launch_date") 

 

be changed to :

$sql_address = mysql_query("SELECT `station_id`, `station_address`, `station_phone`, `station_ownership`, `network_affiliate`, `station_launch_date` from `station_info` where `station_id` = `".$station."` order by `station_launch_date`") 

 

or changed to (`".$station."`)

$sql_address = mysql_query("SELECT station_id, station_address, station_phone, station_ownership, network_affiliate, station_launch_date from station_info where station_id = `".$station."` order by station_launch_date") 

 

The answer to your question is , yes the field station_id is in every table (8 all together) and all of them are lower case and all have been spelled correctly as i just did re-check them.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.