How to INSERT 1 form answer to multiple table results.

allofus

New Member
Messages
183
Reaction score
2
Points
0
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.
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
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:

allofus

New Member
Messages
183
Reaction score
2
Points
0
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:
If you haven't already, I recommend reading Eric Raymond's guide to get prompt responses.

Such a great helper.
 
Last edited:

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
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:

allofus

New Member
Messages
183
Reaction score
2
Points
0
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.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:
$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:
$query="... values ('$file','$idcategoria','$name','$description','${file}_$file.mp3','$downloads','$click','$data','$rate','$trate','$screen1','$screen2','$demo','$autore','$idauth','$peso','$validate')";
 

allofus

New Member
Messages
183
Reaction score
2
Points
0
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.
 
Top