You are here: Re: PHP and Dropdowns « PHP Programming Language « IT news, forums, messages
Re: PHP and Dropdowns

Posted by Gordon Burditt on 10/26/14 11:34

>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");

Check the result of mysql_connect(). Did it fail?

>mysql_select_db("test");

Check the result of mysql_select_db(). Did it fail?

>
>if($submit)

What sets this value? Should it be $_POST['submit']?

>{
>
> $result=MYSQL_QUERY("INSERT INTO birhtday (id,name,day,month,year)".

Is the name of your table spelled correctly?

> "VALUES ('NULL', '$id','$name', '$day', '$month', '$year')");

You have 5 fields and 6 values here. What sets these values?
Inserting 'NULL' is unlikely to be what you want, do you instead
want to insert null (no quotes)? Watch out for SQL injection attacks.

>}
>?>
> <?
>
>$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>
>

Gordon L. Burditt

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация