LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   MySQL - Inserting Data Not Happening! (https://www.linuxquestions.org/questions/programming-9/mysql-inserting-data-not-happening-33762/)

Rhapsodic 10-25-2002 07:14 PM

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 ..:confused: :confused:

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

Any help is much appreciated :)

crabboy 10-25-2002 11:36 PM

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]

Rhapsodic 10-26-2002 02:55 PM

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 :)

jharris 10-26-2002 07:19 PM

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

Rhapsodic 10-26-2002 11:58 PM

Thanks a lot! It works great now :)

-Micah


All times are GMT -5. The time now is 02:39 PM.