...

View Full Version : form question



pphpnewbie
01-23-2010, 02:16 AM
Is there a mistake with this form - when a user select the project from the drop down the year should show up accordingly to the project selected but I get this result:


9<br /> <b>Notice</b>: Undefined index: year in <b>C:\wamp\www\project\0_insert.php</b> on line <b>72</b><br /> from the Year field.


<form id="form1" name="form1" method="post" action="">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project:</td>
<td><label>
<select name="project" id="project">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['acr_id']?>"><?php echo $row_Recordset1['project']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label></td>
<td>Year:</td>
<td><label>
<input name="year" type="text" id="year" value="<?php echo $row_Recordset1['acr_id']?><?php echo $row_Recordset1['year']; ?>" />
</label></td>
</tr>

Thanks in advanced.

seco
01-23-2010, 02:39 AM
is this the 0_insert.php file?

pphpnewbie
01-23-2010, 05:21 AM
is this the 0_insert.php file?

yes it is. the project session of the form supposed to be dynamically populated when the user select the project. then they will type in other infos in other fields before summiting the form.

Thanks.

_Aerospace_Eng_
01-23-2010, 10:19 AM
Where is your $Recordset1 query? Do you have a column in you db table called year? Also in your select are you calling that column from your table? If you aren't then you will get the index notice.

pphpnewbie
01-23-2010, 11:02 AM
Where is your $Recordset1 query? Do you have a column in you db table called year? Also in your select are you calling that column from your table? If you aren't then you will get the index notice.


SELECT *
FROM admin_project
ORDER BY project ASC

Yes, there is a 'year' col. in the table. Now the year did show out. But I just cannot make it sync with the selected project from the drop down menu. Thanks.

oesxyl
01-23-2010, 12:06 PM
SELECT *
FROM admin_project
ORDER BY project ASC

Yes, there is a 'year' col. in the table. Now the year did show out. But I just cannot make it sync with the selected project from the drop down menu. Thanks.
you need to have the option like this:


<option value="year_value" selected="selected">year_value</option>

this for xhtml, your question is in fact a html/css question, :)

best regards

pphpnewbie
01-23-2010, 12:33 PM
<option value="year_value" selected="selected">year_value</option>


Thanks. Would you kindly show me where to insert that code in my form:

<form id="form1" name="form1" method="post" action="">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project:</td>
<td><label>
<select name="project" id="project">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['acr_id']?>"><?php echo $row_Recordset1['project']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label></td>
<td>Year:</td>
<td><label>
<input name="year" type="text" id="year" value="<?php echo $row_Recordset1['year']; ?>" />
</label></td>
</tr>

Thanks

oesxyl
01-23-2010, 01:33 PM
<option value="year_value" selected="selected">year_value</option>


Thanks. Would you kindly show me where to insert that code in my form:

<form id="form1" name="form1" method="post" action="">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project:</td>
<td><label>
<select name="project" id="project">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['acr_id']?>"><?php echo $row_Recordset1['project']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label></td>
<td>Year:</td>
<td><label>
<input name="year" type="text" id="year" value="<?php echo $row_Recordset1['year']; ?>" />
</label></td>
</tr>

Thanks
why do you use a do-while when you need a while? $row_Recordset1['acr_id'] and $row_Recordset1['project'] are undefined until you fetch them using $row_Recordset1 = mysql_fetch_assoc($Recordset1).



while($row_Recordset1 = mysql_fetch_assoc($Recordset1)){
print ' <option value="';
print $row_Recordset1['acr_id'];
print '"';
if(.....){ // I don't know what field from $row_Recordset1 and what variable to compare here, change this to what you know you need
print ' selected="selected"';
}
print '>'. $row_Recordset1['project'] . '</option>';
}


best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum