MySQL Insert Query - php Form

Author Topic: MySQL Insert Query  (Read 1789 times)

Offline kelvin

  • Supporter
  • **
  • Posts: 4
  • Karma: +0/-0
    • View Profile
MySQL Insert Query
« on: January 15, 2010, 05:58:50 AM »


MySQL Insert Query

Code: [Select]
CREATE TABLE  `textbase` (
 `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
 `name` TEXT NOT NULL ,
 `date` DATE NOT NULL ,
PRIMARY KEY (  `id` )
);

config.php
Code: [Select]
<?php 
$dbhost 
'localhost';
$dbusername 'root';
$dbpassword 'mypassword';
$dbname 'mydbname';
$conn=mysql_connect($dbhost$dbusername$dbpassword);
if(!
$conn) :
   die(
'Could not connect: ' mysql_error());
endif;
$db=mysql_select_db($dbname$conn);
if(!
$db) :
   die (
'Can\'t connect to database : ' mysql_error());
endif;
?>


insert.php
Code: [Select]
<?php
include('config.php');
$value2 'value two';
$value3 'now()';
mysql_query("INSERT INTO textbase (name, date) VALUES ('$value2','$value3')");
?>

« Last Edit: January 15, 2010, 05:11:42 PM by admin »

Offline Gliktch

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: MySQL Insert Query
« Reply #1 on: January 16, 2010, 03:46:15 AM »
What happened to value1?  :P

Umm and not to crap all over your work or anything, but any time you're accepting user input it should be treated like the plague - proper input sanitation (and in some cases validation) is essential to avoid being 0wned. ;)

Offline kelvin

  • Supporter
  • **
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: MySQL Insert Query
« Reply #2 on: January 19, 2010, 02:38:58 AM »
Code: [Select]
$value1 = "auto_increment"


:)