LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2002, 07:14 PM   #1
Rhapsodic
LQ Newbie
 
Registered: Oct 2002
Location: Kelowna, BC, Canada
Distribution: RedHat 8.0
Posts: 7

Rep: Reputation: 0
MySQL - Inserting Data Not Happening!


Hi,

I have recently installed MySQL - PHP - Apache, on my machine, and they all work in harmony. Except for one weird thing. BTW I'm running Redhat 8.0

I have been trying to use PHP to insert data into the MySQL database, but I can't seem to get it to work. I can retrieve data no problem (with the same script) but for some reason, when trying to insert (with PHP) nothing happens, not even an error.

This is what I have tried without success:
-Used the scripts from Developers shed website, for a very basic try.
-Tried changing the <form> method = "post"> to "get">
-Tried adding the "insert into db (name,id) values ('$name', '$id')" <--the (name,id) part..
-Tried ('$name'), (".$name.")...
nothing seems to work ..

but when I insert the data manually (at the mysql prompt itself), I can retrieve that data....

Any help is much appreciated
 
Old 10-25-2002, 11:36 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Post a full statement. I'm not sure what you are doing wrong from you description. An insert statement could look sometihing like this:
[code]
$query = mysql_db_query( "dbname", "insert into picture_groups values ( '$NextValue', '$NewGroup')")
or die ("Bad query");
[code]
 
Old 10-26-2002, 02:55 PM   #3
Rhapsodic
LQ Newbie
 
Registered: Oct 2002
Location: Kelowna, BC, Canada
Distribution: RedHat 8.0
Posts: 7

Original Poster
Rep: Reputation: 0
Hi, okay the problem isin't with the database, I just found out. It's with forms and PHP it seems.
For some reason it doesn't seem to pass variables well.
**Code submitform.html***
<html><body>
<form action=submitform.php method=GET>
First Name: <input type=text name=first_name size=25 maxlength=25>
Last Name: <input type=text name=last_name size=25 maxlength=25>
<p>
<input type=submit>
</form></body></html>
***Code for submitform.php*
<html>
<body>
<?php
mysql_connect (localhost, username, password);
mysql_select_db (dbname);
mysql_query ("INSERT INTO tablename (first_name, last_name)
VALUES ('$first_name', '$last_name')
");
print ($first_name);
print (" ");
print ($last_name);
print ("<p>");
print ("Thanks for submitting your name.");
?>
</body>
</html>
Now, what happens is that a line gets inserted into the DB but it's values are blank.. so, I tried changin $first_name to blah then it inserted blah into the db..
Thanks for help
 
Old 10-26-2002, 07:19 PM   #4
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 46
Post

What version of PHP are you using? It sounds to me like you are using 4.2/4.3 without register_globals set to 'on' in php.ini. You either need to enable register_globals by default (and get the security problems that come with it) or start using the new style superglobal arrays. Check out php.net's page on external variables - http://www.php.net/manual/en/languag...s.external.php

cheers

Jamie...
 
Old 10-26-2002, 11:58 PM   #5
Rhapsodic
LQ Newbie
 
Registered: Oct 2002
Location: Kelowna, BC, Canada
Distribution: RedHat 8.0
Posts: 7

Original Poster
Rep: Reputation: 0
Talking

Thanks a lot! It works great now

-Micah
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem inserting data into a mysql table using PHP Rockgod2099 Programming 13 08-03-2005 01:27 AM
why do i get this error when inserting data to a mysql table verbatim Programming 2 06-15-2005 07:12 AM
I need help with inserting data into mysql w/ PHP lostboy Programming 3 08-25-2003 01:08 PM
inserting data in mysql zuessh Linux - Software 4 05-19-2003 02:00 PM
Problem Inserting MySQL data from PHP! rhuser Linux - Software 9 03-03-2003 08:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration