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
Share on other sites

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

Link to comment
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 ( '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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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