Jump to content

Archived

This topic is now archived and is closed to further replies.

aeafisme23

SQL Insert - Text Boxes

Recommended Posts

I am wanting to know how you assign the input text boxes below the particular SQL query since they are populating different tables in a database. I am assuming the code i need to insert is into the name? like name=[?php sql yadda yadda]. I have no clue :)

[code]// Write the queries
$sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";
$sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')";
$sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')";

// Execute the queries
mysql_query($sql) or die(mysql_error());
mysql_query($sql2) or die(mysql_error());
mysql_query($sql3) or die(mysql_error());[/code]

and i have 3 input boxes:

<INPUT TYPE=text NAME="make" ID="make" SIZE="25" MAXLENGTH="60">
<INPUT TYPE=text NAME="model" ID="model" SIZE="45" MAXLENGTH="60">
<INPUT TYPE=text NAME="submodel" ID="submodel" SIZE="60" MAXLENGTH="60">


THANKS

Share this post


Link to post
Share on other sites
[quote]
[code]
// Write the queries
$sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";
$sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')";
$sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')";

// Execute the queries
mysql_query($sql) or die(mysql_error());
mysql_query($sql2) or die(mysql_error());
mysql_query($sql3) or die(mysql_error());
[/code]
[/quote]

LOL, that code looks familiar.

Let me clarify what you are asking. Are you wanting to populate your input text boxes with values that already exist in the database, or are you wanting to know what "[b]name[/b]" each input box should have in order to run these queries?

[code]
// Write the queries
$sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";
$sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')";
$sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')";
[/code]

Share this post


Link to post
Share on other sites
Hey its very good helping code i might add, it was just a pain to have to scroll that far. I do not have the values, this will be completely backend where a user will input all data into the form text boxes and will update somewhere else on the site (not relevant where). So as of right now the boxes have no value but a particular name of the text box that populates information to the appropriate tables in the database. Does this make more sense? Thank you again!

Share this post


Link to post
Share on other sites
After thinking about this and comparing it to other forms that update databases to one table, wouldnt it just work regardless without defining anything other than

// Write the queries
$sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";
$sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')";
$sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')";

// Execute the queries
mysql_query($sql) or die(mysql_error());
mysql_query($sql2) or die(mysql_error());
mysql_query($sql3) or die(mysql_error());

because the value/name/id will match the SQL values so it will just update to the database? Is this logic correct.

Share this post


Link to post
Share on other sites
Fatal error: Allowed memory size of 18388608 bytes exhausted (tried to allocate 12 bytes) in /home2/admin/kindervision-www/anthonydwayne/add.php on line 15

I just got this message when i inserted data into the input fields, i looked at my database and it's filled up by the same input thousands of times!!!!! woah!

heres mysql connection crap:

<?php
if ($submit) {
  // process form
$db = mysql_connect("www.afdsfdfdasf.org", "asdf", "afdasdfasdfas");
mysql_select_db("fasdfadfaf_org",$db);
// Write the queries
$sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";
$sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')";
$sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')";

// Execute the queries
mysql_query($sql) or die(mysql_error());
mysql_query($sql2) or die(mysql_error());
mysql_query($sql3) or die(mysql_error());
 
  $result = mysql_query($sql); //could this be my problem because i dont have $sql2 and 3? wehres my exit too?
  require("add.php");
  echo('thank you for your add');
} else{
  ?>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.