Hi, newbie here just been going through the "Sam's Teach Yourself - PHP, MySQL" book. I've retyped the code for viewing records in an address book.

My problem is this line appears to have a problem. Does it look correct?

$get_list_sql = "SELECT id, CONCAT_WS (', ', l_name,f_name) AS display_name FROM master_name ORDER BY l_name, f_name";

the error I receive from this is...

FUNCTION address_book.CONCAT_WS does not exist

Here is more of the code if it helps out.

if(!$_POST){
// havent seen the selections yet so show them.
$display_block ="<h1>Select an Entry</h1>";

//get parts of records, name and id
$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 = mysqli_query($mysqli,$get_list_sql) or die (mysqli_error($mysqli));


if(mysqli_num_rows($get_list_res)<1){
// if there are no records tell the person that.

$display_block .= "<p><em>Sorry, there are no records to select</em></p>";

}else{
//if there is records

$display_block .= "<form method= \"POST\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Select a record</strong></p><br />
<select name=\"sel_id\">
<option value=\"\">-- Select One --</option>";

while ($recs = mysqli_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><p><input type =\"submit\" name=\"submit\" value=\"View Selected Entry\"></p>
</form>";
}
}

Any help would be great. Thanks in advance.

you can't have the space after CONCAT_WS and you also need a comma after id

select id , CONCAT_WS(', ', l_name,f_name)

thank you, that fixed that problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.