If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > trouble doing basic mysql insert

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-20-07, 23:19
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
trouble doing basic mysql insert

Does anyone know why this isnt getting inserted into the database?
I have another insert thats working fine. Just this one is not.

$name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];

$insert_details = "INSERT INTO participant_info VALUES('$name', '$address', '$phone', '$email')";
mysql_query($insert_details);
Reply With Quote
  #2 (permalink)  
Old 03-21-07, 03:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
please show what you get for this query --
Code:
SHOW CREATE TABLE participant_info
also, have you tried running the query outside of php (with actual values substituted for the php variables)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-21-07, 03:47
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
This is not a SQL script, this is a PHP script.

The first step in isolating SQL problems that occur in the programming language is to run the generated SQL directly against the database. In my experience if 90% of the time the program code (i.e. in your case your PHP code) is the reason - not the SQL itself.

And for future questions, you will get more accurate answers if you try to be more detailed than just "isn't working" (e.g. showing the error message)
Reply With Quote
  #4 (permalink)  
Old 03-21-07, 10:33
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
heres the table

Hi, I havent tried running a query outside of php itself, I really not sure how to do this?...do you mean just insert a some values manualy?... I am using same code for another insert on a different table and it works also I get no error messages from my php script. any ideas?.... sorry for being vague, i just wanted to try an keep the post brief.
Regards, John


-- Table structure for table `participant_info`
--

CREATE TABLE `participant_info` (
`name` varchar(50) NOT NULL,
`address` varchar(55) NOT NULL,
`phone` smallint(12) NOT NULL,
`email` varchar(55) NOT NULL,
PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `participant_info`
--
Reply With Quote
  #5 (permalink)  
Old 03-21-07, 10:37
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
increment issue / related problem? to insert?

Im not sure if this is somehow related to the previous problem, but this table will not auto increment as expected when doing an insert of data, I have to generate a random number in php then it works...really strange as it did work locally when i sent a nul ("") value for "userid" field. When live though i have to actually send a value for that parameter.
John

-- Table structure for table `user_registrations`
--

CREATE TABLE `user_registrations` (
`userid` int(6) NOT NULL auto_increment,
`theday` date NOT NULL,
`seats` smallint(4) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=119309 ;

--
-- Dumping data for table `user_registrations`
--

INSERT INTO `user_registrations` (`userid`, `theday`, `seats`) VALUES
(109845, '2007-03-11', 4),
(66471, '2007-03-05', 1),
(35629, '2007-03-11', 1),
(27049, '2007-03-07', 1),
(119308, '2007-03-07', 1),
Reply With Quote
  #6 (permalink)  
Old 03-21-07, 10:40
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
I'll take an educated guess in that you already have that email address in your table. you should get into the habit of error handling in your scripts.

as to how to connect to mysql without the php code, you can use the command line client for mysql to test your queries and make sure they work okay.
Reply With Quote
  #7 (permalink)  
Old 03-21-07, 10:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by john_cmd
... this table will not auto increment as expected when doing an insert of data
yes it will
Code:
CREATE TABLE john_cmd (
`userid` int(6) NOT NULL auto_increment,
`theday` date NOT NULL,
`seats` smallint(4) NOT NULL,
PRIMARY KEY (`userid`)
) ;

insert into john_cmd (theday,seats) values
 ( '2007-03-22', 9 )
,( '2007-03-22', 3 )
,( '2007-03-22', 7 )
;
select * from john_cmd;

userid      theday      seats
   1      2007-03-22      9
   2      2007-03-22      3
   3      2007-03-22      7
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 03-21-07, 11:28
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
hi guelphdad

no emails are present at all in the DB, as I couldnt get it to insert in the first place, but thanks...
Reply With Quote
  #9 (permalink)  
Old 03-21-07, 11:32
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
hi r937

when I try an insert without sending a number of some sort for the userid param, my database is never updated and does insert of the data...when I generate a random num from php to send with the insert giving that first param a value it works....
how else can i trouble shoot this?
John
Reply With Quote
  #10 (permalink)  
Old 03-21-07, 11:34
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
table structure

hi since i am beginner using Databases, am i creating the table correctly? to insert basic data? do I need another field that is for an ID to autoincremenet?
Best, John

-- Table structure for table `participant_info`
--

CREATE TABLE `participant_info` (
`name` varchar(50) NOT NULL,
`address` varchar(55) NOT NULL,
`phone` smallint(12) NOT NULL,
`email` varchar(55) NOT NULL,
PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `participant_info`
--
Reply With Quote
  #11 (permalink)  
Old 03-21-07, 11:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
okay since you are just getting going, please do the following

- drop your table
- go to post #7 and copy the script down to but not including the blue stuff
- open an sql window in phpmyadmin or the command line or whatever it is you're using to administer your database
- paste in the code, execute it, and let us know what happened
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 03-21-07, 11:55
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
ok

will do thanks!
Reply With Quote
  #13 (permalink)  
Old 03-21-07, 12:01
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
working

yes you are right i was wrong, so seems it must be the way i am sending the insert cmd? or param from php right? actually this var is coming from flash into php then does insert.
John
Reply With Quote
  #14 (permalink)  
Old 03-21-07, 12:06
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
is this where i am going wrong?

flash sending id=""
so since that didnt work sending "", i used a random num for a value, should I just have left that parameter blank?
like this:
$insert_seat = "INSERT INTO user_registrations VALUES('', '$thedate', '$guests')";
mysql_query($insert_seat);

what i have now, php is:

$userid = $_POST["id"];
$thedate = $_POST["date"];
$guests = $_POST["guests"];

$insert_seat = "INSERT INTO user_registrations VALUES('$userid', '$thedate', '$guests')";
mysql_query($insert_seat);
Reply With Quote
  #15 (permalink)  
Old 03-21-07, 12:47
john_cmd john_cmd is offline
Registered User
 
Join Date: Mar 2007
Posts: 26
really stupid

I looked closely at your SQL you posted, and i see the problem now...
i had this:

$insert_seat = "INSERT INTO user_registrations VALUES('$userid', '$thedate', '$guests')";

you had this:

insert into john_cmd (theday,seats) values
( '2007-03-22', 9 )
,( '2007-03-22', 3 )
,( '2007-03-22', 7 )
;

seems i didnt specify where to insert --> (theday,seats) values

thanks much!.
John
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On