|
Posted by Christopher Pomasl on 10/24/33 11:34
On Mon, 12 Dec 2005 00:34:51 -0800, ire.kevin wrote:
> I'm creating a birthday list creator. Using drop down menus for day,
> month, and year. I can manually insert data into my table and have it
> displayed. But I can't get my forumn to submit the data to the
> database.
>
> I have labeled "MySQL Table" , "PHP", and "HTML" below for easy
> reading. This is all on one page.
>
> What am I doing wrong?
>
> ------------------
> MySQL Table
> ------------------
> id int(11) No auto_increment
> name text No
> day int(2) No 0
> month int(2) No 0
> year int(4) No 0
>
>
> ------------------
> PHP
> ------------------
>
> <?
> mysql_connect("localhost","irekevin_irekevi","k24a2");
>
> mysql_select_db("test");
>
> if($submit)
> {
>
> $result=MYSQL_QUERY("INSERT INTO birhtday (id,name,day,month,year)".
> "VALUES ('NULL', '$id','$name', '$day', '$month', '$year')");
> }
> ?>
> <?
>
> $result = mysql_query("select * from birhtday order by month desc limit
> 1");
>
> while($r=mysql_fetch_array($result))
> {
> $name=$r["name"];
> $day =$r["day"];
> $month=$r["month"];
> $year=$r["year"];
>
> ?>
> <div class="box">
> <div class="name"><? echo $name ?></div>
> <div class="day"><? echo $day ?></div>
> <div class="month"><? echo $month ?></div>
> <div class="year"><? echo $year ?></div>
> <br />
> <br />
> </div>
> </div>
>
> <? } ?>
>
> ------------------
> HTML
> ------------------
>
> <form action="<? echo $php_self ?>" method="post">
> <br />
> <input id="name" type='text' value='Name' name='name' size="15"
> maxlength='100'>
> <input type="submit" name="submit" value="Submit"/>
> <br />
> <select name="day">
> <option value="1">01</option>
> <option value="2">02</option>
> etc...
> </select>
>
> <select name="month">
> <option value="01">January</option>
> <option value="02">February</option>
> <option value="03">March</option>
> etc....
> </select>
>
> <select name="year">
> <option value="1970">1970</option>
> <option value="1971">1971</option>
> etc...
> </select>
> </form>
Interesting. I know that you reported that you fixed it already but I
question something here. At least with the SQL I work with normally, DB2
on Z/OS, the values must match the defined column types. You have quotes
around the supposed integer values which seems incongruous to me but MySQL
may allow it.
Also, unless you REALLY need to, I would format the month, day and year
into a date column rather than 3 separate integers in your DB. This way
you can do better date sorting and comparisons if you need to.
You had the right idea with the null value for an auto-increment column,
you just included two value for it. You should have coded it as:
(null,'$name'...etc and leave out the extra '$id'. The null will allow
the DB engine to do the auto-increment.
So my recommendation is more along the lines of:
------------------
MySQL Table
------------------
id int(11) No auto_increment
name text No
date date No today()
------------------
PHP
------------------
....
$isodate = sprintf ("%04d-%02d-%02d", $year, $month, $day);
$result=MYSQL_QUERY("INSERT INTO birhtday (id,name,date)".
"VALUES (NULL, '$name', '$isodate')");
....
HTH,
Chris
Always remember, you are unique...just like everyone else.
[Back to original message]
|