Jump to content

Storing MYSQL data into tables?


winmastergames

Recommended Posts

I cant seem to get this to work can someone plese enlighten me on whats wrong. im trying to insert data into the table (SQL of table below)

CREATE TABLE `tue23` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(200) collate latin1_general_ci default NULL,
  `slogan` varchar(200) collate latin1_general_ci default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

Im trying to use this script but it doesnt work

<?php 
// Connects to your Database 
mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("swd-dbweb") or die(mysql_error()); 
mysql_query("INSERT INTO tue23 VALUES ( '1', titlename, 'sloganname' )");
Print "Your table has been populated"; 
?>

thanks very much

 

Link to comment
https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/
Share on other sites

<?php

// Connects to your Database

mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("swd-dbweb") or die(mysql_error());

mysql_query("INSERT INTO tue23 VALUES ( '', 'titlename', 'sloganname')") or die(mysql_error());

Print "Your table has been populated";

?>

You are trying to insert 1 into an auto_increment field, you can't do that.

 

You can. Use NULL if you wanr it to auto_inc (or omit it completely) but it will accept a value so long as that value doen't already exist.

You are trying to insert 1 into an auto_increment field, you can't do that.

 

You can. Use NULL if you wanr it to auto_inc (or omit it completely) but it will accept a value so long as that value doen't already exist.

 

Yeh but with my guess is the auto-increment is also primary key... so im going to guess that to insert a value would be pretty difficult to find a unique without a pre-check everytime. But again as said in the other post we dont know what the field is! >.<

 

<?php 
// Connects to your Database 
mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("swd-dbweb") or die(mysql_error()); 
mysql_query("INSERT INTO tue23 VALUES ( '1', titlename, 'sloganname' )");
Print "Your table has been populated"; 
?>

 

Into this:

 

<?php 
// Connects to your Database 
mysql_connect('localhost', 'root', 'com12345') 
    or die(mysql_error()); 
mysql_select_db('swd-dbweb') 
    or die(mysql_error()); 
    
if( mysql_query('INSERT `titlename`, `sloganname` INTO `table` VALUES (\''. $titlename. '\', \''. $sloganname. '\' )') ) {
    print "Your table has been populated"; 
} else { 
    print mysql_error();
}
?>

 

Don't ever specify the ID field when it is set to "auto_increment" - MySQL handles that for you. Just ignore it

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.