Jump to content


Photo

insert into MySQL from form list-box


  • Please log in to reply
3 replies to this topic

#1 marcs910

marcs910
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 19 June 2006 - 03:53 PM

Ive searched and found a couple of ways this can be done but they arent matching up with what Ive used.
Im currently reading "PHP and MySQL For Dynamic Web Sites" by Larry Ullman and this is where I am learning my code.

What I'm trying to do is create a dropdown menu item to insert into a db. The codes I've tried from here isnt working with what I have. It creates the dropdown but never inserts the value. I'm including two textboxes that are working correctly, above and below in the form code.

What will fix this or what am I doing wrong? Thanks [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

The SQL code im using:

if (isset($_POST['submitted'])) {

  require_once ('mysql_connect.php');
  
   $query = "INSERT INTO homes (category, type, address, location, zip, year, bedroom, bathroom, garage, lotsize, stories, active, price, description, date_entered) 
   VALUES ('$category', '$type', '$address', '$location', '$zip', '$year', '$bedroom', '$bathroom', '$garage', '$lotsize', '$stories', '$active', '$price', '$description', NOW())";
   $result = @mysql_query ($query);
   

The form code I'm using:

<p>Category:<input type="text" name="category" size "15" maxlength="15" value="<?php if
    (isset($_POST['category'])) echo$_POST['category']; ?>" /></p>
    
    <p>Active:<select size="1" name="active">
    <option selected value="<?php if
    (isset($_POST['active'])) echo$_POST['active']; ?>">Y</option>
    <option value="<?php if
    (isset($_POST['active'])) echo$_POST['active']; ?>">N</option>
    </select></p>


    <p>Type:<input type="text" name="type" size "15" maxlength="15" value="<?php if
    (isset($_POST['type'])) echo$_POST['type']; ?>" /></p>


#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 19 June 2006 - 07:45 PM

Your form looks fine.
The problem I see is with the variable on the insert. You need to set $catagory, $type, and $active.
I believe you rcode would only work of global variable are turned on, which they are not by default and should not be.

if(isset($_POST['category'])){
$category = $_POST['category''];
}else{
$category = '';
}

Each one would have to be set

Ray

#3 marcs910

marcs910
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 19 June 2006 - 08:02 PM

[!--quoteo(post=385779:date=Jun 19 2006, 03:45 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Jun 19 2006, 03:45 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your form looks fine.
The problem I see is with the variable on the insert. You need to set $catagory, $type, and $active.
I believe you rcode would only work of global variable are turned on, which they are not by default and should not be.

if(isset($_POST['category'])){
$category = $_POST['category''];
}else{
$category = '';
}

Each one would have to be set

Ray
[/quote]

Even if the rest of the fields are working fine?

#4 marcs910

marcs910
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 21 June 2006 - 12:30 PM

*bimp*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users