-1

I have a form that works perfectly. I have a table for each categorie in my database. i would like to send values straight into a categorie table that i will choose from the categorie input in the form i tried doing this but it did not work! Any ideas?? thanx alot

$categorie=$_POST['categorie'];
$sql = "INSERT INTO '$categorie' (title, price, description, urlimage) VALUES ('$ad_title', '$ad_price', '$ad_description', '$ad_photo') ";
$conn->query($sql);


<form method="post" role="form" action="" enctype="multipart/form-data">                   
    <div class="row">
        <div class="col-lg-12 padding-top-10">
            <label for="title" class="control-label">Titre</label>
            <input type="text" class="form-control" name="title" placeholder="Title" required></input>
        </div>                                
    </div>
    <div class="row">
        <div class="col-lg-12 padding-top-10">
            <label for="price" class="control-label">Prix</label>
            <input type="text" class="form-control" name="price" placeholder="Price" required></input>
        </div>                     
    </div>
    <div class="row">
        <div class="col-lg-12 padding-top-10">
            <label for="categorie" class="control-label">categorie</label>
            <input type="text" class="form-control" name="categorie" placeholder="categorie" required></input>
        </div>                     
    </div>
    <div class="row">
        <div class="col-lg-12 padding-top-10">
            <label for="description" class="control-label">Description*</label>
            <textarea class="form-control" rows="5" name="description"></textarea> 
        </div>                      
     </div>  
     <div class="row">
        <div class="col-lg-12 padding-top-10">
            <label for="photo" class="control-label">Photo</label>
            <input type="file" class="form-control" name="photo" required></input>
        </div>                     
    </div>                   

                <div class="row">
        <div class="col-md-12 padding-top-10">   
            <button type="submit" class="btn btn-primary btn-lg btn-block" name="submit">Post</button>
        </div>      
   </div>                               
</form>    
u_mulder
  • 54,101
  • 5
  • 48
  • 64
Juju
  • 51
  • 5
  • What do you mean by *did not work*? – Fredster Jun 30 '16 at 10:50
  • form working perfectly? where is your code? what is working? – Alive to die - Anant Jun 30 '16 at 10:50
  • You have to use isset function for checking that your variables are set or not. Visit this link : [if-isset-post](http://stackoverflow.com/questions/13045279/if-isset-post) – Bhavin Jun 30 '16 at 10:50
  • i meant to form sends values to table correctly when i specify the table name in the INSERT INTO query. I would like to send values in a table that will be determined by the categorie input from the form. so I guess table becomes a variable becaue i don't know which categorie table my user will choose when fiiling the form. how can i write the php to insert the data directly in the categorie table selected in the form?? – Juju Jun 30 '16 at 10:57

1 Answers1

0

You should use " (double-quote) or ` back-ticks here.

$sql = "INSERT INTO `$categorie` ...
Fredster
  • 776
  • 1
  • 6
  • 16