can anyone tell me why this code does not work? it's suppsed to give back a name from the database but it always returns blank.

//connect to database
	$mysql = mysql_connect("localhost", "root", "")
		or die ("couldn't connect to server");
	$mysql .= mysql_select_db("addressbook", $mysql)
		or die (mysql_error());
if (!$_POST) {
	//havent seen the selection form, so show it
	$display_block = "<h1> Select an entry</h1>";
	echo $display_block;
	//get parts of records
	$get_list_sql = "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_sql)
		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>";
		echo $display_block;
	} else {
		//has records so get results and print in form
		$display_block = " <form method='POST'><P><strong>Select a record to view:</strong></p><br /> <select name='sel_id'><option value= ''>-- select one--</option>";
		echo $display_block;
	while ($recs =mysql_fetch_array($get_list_res)) {
		$id = $recs['id'];
		$display_name = stripslashes($recs["display_name"]);
		$display_block = "<option value= '.$id.'> $display_name</optioin>";
		echo $display_block;
	$display_block = "</select><p><input type='submit' name='submit' value = 'view selected entry'></p></form>";
	echo $display_block;
	//free result
} elseif ($_POST) {
	//check for required fields
		if ($_POST["sel_id"] == "") {
			header("location: selentry.php");
		$sel_id = $_POST['sel_id'];
		$get_list_sql= "SELECT l_name FROM master_name WHERE id = '".$sel_id."'";
		$get_list_res = mysql_query($get_list_sql)
		or die (mysql_error());
         $display_name = stripslashes($get_list_res);
         echo "<h1>showing records for ", $display_name"</h1>
<title>My Records</title>

$mysql .= mysql_select_db("addressbook", $mysql)
		or die (mysql_error());

strip out "$mysql .=". The dot operator is used for concatenating strings, not ressources.

This article has been dead for over six months. Start a new discussion instead.