+ Reply to Thread
Results 1 to 8 of 8

Thread: How to INSERT 1 form answer to multiple table results.

  1. #1
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Question How to INSERT 1 form answer to multiple table results.

    Hi,

    I have a few questions related to MySQL and forms.

    I am editing a file-share to be a semi-automatic show-archive for our latest addition, an internet radio broadcast.

    Basically the shows are recorded and saved by date and hour

    2009063023

    would be a show on 6/30/2009 starting at 11pm.

    The files are then auto FTP to our server.

    I then want a form that hosts fill out to publish their show.



    Title
    Description
    Length etc etc


    The table has multiple fields that use the same answer 2009063023

    I can create a form with drop downs, or text fields,,, Year, Month, Day, Hour or 1 field that asks for the combination but how do I either get the 4 fields to be 1 submission and or get the 1 resulting answer to feature in several fields in the table...

    filename
    reference


    omg my question is more complicated to ask than answer I dare say.





    Also how can I mix hidden and user submitted info

    eg
    2009063023 + (hidden) .mp3

    Thansk for any assistance.

  2. #2
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: How to INSERT 1 form answer to multiple table results.

    You question is complicated, but that is not why you are not getting answered. Your question is riddled with logical and grammatical errors. Please post that question in a way that is easier to understand, with the problematic code in that post.

    1) Problem
    2) Question
    3) Code

    Then I am sure someone would be happy to help you
    Last edited by Twinkie; 06-30-2009 at 07:47 PM.

  3. #3
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: How to INSERT 1 form answer to multiple table results.

    If you haven't already, I recommend reading Eric Raymond's guide to get prompt responses.
    Last edited by xav0989; 06-30-2009 at 08:21 PM.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  4. #4
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Re: How to INSERT 1 form answer to multiple table results.

    Thanks Twinkie,


    Q. How do I turn 3 fields in a form into 1 INSERT in a MySQL table
    eg
    YY =2009
    MM = 07
    DD = 01
    HH = 23

    INSERT = 2009070123

    2009




    Q. How do I add the same field to several cells in the table

    ref = 2009070123
    filename = 2009070123_2009070123.mp3




    Q. can I combine txt, radial or drop-down with 'hidden' fields

    eg
    txt field = 2009070123 or YY + MM + DD + HH
    hidden = .mp3

    INSERT = 2009000123.mp3
    Edit:
    Quote Originally Posted by xav0989 View Post
    If you haven't already, I recommend reading Eric Raymond's guide to get prompt responses.
    Such a great helper.
    Last edited by allofus; 06-30-2009 at 11:35 PM. Reason: Automerged Doublepost

  5. #5
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: How to INSERT 1 form answer to multiple table results.

    1) If it is all in the same table then you could just use a standard insert:

    INSERT INTO tablename (column1,column2) VALUES (value1,value2);

    2) See above.

    3) You can do that anywhere, in client side with JavaScript, in PHP (best), or in the query itself.
    Code:
    <?php
    $con = mysqli_connect(...) or die("MySQL hates you.");
    
    $query = "INSERT INTO tablename (column1,column2) VALUES ({$_POST['value1']},{$_POST['value2']});";
    
    mysqli_query($con,$query) or die("Didn't work!");
    ?>
    You questions seems like you want to learn web programming. I recommend looking into w3schools.com. When you learn about the language you are coding in, your questions get to be more specific and less frequent.
    Last edited by Twinkie; 07-01-2009 at 01:22 AM.

  6. #6
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Thumbs up Re: How to INSERT 1 form answer to multiple table results.

    Code:
    $link = mysql_connect("localhost","***not-my-admin**","***not-my-password***");
    mysql_select_db("blabla",$link);
    $query="insert into TableName(id,idcategoria,name,description,file,downloads,click,data,rate,trate,screen1,screen2,demo,autore,idauth,peso,validate) values ('".$file."','".$idcategoria."','".$name."','".$description."','".$file."_".$file.".mp3','".$downloads."','".$click."','".$data."','".$rate."','".$trate."','".$screen1."','".$screen2."','".$demo."','".$autore."','".$idauth."','".$peso."','".$validate."')";
    mysql_query($query);
    
    header("Refresh: 0;url=http://4allofus.com/shows/britishnproud/complete.php");
    This works just fine, as you can see;

    Code:
    ".$file."','".$idcategoria."','".$name."','".$description."','".$file."_".$file.".mp3','
    Code:
    .$file.
    is repeatedly used


    Thanks for your help, all be it help that did not actually help me, I got it sorted.

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: How to INSERT 1 form answer to multiple table results.

    Did you sanitize the values you insert using (e.g.) mysql_escape_string or one of the filter functions? You don't want to leave your script open to SQL injection

    PHP Code:
    $validKeys=array(
      
    'year'=>0'month' => 0'day' =>0'hour' => 0,
      
    'name' => 0'description' => 0,
      ...
    );
    $row array_intersect_key(array_map('mysql_escape_string'$_POST), $validFields);
    $row['id'] = "$row[year]$row[month]$row[day]";
    $row['file'] = "$row[id].mp3";

    $fields implode('`,`'array_keys($row));
    $values implode("','"$row);
    $query "INSERT INTO $table (`$fields`) VALUES ('$values')"
    Also, if you've got a large number of strings that you're combining, using variable interpolation is more readable than string concatenation (and a little faster, though not appreciably so).
    PHP Code:
    $query="... values ('$file','$idcategoria','$name','$description','${file}_$file.mp3','$downloads','$click','$data','$rate','$trate','$screen1','$screen2','$demo','$autore','$idauth','$peso','$validate')"
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  8. #8
    allofus is offline x10 Sophmore allofus is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Wetherby, West Yorkshire, England
    Posts
    183

    Re: How to INSERT 1 form answer to multiple table results.

    Thanks mission,

    I actually installed adn sued 'phpFormGenerator' and then customised.

    I have trawled through many tutorials and frankly I find the sintax quite confusing and despite getting the general idea of how things work I get lost quickly when I attempt to code from scratch.

    Our website is built using mkportal, which 6 months into the project became a clear mistake, modification is quite difficult but so far I have managed to get most tasks done.

    mission I thank you for taking time out to write the above code and I am tryig to apply it to what I already have, but with little real success.

    That said, I have managed to get the form to do what I want it to do, so hooray.

    Now to get the page to pre-load some hidden fields so the hosts can stick to the basics, title, description, date...


    Code:
    <?php echo $txt'<? ($_GET['host']);?>_show_title'; ?>
    Why won't this work? I have the string in the url, the $txt array but for the love of god I can't get it to work.

+ Reply to Thread

Similar Threads

  1. MySQL Issues Here
    By Corey in forum Service Alerts
    Replies: 304
    Last Post: 01-06-2008, 09:10 PM
  2. Enabling IP addresses in your firewall.
    By 1337scape in forum Free Hosting
    Replies: 32
    Last Post: 11-15-2007, 01:40 PM
  3. INSERT command denied??
    By 1337scape in forum Free Hosting
    Replies: 6
    Last Post: 11-14-2007, 05:15 PM
  4. Table inside table
    By wizeman in forum Tutorials
    Replies: 4
    Last Post: 07-11-2005, 05:56 PM
  5. Mod Help
    By Ericsson in forum Free Hosting
    Replies: 4
    Last Post: 03-04-2005, 03:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers