<?
$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.
Help w/ code
Moderator: General Moderators
declare
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
$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
but when i do that it doesn't show all the names in the database.
This is line 29
It still works w/ the error, so i am just thinking about hiding the error.
but i want to fix it.
This is line 29
Code: Select all
<?php
$option_block .="<option value=''$id''>$l_name,$f_name</option>";
?>but i want to fix it.