Jump to content


Photo

SQL Insert - Text Boxes


  • Please log in to reply
4 replies to this topic

#1 aeafisme23

aeafisme23
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationUSA

Posted 04 August 2006 - 03:37 PM

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 :)

// 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());

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


#2 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 04 August 2006 - 03:45 PM

// 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());


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 "name" each input box should have in order to run these queries?

// 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')";


#3 aeafisme23

aeafisme23
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationUSA

Posted 04 August 2006 - 03:50 PM

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!

#4 aeafisme23

aeafisme23
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationUSA

Posted 04 August 2006 - 04:25 PM

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.


#5 aeafisme23

aeafisme23
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationUSA

Posted 04 August 2006 - 04:48 PM

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{
  ?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users