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




Default Value To Insert Into MySQL


What should I insert as the default value if a form field is blank? My fields don't currently accept null.

if($_POST['height']) {
  // error checking
  $height = $_POST['height'];
}
else {
  $height = '';
}
Should $height be equal to '', NULL, or maybe 'NULL'? I'm thinking 'NULL' incase I or someone else decides to change the field to accept null?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Problem On Default Value : : MySQL
Problem on default value : : MySQL

I am facing problem in this line

`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

when I tried to crate a new table in MySQL(version 3.23.47-nt)

MYSQL: How To Set A User's Default Database?
Is it possible to set a user's default database for MySQL database?

Instead of having an additional line of command, i.e:

mysql> use database <database_name>

Perhaps there are parameters I can set up a default database for a user when
she log on to mysql.

Mysql - DEFAULT '' Defined Yet NULL Inserted
My database was inserting NULL for empty strings so I changed the field
definition with this query:

ALTER TABLE `myTable` CHANGE `myUrl` `myUrl` VARCHAR( 255 ) NOT NULL
DEFAULT ''

No error was reported following the query and yet I still get NULLs on
insertions.

MySQL Datetime Field Default Now() Fails
I have a mySQL database table with a column field datatype of datetime that
I set up in the original create table statement like this:

create table nnet_usermetadata (
....
nnet_record_entered datetime default 'now()'
)

However, upon execution, each time a record is entered into
nnet_usermetadata the results are:

00-00-0000 00:00:00

Is there a way I can always ensure that the current date and time are always
entered into the datetime field?

Enabling/Disabling InnoDB With Default Mysql Installation.
If you install mysql and find innodb table type is not available,
follow these steps.

find my.cnf file. usually my.cnf file resides in "mysql/bin" folder.
Then search for "skip-innodb", if you find the line then comment it as
"#skip-innodb", then retart you mysql daemon.

Thats it

To disable, uncomment "skip-innodb" or start mysql daemon with
following command

mysql --skip-innodb

thats it.

Database Stores Default Number Everytime, But I Havent Set A Default Number??
Im having some problems with my database. Everytime i store a number which is longer than 10 numbers the script or database puts this number into the database: 2147483647. Its does this everytime no mather how i write the numbers and nomather how long the number is, it just needs to be over 10.

I have set any default value in the database and to be sure i havent i tried deleting the table, but same thing happends again???

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?

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:

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.

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:

How To Get Last Insert ID In MYSQL Table
May I know how to retrieve the last inserted ....

MySQL: INSERT If Name Doesn't Exist
I am trying to write a query that will insert if a row with the same name (col='name') doesn't alread exist.

So basically, if the query trys to insert Jim, but Jim is already in the table, it will skip the operation.

Can anyone tell me how to do this?

Also - is it more efficiont to run one query with multiple inserts or multiple queries with one insert.

MySQL Insert With PHP Array
I have a form that collects input to be stored in a database. I want to store each field in the form in the database. But for some reason this code doesn't work: PHP Code:

Using Php To Insert Data Into MYSQL
I just whipped up this script for part of our project. Do the insert statements and script look legit in order to make php insert data into my mysql tables which I already created in previous scripts? Code:

PHP MYSQL Insert Syntax
$q = "INSERT INTO downloads (sub, title, name, email, link, date, description, pic)
VALUES ('$c', '$t', '$n', '$e', '$l', 'NOW()', '$d', 'NULL')";
$addinfo = mysql_query($q);

Does that look right?  I don't have many resources for php and mysql.

Bulk Insert => MYSQL
How do I instert multiple rows of SQL into a database from a php file?
Is there a way to have a PHP file read a MYSQL DUMP (.sql) file and run it?

Mysql Insert Query
I can't figure out whats wrong witht his query.

Quotemysql_query("INSERT INTO `serverInfo` ( `id` , `serverid` , `size` , `filename` , `timestamp` ) VALUES('null', '1', '".$size."', '".$dir."', '".$date."'") or die(mysql_error());

Anything stupidly wrong here? the id,serverid, size, filename,timestamp thsoe are all right.

Error:
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 '' at line 1

MySQL: Insert...select - Update?
I was reading about insert select
http://dev.mysql.com/doc/mysql/en/insert-select.html

Thought this may be a better way to perform a query I'm doing. The differenc is that I need td select from one field, and then update another field in the same record (it is a backup/undo field).

Is there a way to do this in one query? It's a large chunk of data (longtext) so I thought this would be faster than the alternative...

Mysql Insert Statements Problem
i've created a site locally on my machine using php 4 and mysql3 all working fine, however having bought a new laptop i decided to upgrade to php 5 and mysql 5. i've sorted any other problems i had but bizarrely none of my mysql insert statements throughout the site work any more? they worked before? is there a syntax change to inserts or something that i'm missing?

Php/mysql Insert, Update, Delete All-in-one
I have a check box form in an admin area, that links various related tables into one.

These check box results are stored in an array, and then looped, there are in fact four groups of arrays, but the array length could become large (i.e. dozens - not hundreds)

The issue I have is that from the one form multiple things need to occur.

- If a box is checked and the record doesn't exist a new record needs to be inserted.
- If a box is checked and the record does exist, it should be ignored (as it already exists).
- If the box is unchecked and the record exists, it should be deleted.
- If the box is unchecked and the record doesn't exist it should be ignored (the record doesn't exists).

I'm looking for the logic and process (rather than being hand fed code ) Can this be done with 1 (or more likely 2) sql statements. Or do I have to loop thru the arrays, checking the existance and then applying a specific sql statement depending upon checked status and the records existance. Someone mentioned using IF() in the sql statement, but I am not familiar with that one.

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 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 Text From TEXTAREA Into MySQL
I'm trying to figure out how to INSERT/UPDATE text from TEXAREA into
MySQL. Because TEXAREA has no VALUE, I'm hitting a brick wall here.


Multiple PHP/MySQL INSERT Statements
I have a text file of data in a file (add2db.txt) where the entries are
already entered on separate lines in the following form:

INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");

INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");

INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
Good food.", " (Minnie Mouse - 01/03/2004)");

etc etc

These have been parsed from a review form that a client already
submitted. What I need to do now after I have reviewed the information
for appropriateness and grammer is to insert it into my MySQL database.
I would write single line entries like this:

// Set Mysql Variables
$host = "localhost";
$user = "root";
$pass = "";
$db = "rest";
$table = "reviews";

// Connect to Mysql, select the correct database, and run the query
which adds the data gathered from the file into the database

mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_review = "INSERT INTO $table
values('','$rname','$umeal','$ucomment','$uname')";
mysql_query($add_all) or die(mysql_error());

But how would I write the $add_review to read each line of the
add2db.txt and enter it as a separate entry?

Insert Giant XML Files Into MYsql
I have a 36 meg XML file that contains 11,000 records, Each record has about 40 pieces of information. Here is a simple version of the file Code:

How Do I Insert And Display Currency In PHP/MySQL?
I have a field in mysql which is a double and I trying to store say $5.00. I'm entering 5.00 but my select statements are returning 5, I need the .00 as well though.

Text To Date And Insert To Mysql...
Kindly break out the 4x2 and bring me to my senses.
I seem to have gotten myself totally confused with php.net, mysql.org pages
on dates etc, as well as groups.google.

Could someone explain, even using pseudo code, how to take a text input I
have set up as YYYY-MM-DD using php, and convert to a value mysql will
insert into a Date (not timestamp, not datetime) field.

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:

Multiple Table Insert With Php Mysql
I am having and issue getting this code working. It seems rather simple but I cannot figure out why only one sql statement is exectuing and the insert statements the other 2 are not exectuting and updating the other 2 tables. I need to do this. I need to update one table, then from that I need to retrieve the mysql_insert_id or just get the id of the last record in the tabe.

There is an auto increment column that gets assigned a unique id each time a record is inserted. I need this id number then I need it to place data into 2 other tables that will use this value as a reference. here is the code:

Form To Insert Mysql Row *and* POST Data
I'm reasonably new to PHP and after searching all over the place can't find anything useful

I need to insert some variables into a mysql row and then POST variables to another web page using the same form

The page i'm posting to is an SSL (bank hosted)ecommerce transaction page which I have no powers to change

I don't have any problems inserting just mysql rows or making html forms to post separately, I just don't know where to start to get the one form to do both.

Strange, Inconsistent Mysql Insert Problem
I was having a rather strange problem. I don't seem to be having it anymore, but I didn't really do anything to fix it, so I'm concerned in case it comes up again.Here's the pertinent code:

PHP/mySQL Insert Into Statement With Auto Increment
When i use mysql from the linux command line it is just plain simple to add an row into a table, even with php this isn't a problem. But when the table has aan field with auto_increment php won't allow to insert a new row in the table. I'll get an invalid query back.. In don't understand how to insert a new row into a table with the auto increment. Btw this is also the primary key: Code:

Insert NULL Not Blank Into MySQL With PHP Script
Here's my question: How do I pass a NULL value in a variable to a
MySQL DB?

Here's an overview of my problem: I have a PHP page that processes
code, then inserts the code into a database. Very straightforward.
But, some NULL values are being inserted as a blank space, or the
string "NULL" instead of a true NULL.

Below is the db insert...

INSERT Into Mysql Alway Make Two Entries
I code some site and because Im a freak I made my own session-handling.
When a user open up my site it will check if there is a ssid in the url
if not generate one. this will be done by a function generate_ssid() and works fine.
next step is to register the ssid in the table session
this will be done by the following code:
******************************
function ssid_register($ssid,$login,$uid,$admin){

$connect = mysql_connect( $GLOBALS["db_host"],
$GLOBALS["db_user"],
$GLOBALS["db_password"])
or die($GLOBALS["db_error"]);
mysql_select_db($GLOBALS["db_name"],$connect) or die($GLOBALS["db_error"].'<br>ErrorCode s.001-con');
$result = mysql_query("INSERT INTO session SET ssid='$season',ip='$rip'",$connect);
echo ($rs);
return;
}
********************************
I redesigned the INSERT INTO part into all possible syntax but everytime I look into the db, there are two entries with two DIFFERENT ssids.
The only way it works correct is to dont use a variable on the first place.
Means if I use ssid='godhelpmetofindaworkingsolution' it works great but is not realy what I want.

As told above a "INSERT INTO session (ssid) VALUES ($ssid)" also has the effect of two new db-entries.

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 Empy Variable Into Mysql Table
I've got a form in which a couple of the address fields can be empty when the form is submitted... I haven't actually managed to get the Insert statement to work yet (see other post..), but I know this seems to also be causing problems. I have set up the table fields for these 2 address form fields to be Yes under the NULL column, but it still gives the almighty:

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 ' , London, W1, UK, 9991, 007, 'warstormer@hotmail.com'' at line 1 Code:


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