Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To Insert Arrays Into Mysql Database


This is my order.php file. Now I try to make a new php-file for processing the ordered items on this page, into another table "ordered_products" in the database. I want to INPUT following values into the table "ordered_products":
'order_num', 'order_item' and 'order_ant'

I know how to insert rows in a table using the INSERT query, but I don't know how to do it while looping the arrays. I have to fetch the arrays from this page, and insert them row by row in the "ordered_products" table. Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Insert Multiple Arrays Into Mysql
I am having problems writing the code to generate my SQL INSERT query. I have 3 arrays and one static variable ($cat_number):

$track_name[]
$music_link[]
$track_number[]
$cat_number

Should I be using a foreach command. I know how to insert multiple values but its generating the query that i'm not sure about.

INSERT INTO table (track_name, music_link, cat_number, track_number)
VALUES
(var1,var2,var3,var4),
(var5,var6,var7,var8),
(var9,var10,var11,var12);

I don't want to store the actual array in the dataabase, I am just using an array to catch the data.

Insert Into Mysql Database
It sounds very simple, but for some reason I just can't figure it out, and it will save a lots of time to me, if someone can direct me into the right direction. I was trying to input data into mysql table through post method, but it was not working. I made it simple and just tried to enter anything from a php file, but it does not work, so there is something that i am doing wrong with the insertion query.

$link = mysql_connect($hostName, $userName, $password);
echo("connected");

mysql_select_db($databaseName, $link);
echo("database selected");
echo ($databaseName);

mysql_query("INSERT INTO image VALES('','','','','','','','','', 'hello', '', '', '','','','','')", $link);

echo ("done");

I am trying to enter into one of those fields, but it does not populate the table in mysql database.

How Do I INSERT A Value That Contains A Variable Into A MySQL Database?
I'm trying to insert values into my database that contain a variable
that gets incremented by one for each item in a shopping cart.
item_name becomes item_name1, item_name2, item_name3, and so on for
the total number of items in the cart.

This code works great when i only have one shopping cart item to deal
with.....

Text With Quote To Insert In A Mysql Database
i have a text field in a mysql database, how can i insert text with quote ( ' ).

Insert Data From Form To MySQL Database
I have run createTable.php and everything is created. Now I want to run insertData.php. I want the user to enter stuff in the form & everything must be fill in before they click the submit button. It will call submitData() & all the information was enter will insert into the database. PHP Code:

Pesky Checkbox Arrays And A MySQL Song Database
I'm not one who likes to ask for help, so for the last three days my brain has been turning to mush while I try to create a DJ Request Song Wish List. Anyone who can help me out will be saving me from severe insanity. :)

My goal is to:

1. Display search results for song title, artist and genre. (accomplished)
2. Allow the user to add songs to their Wish List. This is done by displaying checkboxes with the corresponding value equal to the songID. (working on it)
3. Allow the user to update their wishlist by adding/deleting songs.

So far I have a form that retrieves the song info from a database in a repeating region. In Dreamweaver:

<input name="songID[]" type="checkbox" id="songID[]" value="<b><?php echo $row_RecordsetSearchResults['Title'];?></b> by <?php echo $row_RecordsetSearchResults['Artist'];?>">

This puts the corresponding songID number into a checkbox value, which in turn is submitted by form POST action to the following page as an array.

To process this array I have:

if(isset($_POST['songID']))
{
$songID = $_POST['songID'];

print '<p>Song IDs:</p>'
// process items
$n = count($songID);
for($i = 0; $i <= $n; $i++)
{
//See if the values are being passed from POST
echo $songID[$i];
echo '<br>'
}
$songsInsert = '*'.implode('*',$_POST['songID']).'<br>'
$insertSQL = sprintf("INSERT INTO wishlist (Username, Title) VALUES (%s, %s)",
GetSQLValueString($MM_Username, "text"),
GetSQLValueString($songsInsert, "text"));

mysql_select_db($database_ToneDeaf, $ToneDeaf);

$Result1 = mysql_query($insertSQL, $ToneDeaf) or die(mysql_error());
}

The problem is, I'm using implode. It does store the songs, but only as one long block of text. So if the user picks "New York by Frank Sinatra" and "Hot In Here by Nelly" it is stored as "*New York by Frank Sinatra*Hot In Here by Nelly*" Obviously this gives me no options to make this actually readable, let alone allow the user to remove one of those songs from their list (both would be have to be removed.)

Also, referencing only the songID number as stored in the music database doesn't seem a good option, since the song database will be changing frequently and song data may be overwritten. Not sure if there's a viable workaround there.

Originally I wanted to store Title, Artist, Genre under seperate columns so I could link them to something like "See more songs from this Artist." However the more I read about arrays and multidimensional arrays, I realize I'm not ready to go there yet. (I just started learning PHP two weeks ago.)

How To Insert Arrays From Screen Scrape Into Db?
I am currently running a class to execute screen scrapes from a general stats page. Currently it is set to print out the arrays. How can I utilize and organise this data so I can then enter it into my database?

Database Insert
I want to insert data into two tables of a database. Basically i want to insert into table1 then use the automatically generated auto increment id number as a variable in the second part of the insert. any ideas how to go about doing this?

Insert Into Database
I am currently working on committing this to the database.  however my problem is that not all of these fields may be populated.  For example q3c may be left blank therefore only two records need committing to the db instead of three. Code:

Database Insert
ive wrote a very simple News Script, but the only way i can add news to it is iva PHPmyadmin. I have no idea how to write the code to insert the information into a database.

Insert To Database
i want to do a simple insert into my database. The code works but nothing is inserted. I have removed the usernames and passwords for obvious reasons. Code:

Can't Write In The Database Using INSERT INTO
This is my script:

$table_to_use = "irr_accounts";
include ($_SERVER['DOCUMENT_ROOT'].'/snippets/cnx.php');

$query = "INSERT INTO $table_to_use (account_number, handling_branch, acct_type, school, address, street, city, contact_person, contact_number, first_name, last_name, date_applied, date_approved, end_date, status) VALUES

('$account_number', '$handling_branch', '$account_type', '$school', '$address', '$street', '$city', '$contact_person', '$contact_number', '$first_name', '$last_name', &#3900;-00-00', &#3900;-00-00', &#3900;-00-00', '$status')";

mysql_query("COMMIT");

Trying To Insert Data In A Database
I am trying to insert data in a database
Code:

Insert A Image To The Database
I tried to insert a image to the database but whenever I do I get a error message called 'invalid hex code' any idea guys?

Database Insert Security
I have a general question about security when inserting into a database. I just now realized that magic quotes in turned on. I discovered it while testing the formatting of my mail function. One of the words I typed had a single quote in it that got escaped. My next step is to insert the data into a MySQL database. I don't have the option to turn off magic quotes because I don't have access to the php.ini. Does this mean that every time I use data sent by a POST that I need to stripslashes?

Are the magic quotes enough security when inserting into a database? Should I be doing more to make sure that I am not the victim of a SQL injection? Should I also use htmlentities? Are the other measures I should be taking? At what point does this become overkill?

Get And Insert Info Into Database
I have one table (form) that has multiple fields. Here are few fields we need to know: ID, NAME, CITY, STATE, PROFESSION, x, y, z (x, y, z means more than 50 fields that give me more information about each name).

The ID and NAME are unique and they don't change (each name has it's own ID). A NAME and its ID can be in any CITY, STATE or PROFESSION but this is fixed. That means if ID# 123 for Mr JOHN is Austin, TX, that will stay in Austin, TX for ever. I have more than 5000 NAME and it's ID, 9 professions, all US States and all Cities in my database.

Here is what I need to do:
I want to have a form on my site that my visitor finds his name first and then enters more information about him/her that will complete my database fields of x,y,z. What I'm thinking to do is to create a drop down list that the visitor first selects the profession. Based on the profession the second list shows the states that has that profession. Then by selecting the state, all the available cities will show up in the third list, and by selecting the city all the names related to that profession in that city, state will show up and he can select the name from the forth list. Then he enters other required information about him that will be send and saved in the database.

Here is what I have done and I know to do so far:
I have created the database with all the information in one table. I also know how to send data to database to be saved. But my problem at this point is how to create this list selection that narrows the search to find the right person.

Insert Form Info Into Database
i am trying to enter info from a form into a mysql database. when i submit the form, a new row is created, but the information isn't contained in it? any thoughts? PHP Code:

To Insert Array Value In Database---important
ihad an array in php and iwant to insert its value in database
the coding is:

<?php
$nv_pairs = explode('&',$query_string);
$array[50];
list ($name, $value) = explode ('=',$nv_pairs);
$i = 0;
foreach($nv_pairs as $array[$i]) {
$array[$i]=
preg_replace('/\%0d%0a+/',"<br> &nbsp;&nbsp;&nbsp;&nbsp;
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; ",$array[$i]);
$array[$i]= urldecode ($array[$i]);
$array[$i]= preg_replace('/d*=/', " ",$array[$i]);
$array[$i]= urldecode ($array[$i]);
$i++;
}
ksort($array);
while(list($key,$value)=each($array)) {
if (preg_match("/d+/",$value)) {
echo "<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<b>$value</b>";
}
else {
echo " <b>$value</b>";
}
}
?>

Issue Insert ' Into Database From Form
I am unable to insert a ' through a form into my data base here where it is messing up i believe: PHP Code:

Insert New Record To Database Without Duplicating
Is there a simple way when inserting a new record to a database to only execute if it is not duplicating an existing record? The way I would currently do this is to query the database first with the new values and see if I get a match, but is there simpler way?

Unable To Insert All My Values Into The Database
I have an error in my code because its not inserting my $_session['identity']  into the database. I know the session has a value because I am able to display it on the page. it just wont insert it into the database. Code:

Can't Insert Record Into Access Database
I'm trying to create a registration/login script using Access 2003. I'm using ADOdb to connect through ODBC.

The problem is that I get the little custom error Could Not Connect to Server when I try to insert a record, yet when I use the form with a username I inserted through Access it reads it just fine and returns if the username has been used. Also if I removed line line 23 or die('<b>Could Not Connect to Server</b>'); and it'll complete the script, but it won't insert the record. Code:

Insert To Database On Page Load
I have the code for inserting data to a database form a form (Code below) but I want the data to be entered upon a page loading, how would I do this? Code:

Dynamic Insert Of POST Data Into Database
I have two tables one with game data ie visitor team home team so on and so forth and one with team name and team id, this info is pulled into a dynamic form. I can get the data from the form ok

foreach($_POST as $key => $value){
echo "$key:$value";
}

when I echo the info it gives me the correct output

game1:7 game1id:513
game2:14 game2id:514

I have columns in the database that correspond to the form var fields What my question is is how do I get the info into the database through each iteration in one row?

This is an example I have tried and I know doesn't work

$sql = "INSERT INTO teampicks ($key) VALUES('". $value ."')";
$res = mysql_query($sql);

Insert Multiple Variables Into A Database Quickly
I've just started using PHP and have written a small script to insert 10 variables into my database, e.g:

$query = "insert into items values
('".$q1."', '".$q2."', '".$q3."', '".$q4."', '".$q5."','".$q6."', '".$q7."', '".$q8."', '".$q9."', '".$q10."')";

The problem is, I will eventually need 300 questions so I don't want to list them all individually. How can change this snippet of code so that it says something along the lines of "please insert all the variables q1-q300 into the database"?

Simplify Insert-update-delete From Database
I'm looking for some functions or objects allowing to
select-insert-update-delete from any table in a mysql database without the
need to create a new query every time. Example:

selectdatas(array('field1','field2','fieldn'),arra y('table1','tablen'),array('left
join,idy','inner join, idx'))

then the function build the query, execute it and then return an object with
the query result.

I must build a database driven site that is 90% of the time spent on
building queries. If I may avoid build them manually it will help me a lot
and let me gain some days of programming.

Safe Mode To Insert Data In Database?
Hi what is the safe(est) mode to insert data (exmple email address) into database?
Example:

$query_return = mysql_query("INSERT INTO e_group (e_group_email) VALUES ('".$_POST['e_group_email]");
if(!$query_return) {
echo mysql_error();
exit;}

I heard about a slash (/) to put is somewhere when I want to email dont be a cached on the fly between a post and inserted into dbase  - I think its good for a password too.

Insert Server Date / Time Into Database
I currently have the following to insert a variable into a database:

$zip = $db->escape($_POST['zip']);
$db->query("INSERT INTO zip SET zips = '$zip'");

I would like to also add the date & time the submission was made.

Unable To Insert User Input Into Ms Sql Database.
i have tried to insert user input into ms sql database but still unable to do so. my code has no errors in it. its just that the user input cannot be submitted into the ms sql database. Code:

Inserting Values Into Database Using Arrays
I'm trying to insert the database the answers to a question and to get the user to select the correct answer. PHP Code:

Arrays And Inserting Data In To The Database
I have a form that uses two arrays one get's a list of courses from the database and one creates dates... i have two questions

1. how do i get the $i and $d value off of the arrays to insert in to the database, but still have each know they belong in the same row?

2. how do i change the dates from a multiselect dates ie, Jun 3, Jun 6, and Jun 12 to 'Jun 3, 6, 12'

here is the snippet of code from my select page. $numposts is a value selected on an earlier page. Code:

Inserting Elements Of Multiple Arrays In Database
I am stuck when trying to pass the contents of multiple arrays to an INSERT statement. Here is my code:

Multiple Array Selection From Database Instead Of In-Page Arrays
Have posted before, but will simplify problem here. For original post go to
http://forums.devshed.com/t80025/s.html

I have setup 2 arrays like so in my one page script:

Code: ( php )

Insert Into MYSQL Using PHP
I'm having problems with a form I've created to insert or update into a MySQL database using PHP. The fields (some are varchar and some are text) sometimes contain single or double quotes or slashes or '¿' and some other special characters. These seem to throw off the INSERT process in one way or another. Either that or when I got to display this information, it doesn't come out right. Are there functions that I need to run on the information to make this database safe before I INSERT (or UPDATE) or before I display it?

PHP-MySQL Insert
$Insert_query = mysql_db_query( "INSERT INTO $Table_result VALUES('$Item_Name', $Item_Price)" );

Why do I get a parse error on this line of code???

Insert Into MySQL
I have a system from a company called ProTx they provide online credit card transactions. I have their PHP code, and have had to change some parts of this to work correctly but am getting stuck on this part.

This code, is part of a page that sends off some variables to their server and expects a response. I am able to send the variables, and get the response but I want to put them into a database so that I have all refunds seperate from all orders. PHP Code:

Mysql Insert
I can't figure why an INSERT query won't work. This is the table:

downloads
----------------
id - int(10) - auto_increment
category - char(1)
file - text
date - varchar(20)
user - varchar(50)
desc - text

These are the variables:

$category = "1";
$file_name = "cow.gif";
$date = "0000-00-00 00:00";
$login = "fresh";
$desc = "Bertha the cow.";

This is the code: PHP Code:

Cannot Insert In Mysql Using Php
i have a problem about inserting data into the table. I dont
know why the output always said cannot be added to the database!
Anyone has idea for me?
i check the connect is ok, but dont know why.
The following is a function i will call to insert the database.
Thx!!!
function AddPart($Partnumber, $Partname, $Partdescription)
{
//Set the variables for the database
$DBName="krista";
$TableName = "parts";

$Link = mysql_connect("localhost","","") or die ('I cannot connect to
the database because: ' . mysql_error());
mysql_select_db($DBName,$Link);

$Query = "INSERT into $TableName (Part_Number, Part_Name,
Part_Description) values ($Partnumber, $Partname, $Partdescription)";

if (mysql_query($DBName, $Query, $Link)){

print("Your information is successfully added to the database!!
<BR>
");
}
else{
print("Your information cannot be added to the database! <BR>
");
}

//close MySQL
mysql_close($Link);

}

INSERT Mysql
How do I write something to a mySQL server using PHP?

What Is Indexing In Mysql And How It Will Be Useful And How We Can Retrieve Database Content Easily From A Database Table Containing About 5lakhs Datas
I need to select data from a database table containing huge amount of
data. Now I am storing data using one primary key and I am just using
simple select statement, and this process gives me the output but it is
taking long to execute the query. As much I had heared I want to use
some indexing or cluster indexing which might help me but I am not so
familiar with these things.

PHP INSERT Code (MySql)
Ok... i want to insert info into a db using php and mysql...
I can connect to the db using most of this code the only thing i am having trouble with is the 'mysql_result'.... If anyone could help. that would be great... thanks.

This is the code im using... my sql statement is fine but im not sure what php code to use...
<?php
$db = mysql_connect(sql,username,password);
$sql = "INSERT INTO tblMyTable (name,address) VALUES ($strName,$strAddress)";
$res = mysql_db_query(username, $sql)
***here is my problem... what goes here?
mysql_result($res,0);
***that was my guess but its not working..
?>
I couldnt find the code in the manual.. If anyone could help that would be great thanks

Problem With MySQL INSERT
I am trying to create a user interface to add/delete news.Here is my code:

PHP -> MySQL Insert Statement
heres what i am using : Code:

if (($p1 == $p2) && ($p1 != " ")) {print "accepted";
print "<br>entering you into the database....";
$enter = 'INSERT INTO member(name, psw) VALUES("$name", "$p1")'
$goenter = mysql_query($enter) or die("Entery Failed due to " . mysql_error());}
else {print "<br><font size=+1>Password did not match, try again!</font>";}} ?>


now heres the problem : when it writes to the table (all the db selection etc is fine) all that gets written is : "$name" and "$p1"

literally $name and $p1 *** not their values. I have tried combinations of quotes ( as " " will interpolate but ' ' will not) but still no dice. and w/o the quotes around the values ("$name" , "p1") --- it will return an error stating the colum ($name value) does not exsist.

Insert Objects Into MySQL ?
I'd like to know if there is a way to insert any object into a mysql-database.PHP Code:

Mysql Insert Just Wont Have It!!
i have the following query to insert data into a table with 7 fields...
one of the fields only need the default value to start with and the other is and auto increasement field. PHP Code:

Insert Time Into MySQL
I have a page in which the user selects the time with comboboxes labled:

hour - minutes - ampm

when the user clicks on submit this function gets called to format the selected time:Code:

Return The Key From Last Mysql Insert
How do I return the auto incremented value of the primary key from a tuple that I have just inserted into a MySql database. If that is not quite clear enough then this long winded explanation should explain what I mean: Say I have a MySql table called "n" with two columns:

1: id = Autonumber - Primary Key
2: name = Text

If I insert a tuple with the following mysql command using a PHP interface:

Quote: INSERT INTO `n` ( `name`) VALUES ('Paul Smith')

Then a tuple with with values say (34,Paul Smith) will exist in the MySql table. 34 is the value of the auto generated primary key. The question is how can I find this value 34, which is the primary key, without running a statement like :
Quote: SELECT * FROM `n` WHERE `name` = 'Paul Smith'

MySQL INSERT Problem
I am trying to insert data into the fields id and term of the table
key. id is an auto-incrementing field.

Each of the following forms fails:-

INSERT INTO key (id, term) VALUES (0, 'dog')

INSERT INTO key ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' (id, term) VALUES (0, 'dog')

mysql_error() returns messages of the following form:-

You have an error in your SQL syntax. Check the manual that corresponds
to your MySQL server version for the right syntax to use near 'key (id,
term) VALUES (0, 'dog')' at line 1

What is wrong with the syntax?

Get The Last Insert Of A Mysql Tabel
how can i get the last insert of my userid column its not the primary id if there is one it should add one to this number and save it in a varible so every user gets another userid Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved