Forms and PHP

Discuss all aspects of programming here.

Moderator: The Mod Squad

Forms and PHP

Postby Falklian » Thu Mar 17, 2005 4:20 pm

On my website I have a news submission form, with a dropdown box for a person to enter his/her name. Since I'm the only one who ever posts any news, I figured everything was working correctly. Well, today I added a new user and found out it is broken :oops:

This is what I have:

Code: Select all
<select name="name">
  <option value="" selected>---Select---</option>
  <option value="Athaniel">Athaniel</option>
  <option value="Borador">Borador</option>
  <option value="Fayrwel">Fayrwel</option>
  <option value="Unsane">Unsane</option>
  <option value="Verdin">Verdin</option>

Now, originally I figured the value would end up in the name variable. Silly me, it doesn't seem to work that way. It seems the very last name in the list is always stored in the name variable. I've selected the other names and the last name ends up in the variable, I've even not selected a name and I get the same results.

Here's my PHP code:

Code: Select all
  $date = date("l dS of F Y h:i:s A");
  if(empty($title) || empty($text) || empty($name))
    echo "You didn't completely fill in the form!  Please click the back button on your browser and make sure you filled out the name, article title, and news item sections.";
    echo "Thank you for submitting a news item!  Please return to the index page to see your post!";
    mysql_query("INSERT INTO news (name,date,title,text) VALUES ('$name','$date','$title','$text')");

The form method is POST by the way.

Edit: Nevermind! I fixed it! I changed <select name="name"> to <select name="toon"> and it works now! Seems you shouldn't assign the value "name" to a variable called "name" :wink:
Black Belt
Black Belt
Posts: 921
Joined: Tue Oct 01, 2002 2:06 pm
Location: Illinois

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest