My first guess was from the volume of errors, you're not connecting to 
the database.
You'd typically get a bunch of errors at your queries, because you're 
not supplying a valid database handle.

Looking closer, I don't think that's the case...

You've done a good thing by putting your queries in a string, then 
passing them to mysql_query().
If you're not sure about the syntax, var_dump or echo it, then test it 
in your mysql client (CLI or phpMyAdmin).
If your query is broken, that's a good way to find out why.

$get_list = "select id, concat_ws(', ', l_name, f_name) as display_name from 
master_name order by l_name, f_name"; 

var_dump($get_list);

/* or if you're slick
if(DEBUG == true) { 
        var_dump($get_list);
}
*/

$get_list_res = mysql_query($get_list)

I think this query here should read (note the double quotes):

SELECT id, concat_ws('','','l_name','f_name') AS display_name FROM 
master_name ORDER BY lname, fname

IF concat_ws is a PHP function and not a MySQL function (I don't feel 
like looking right now... sorry) then you probably want:

$get_list = 'SELECT id, ' .  concat_ws('','',l_name,'f_name') . ' AS 
display_name FROM master_name ORDER BY lname, fname';

Same thing here, you can't use associative arrays inside of quotes, 
you've got to append it to the string like this:

$get_addresses = "SELECT address, city, state, zipcode, type FROM address WHERE 
master_id = '" . $_POST[sel_id] . "'";

Those seem to be the themes here... just apply these to the broken queries, and 
you should be on the right track.


When you've got some time, check out PEAR DB (pear.php.net) and Smarty 
(smarty.php.net).  
Using them would improve and simplify your code tremendously.

You might also want to think about putting some of this stuff into functions or 
classes.

$addresses = get_addresses($_POST['sel_id']); 
$smarty->assign("addresses",$addresses);

Is much easier and clearer to read than: 

        //Get All addresses 
        $get_addresses = "select address, city, state, zipcode, type from 
address where master_id = $_POST[sel_id]"; 
        $get_address_res = mysql_query($get_addresses); 
                         
        if (mysql_num_rows($get_addresses_res) > 0) { 
         
                $display_block .= "<P><STRONG>Address:</STRONG><BR> 
                <UL>"; 
         
                while ($add_info = mysql_fetch_array($get_addresses_res)) { 
                        $address = $add_info[adress]; 
                        $city = $add_info[city]; 
                        $state = $add_info[state]; 
                        $zipcode = $add_info[zipcode]; 
                        $address_type = $add_info[type]; 
                 
                        // You'll probably want to fix this typo: ($zipecode)
                        $display_block .= "<LI>$address $city $state $zipecode 
($address_type)"; 
                } 
         
                $display_block .= "</UL>"; 
        } 

Note there's no HTML in the first example, either.  If your graphic 
designer decides this stuff needs to be in another format, or you want 
to display it as XML for something else, you're modifying all of this, 
instead of just adding an XML output funtion.

Oh, one last picky thing.

Using $_POST[sel_id] is incorrect.  $_POST['sel_id'] is the proper way 
to reference a key in an associative array.

In your instance, sel_id is first evaluated as a constant, not a 
string.  While the odds that you've defined sel_id as a constant 
elsewhere in your app are slim, PHP would grab the value from the 
constant instead of using the string 'sel_id' as a key.

example:
<?php

$_POST = array ([0] => 'something', 'sel_id' => 'something else');

echo $_POST[sel_id];
// output: something else

define('sel_id',0)
echo $_POST[sel_id];

// output: something
echo $_POST['sel_id'];

// output: something else
?>

While you can probably get away with it if you're the only developer, it 
could create mysterious and hard-to-find errors in a large application.  
You'd definitely want to use it correctly in code samples if you're 
applying for a PHP development gig.  :)

Best,
Jeromie

matt wrote:

>Here is the code. 
><?php 
>//Connect to database 
>$conn = mysql_connect("localhost", "someuser", "somepass") 
>       or die(mysql_error()); 
>mysql_select_db("PhoneBook",$conn) or die(mysql_error()); 
> 
>if ($_POST[op] != "view") { 
>       //Haven't seen the form, so show it 
>       $display_block = "<H1>Select an Entry</H1>"; 
>        
>       //get parts of records 
>       $get_list = "select id, concat_ws(', ', l_name, f_name) as 
>display_name 
>               from master_name order by l_name, f_name"; 
>       $get_list_res = mysql_query($get_list) or 
>die(mysql_error()); 
>        
>       if (mysql_num_rows($get_list_res) < 1) { 
>       //no records 
>       $display_block .= "<P><EM>Sorry, no records to 
>select!</EM></P>"; 
>        
>       } else { 
>               //has records, so get results and print in a form 
>               $display_block .= " 
>               <FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\"> 
>               <P><STRONG>Slect a record to view:</STRONG></BR> 
>               <SELECT NAME=\"sel_id\"> 
>               <OPTION VALUE=\"\"> --SELECT ONE-- </OPTION>"; 
>                
>               while ($recs = mysql_fetch_array($get_list_res)) { 
>                       $id = $recs['id']; 
>                       $display_name = 
>stripslashes($recs['display_name']); 
>                        
>                       $display_block .= "<OPTION VALUE=\"$id\"> 
>                               $display_name</OPTION>"; 
>               } 
>               $display_block .= " 
>               </SELECT> 
>               <INPUT TYPE=\"hidden\" NAME=\"op\" VALUE=\"view\"> 
>               <P><INPUT TYPE=\"submit\" NAME=\"submit\" 
>                       VALUE=\"View Selected Entry\"></P> 
>               </FORM>"; 
>       } 
> 
>} else if ($_POST[op] == "view") { 
>        
>       //Check for required fields 
>       if ($_POST[sel_id] == "") { 
>               header("Location: selentry.php"); 
>               exit; 
>       } 
>        
>       //Get master_info 
>       $get_master = "select contact_ws(' ', f_name, l_name) as 
>display_name 
>               from master_name where id = $_POST[sel_id]"; 
>       $get_master_res = mysql_query($get_master); 
>       $display_name = stripslashes(mysql_result($get_master_res, 
>               0, 'display_name')); 
>       $display_block = "<H1>Showing Record for 
>$display_name</H1>"; 
>       //Get All addresses 
>       $get_addresses = "select address, city, state, zipcode, type 
>               from address where master_id = $_POST[sel_id]"; 
>       $get_address_res = mysql_query($get_addresses); 
>                        
>       if (mysql_num_rows($get_addresses_res) > 0) { 
>        
>               $display_block .= "<P><STRONG>Address:</STRONG><BR> 
>               <UL>"; 
>        
>               while ($add_info = 
>mysql_fetch_array($get_addresses_res)) { 
>                       $address = $add_info[adress]; 
>                       $city = $add_info[city]; 
>                       $state = $add_info[state]; 
>                       $zipcode = $add_info[zipcode]; 
>                       $address_type = $add_info[type]; 
>                
>                       $display_block .= "<LI>$address $city $state 
>$zipecode 
>                               ($address_type)"; 
>               } 
>        
>               $display_block .= "</UL>"; 
>       } 
>        
>       //Get All Telephone Numbers 
>       $get_tel = "select tel_number, type, from telephone where  
>               master_id = $_POST[sel_id]"; 
>       $get_tel_res = mysql_query($get_tel); 
>                        
>       if (mysql_num_rows($get_tel_res) > 0) { 
>        
>               $display_block .= 
>"<P><STRONG>Telephone:</STRONG><BR> 
>               <UL>"; 
>        
>               while ($tel_info = mysql_fetch_array($get_tel_res)) 
>{ 
>                       $tel_number = $tel_info[tel_number]; 
>                       $tel_type = $tel_info[type]; 
>                
>                       $display_block .= "<LI>$tel_number 
>($tel_type)"; 
>               } 
>        
>               $display_block .= "</UL>"; 
>       } 
>        
>       //Get All Fax Numbers 
>       $get_fax = "select fax_number, type, from fax where  
>               master_id = $_POST[sel_id]"; 
>       $get_fax_res = mysql_query($get_fax); 
>                        
>       if (mysql_num_rows($get_fax_res) > 0) { 
>        
>               $display_block .= "<P><STRONG>Fax:</STRONG><BR> 
>               <UL>"; 
>        
>               while ($fax_info = mysql_fetch_array($get_fax_res)) 
>{ 
>                       $fax_number = $fax_info[fax_number]; 
>                       $fax_type = $fax_info[type]; 
>                
>                       $display_block .= "<LI>$fax_number 
>($fax_type)"; 
>               } 
>        
>               $display_block .= "</UL>"; 
>       } 
>        
>       //Get All E-Mail 
>       $get_email = "select email, type, from email where  
>               master_id = $_POST[sel_id]"; 
>       $get_email_res = mysql_query($get_email); 
>                        
>       if (mysql_num_rows($get_email_res) > 0) { 
>        
>               $display_block .= "<P><STRONG>Email:</STRONG><BR> 
>               <UL>"; 
>        
>               while ($email_info = 
>mysql_fetch_array($get_email_res)) { 
>                       $email_number = $fax_info[email]; 
>                       $email_type = $fax_info[type]; 
>                
>                       $display_block .= "<LI>$femail 
>($email_type)"; 
>               } 
>        
>               $display_block .= "</UL>"; 
>       } 
>        
>       //Get Personal Note 
>       $get_notes = "select note from personal_notes where  
>               master_id = $_POST[sel_id]"; 
>       $get_notes_res = mysql_query($get_notes); 
>                        
>       if (mysql_num_rows($get_notes_res) == 1) { 
>               $note = 
>n12br(stripslashes(mysql_result($get_notes_res,0,'note'))); 
>        
>               $display_block .= "<P><STRONG>Personal 
>Notes:</STRONG><BR>$note"; 
>       } 
>                
>       $display_block .= "<BR><BR><P align=center> 
>               <A HREF=\"$_SERVER[PHP_SELF]\">Select 
>Another</A></P>"; 
>} 
>?> 
> 
><HTML> 
><HEAD> 
><TITLE>Select Entry</TITLE> 
></HEAD> 
><BODY> 
><?php echo $display_block; ?> 
><HR> 
><!--Footer Menu--> 
><P><A HREF="index.php">Main Menu</A> | <A HREF="mymenu.php">Phone 
>Menu</A>  
>       | <A HREF="addentry.php">Add Entry</A> | <A 
>HREF="delentry.php">Delet Entry</A> |  
>       Veiw Entries 
></BODY> 
></HTML> 
> 
>Thank you, 
>Matthias Urankar 
>
>
>
>
>
>The PHP_mySQL group is dedicated to learn more about the PHP_mySQL web 
>database possibilities through group learning.  
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>  
>


The PHP_mySQL group is dedicated to learn more about the PHP_mySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to