ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have got the following code to try and insert data into MySQL database but I am not having much luck.
Has anyone any ideas as to what’s I am doing wrong.
I am not getting errors when I try click enter info.
Ta,
g
<html>
<body>
<?php
$db = mysql_connect("localhost", "user", "passwd")
or die ("cant connect to the DB");
print ("connected to database successfully");
mysql_select_db("test",$db);
?><html><br><br><?php
if ($submit) {
$sql = "INSERT INTO employees (first,last,address,position)
VALUES ('$first','$last','$address','$position')";
i had problems before with this, and the way i solved this was to download the rpm for the link between php and mysql. i think it is called php-mysql.
A module for PHP applications that use MySQL databases.
i was using Red hat, so i obtained php-mysql from rhn.redhat.com.
php-mysql-4.2.2-8.0.7.i386.rpm
------
The php-mysql package contains a dynamic shared object that will add
MySQL database support to PHP. MySQL is an object-relational database
management system. PHP is an HTML-embeddable scripting language. If
you need MySQL support for PHP applications, you will need to install
this package and the php or mod_php package.
I have seen that problems before also and have database connectivity and can call data from the MySQL DB happily
Also with some simple script I can also add to the data base
But when I try and enter data in the MySQL via a form no Cigar!!
This is an example of some code that works for me
$insert = "INSERT INTO employees (first,last)
VALUES ('Morgan','Andersson')";
mysql_query($insert) or die ("Could not add data to the table");
$result = mysql_query($sql);
Your problem may be caused by having the option "register_globals = Off" in your php.ini file (somewhere in /etc/ or /etc/php /etc/php4 or so). If you set it to "On" (maybe you need to restart apache after editing php.ini), I think your script will work.
If you don't want to set "register_globals = On" (e.g. for reasons of better security), or if you can't because it's on some provider's server, add some lines to your script in order to fill the variables. Like this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.