Page 1 of 1

Help w/ code

Posted: Thu Aug 21, 2003 1:07 pm
by salgonza
<?

$db_name ="testDB";
$table_name ="my_contact";

//connect to server and select database
$connection = @mysql_connect("localhost","spike","9sj7En4") or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());

//build and issue query
$sql ="SELECT id, f_name, l_name FROM $table_name ORDER BY l_name";
$result = @mysql_query($sql,$connection) or die(mysql_error());

//check the number of results
$num = @mysql_num_rows($result);

if ($num < 1) {
//if there are no results,display message
$display_block = "<P><em>Sorry!No results.</em></p>";

} else {

//if results are found,loop through them
//and make a form selection block
while ($row =mysql_fetch_array($result)){
$id = $row['id'];
$f_name = $row['f_name'];
$l_name = $row['l_name'];
$option_block .="<option value=''$id''>$l_name,$f_name</option>";

}

//create the entire form block
$display_block ="
<FORM METHOD=\"POST\" ACTION=\"show_modcontact.php\">
<P><strong>Contact:</strong>
<select name=\"id\">
$option_block
</select>

<INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"Select this Contact\"></input></P>
</form>";

}
?>


That is my code. however when i run the page, i get an error message for line 29.

Apache 2.0.47 (win)
MySQL 4.0.14b
PHP Version 4.3.2

Could it possibly be a conflict in versions of software that i am using?
or if not, can you please help w/ my code.

Thanks in advance.

Posted: Thu Aug 21, 2003 1:09 pm
by salgonza
Notice: Undefined variable: option_block in C:\Program Files\Apache Group\Apache2\htdocs\pick_modcontact.php on line 29

That is the error i get, sorry forgot to put it in the original post.

line 29

Posted: Thu Aug 21, 2003 1:10 pm
by phpScott
what is line 29 and what error do you get.

phpScott

beat me to it

declare

Posted: Thu Aug 21, 2003 1:14 pm
by phpScott
before you start doing
$optionBlock.="";

you should just assign a value to $optionBlock like
$optionBlock="";

PHP has know idea what the orginal value of optionBlock is before you start trying to concatinate things to it and this caused the problem.

phpScott

Still not working! Argh

Posted: Thu Aug 21, 2003 2:27 pm
by salgonza
but when i do that it doesn't show all the names in the database.

This is line 29

Code: Select all

<?php
$option_block .="<option value=''$id''>$l_name,$f_name</option>"; 

?>
It still works w/ the error, so i am just thinking about hiding the error.
but i want to fix it.