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




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.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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:

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:

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.

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', ༼-00-00', ༼-00-00', ༼-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.

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.....

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:

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:

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

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:

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:

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.

Images In Database Vs. Image References In Database
i kept all of the uploaded images as files on the server, and created links to them in the database. I have been changing things around now (especially directories) and I am thinking of storing the images in the actual database. I read somewhere that this can be considered a bad practice, so i was wondering what the consensus here was. In my opinion, modifying all of the code to point to the correct directories everytime a page location changes seems like a pain in the a**.

Insert
what is the proper way to insert a new field into a mysql database? i want to insert a new id guildname and username? i mean doing through a php script?

Sql Insert
I have looked at numerous examples of SQL insert statements with PHP and this apparently should work:

$sql = "insert into estateagents
(companyName) values
('$companyName')";

but it does not - it tells me a record has been added....but nothing appears in the db...any ideas?

Insert (now(),now(),....)
I've a query with insert records in a table.

I've 2 fields: DateTimeInsertion and DateTimeLastModification.

When I create the record, I must have those 2 fields set the same value.

Now I've this

Insert into article values(now(), now(),....)

but what appens if the time changes between the 2 now calls ?

It's there any way to be sure to set the same value ?

No Insert ...
I have a php-script with a mysql_query ...

$insert = mysql_query("INSERT INTO $table (textID,redaktion) VALUES
('$_POST[ID]','$row_startseiten[ID]')");

I get no mysql_error, if i copy the insert directly into phpmyadmin, the
insert works. but with the php-script the insert doesn`t create a new
row in the table .. but why?

PHP To Insert
How to make an insert in a mysql database in string type the '#' character?

INSERT INTO DB
All of the variables are registered with the session and I see them when I do a test. Knowing that I now wish to use the code below to insert them into the DB. But it doesn't work! When I run the script it appears to work but the DB does not get updated. Code:

Insert
if i wanted to insert something to my database will the code be like this?

$email2=$_POST['email2'];
$tbl_name=users;
$sql="INSERT FROM $tbl_name WHERE email='$email2'";
$result=mysql_query($sql)

PHP Insert
Im having a problem with a subscription script I made. Its a basic script, and the purpose of it is to allow a user to enter their email address, forename, surname, and select weather they are a business user or home user, then click "submit" and the information gets entered into the database/table I made for the script.

Now the problem Im having is the script works, and it submits, the problem is if I go look in the database the script didn't actually insert any information into the database.

Below I have included the html form, and the handle.php (the php script that handles the form information) I was hoping someone may be able to provide some insight/advice as to why its not inserting whats in the field values into the database Code:

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?

INSERT With OCIBindByName Or Not? What Is Better?
I was wondering. What is better?

INSERT a value with the OCIBindByName function like this:

$connection = //connect to database

$sql = "INSERT INTO <tablename> (column) values (:new_value)";

$stmt = OCIParse($connection,$sql) or die ("whatever");

OCIBindByName($stmt, ":new_value", &$variable, 20);

OCIExecute($stmt);

OCICommit($connection);

OCIFreeStatement($stmt);

Databasedisconnect($connection); //my own function to disconnect the database

OR VIA THIS WAY (which I prefer by the way, because the code is shorter)

$sql = "INSERT INTO <tablename> (column) values ($variable)";

$stmt = OCIParse($connection,$sql) or die ("error during parsing");

OCIExecute($stmt) or die ("error during execute");

OCICommit($connection);

OCIFreeStatement($stmt);

Databasedisconnect($connection); //my own function to disconnect the database

I hope someone can tell me which one the methods above is better/faster/more efficient.

Insert 1 Field Instead Of 10??
can i insert only one field in a table which consists of 10 fields??

wat i am trying to do here is to see whether table have this record ornot? PHP Code:

Redirect After INSERT
I have taken old Dreamweaver INSERT record code and turned it into a generic function. Basically another function generates the SQL and this one inserts it.

The INSERT works great but I then want the page to redirect back to the index.php page and this is not working at all. Does anyone know the best way to do this. The code is below:

The form action is below:

<form action="<?php insertSQL($c13_db, $add_competition);?>" method="POST">

This is the insert function:

function insertSQL($_db, $sql)
{
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["form_submit"])) && ($_POST["form_submit"] == 1)) {
$sql = get_sql($sql);
$result = mysql_query($sql, $_db) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?'))? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}

The header function is left over from the old Dreamweaver code and I cannot get it to work now it's within a function. Can anyone please help me out.

Insert Ignore
Are you allowed to use the following syntax in Mysql 4.0.17-nt :

INSERT DELAYED IGNORE INTO `mytable` ( `ID` , `A` , `B` ) VALUES
("'.session_id().'", "2", ROUND(NOW()/10000) );

I am particularly interested in the delayed ignore. I want to make sure
that no matter what, the instruction is carried out and that, due to
indexes, the data is not allowed to go in, that we do not get an error.

Insert File-name Into Db
I have an html-form with 3 fields, 2 simple textfields and one file-field. I want to store the information in an mySql-table.

The two text-fields are easy-ones, $_POST[text1], $_POST[text2], but how do I get the value from the file-field? $_POST[file] does not do it for me...

I just want to store the name of the file in the table, pic/article1.jpg, for example.

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

PostGreSQL INSERT
I've written some scripts to display information from a PostGreSQL database in a table format, and everything is fine. I've been adding data manually up until now. So, I've written a page where users input their information and this gets inserted into the relevant table. However, this isn't working.

I have been chopping code out to the bare minimum just to get something working, but even the simplest thing doesn't work.Here's what I've got at the moment :

$resultSet = pg_exec($conn, "INSERT INTO ntable (make, model) VALUES ('Suzuki', 'Bandit'))";

I have connected ok, so there's no problem there, but the above line produces :
Parse error: parse error in /web/sites/042/grendel/www.grendel.f2s.com/addins.php3 on line 39 .

SQL Insert And Delete?
Anyone know if there's a way to call a query but remove whatever you grabbed from the database, or would I have to do a query to retrieve what i needed, then follow it up with a delete on the same query results?

How Can I Insert A Pic Onto A Blogger?
Can someone please help me with this. I need to align a picture onto a
"blogger"?

Need To Insert A Bold Tag
I need to enter a bold tag on a part of my db. This is the only place where I can enter:

$actcp->number = "some text here <b>" . $actcp->number ;
} else {

Any ideas on how to enter the closing bold tag? I am getting a blank page when I enter it normally. I tried adding the ." or just ", but no luck.

How Can I Insert Data In A Pdf From Php??
I have been reading this group but I can not find the simple answer
tohow i can solve what i need to do. I have a pdf template, it is, a
pdf with some data like name, surname,etc ...and i want from web
(using php) to open this pdf, fill thesedata and repeat it so many
times as number of students there are... I have read about fdf , etc,

Insert/update
I came accross a little piece of code today that I thought was quite
cute, but I'm not sure if it's any better than my usual method. The
code ultimately needs to see if a unique identifier exists in a
database, then either insert or update accordingly.

The way I've always done it is:

SELECT * FROM blah where.....

if (there's a row) then
UPDATE.....
else
INSERT

but the nifty bit of code did it like this.

UPDATE....
if (mysql_affected_rows == 0) then
INSERT


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