Log in

View Full Version : Insert row in a mysql Database



pavmoxo
04-18-2006, 03:57 PM
I have:


<select name="year" id="year" tabindex="3">

<option value="<? echo date('Y'); ?>">
<? echo date('Y'); ?>

</option>

<option value="<? echo date('Y')-1; ?>">
<? echo date('Y')-1; ?>
</option>

<option value="<? echo date('Y')-2; ?>">
<? echo date('Y')-2; ?>
</option>

</select>
to list 3 years


And I want to correspond a number of documents for year to insert to a mysql DB:


PHP Code:

<?php

$sql = "select MAX(number)+1 as mynumber from actas2 where year=year(now());";
$query = mysql_query($sql);
print mysql_error();
$arr2 = mysql_fetch_object($query);


?>

<p><? echo $arr2->mynumber; ?></p>
<input type="hidden" name="number" value="<? echo $arr2->mynumber; ?>">

How I will join this two parts for insert?????

Twey
04-18-2006, 04:14 PM
Firstly, the above code can be simplified to:
<select name="year" id="year" tabindex="3">
<?php for($i=0;$i<3;$i++) { ?>
<option><?php echo(date('Y') - $i); ?></option>
<?php } ?>
</select>Secondly, I'm not entirely sure what you want to do, but to insert the year into the table, you'd use:
INSERT INTO actas2 (year) VALUES ($year);... where $year is a defined year and actas2 is the table.

pavmoxo
04-18-2006, 04:21 PM
You&#180;d understand me!!!

I want to insert the year and a number of document at the same time. If there are documents in DB of any year , it selects the last number e adds plus one.