help with an insert code

Discussion in 'PHP' started by dougvcd, Aug 8, 2008.

  1. #1
    ok i have this code to insert into database from a form
    what i am trying to do is select which pic file should be entered
    this depends which type is selected on form
    eg if type = cat then pname = cat.jpg
    if type = dog then pname = dog.jpg
    if you see what i mean
    dont know where to put it
    cheers
    Doug

    <body>
     
     
    <?php 
    //This gets all the other information from the form
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $date = date("d-m-Y"); 
    
    // Connects to your Database 
     $dbh=mysql_connect("localhost", "caravan", "smu") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("carav"); 
    
    //Writes the information to the database 
    mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')");
     
    PHP:
     
    dougvcd, Aug 8, 2008 IP
  2. nhl4000

    nhl4000 Well-Known Member

    Messages:
    479
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #2
    //This gets all the other information from the form
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $date = date("d-m-Y"); 
    $pname=$type.".jpg";
    
    // Connects to your Database 
     $dbh=mysql_connect("localhost", "caravan", "smu") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("carav"); 
    
    //Writes the information to the database 
    mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')");
    PHP:
     
    nhl4000, Aug 8, 2008 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    big thanks for that good buddy
    works a treat
    cheers
    Doug
    :D
     
    dougvcd, Aug 8, 2008 IP