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.
Hi there,
I'm new to PHP and mySQL and I'm finding both thoroughly interesting.
Though, I'm having issues while using mySQL functions in a PHP script on my Fedora 6 machine.
This is something that I wish to run:
<?php
mysql_connect(“localhost”, “username”,”password") or
die (“Could not connect to database”);
mysql_select_db(“databasename”) or
die (“Could not select database”);
?>
And strangely, when I try to, the browser page goes completely blank and looking in the error log tells me that PHP is not recognizing the mysql functions in the script. I'm not able to run any of the mysql functions in php.
(The error log is:
[Wed May 02 17:52:19 2007] [error] [client ::1] PHP Fatal error: Call to undefined function mysql_connect() in /var/www/work/dbconnect.php on line 2, referer: http://ashesh.homeip.net/work/sign.php
)
My php version is 5.1.6.
Can anyone tell me how to rectify this?
Many thanks in advance.
Last edited by ashesh0326; 05-01-2007 at 07:25 AM.
Well, I just had another question.
It seems like I'm having trouble passing variables from forms to my php scripts.
For example, this is an extremely rudimentary script and yet it refuses to work in my case. No matter how many things I try, it's giving me the same, 'form data incomplete message'
<?php
if (isset($submit) && $submit=="yes")
{
echo "Thank you for submitting your form.";
}
else {
?>
<h3>form data incomplete</h3>
<form action=mypage.php method = post>
<input type=text name = email>
<input type=text name=first_name>
<input type=submit name=submit value=yes>
</form>
<?php
}
?>
And it refuses to work. I had the same problem with a more complex form, and I had decided that I'd resolve the issue later.
As it seems now, I don't think I have any idea as to what's wrong with what.
Can anyone please help? Thanks in advance.
This is what I got when I checked apache's error_log:
Quote:
[Sun May 06 19:33:15 2007] [error] [client ::1] PHP Notice: Undefined variable: first_name in /var/www/work/mypage.php on line 3, referer: http://ashesh.homeip.net/work/form.html
I also changed the form method to GET and checked the variable names and everything seems ok. Why is it then that PHP is having issues with recognizing the variables? Help please!
Last edited by ashesh0326; 05-05-2007 at 09:14 AM.
The way you are codign the php worked many years ago but now alas is doesn't. It's actually a security thing but to get it working the submitted data is held in a superglobal called $_POST.
So try something like $_POST['submit'] to access the submit details.
Hi guys, I'm sorry about the double post.
It now seems like the problem was not with the code, but with the php.ini file. I checked and saw that the global variables had not been enabled, and since I enabled them, and restarted apache, there have been no problems.
The reason global variables is disabled is because of security reasons, the way to code it without globals being set is by using the $_POST super global variable. It is a good idea to use this because almost all web hosts will have it disabled and so you code will then be portable, and it gets you in to the practice of using this technique. Also I believe that the global variables directive is due to be phased out in the next major release of PHP.
Thank you Graemef. I had seen in the php.ini file that it had been mentioned that the global variables have been disabled for security issues, and I did not know about the $_POST[] or the $_GET[] arrays. Thank you so much for letting me know. I'll disable the global variables and use these arrays from now on. They look like more fun too.
By the way, speaking of security issues, can you please elaborate as to what kind of issues can be caused by using global variables? I'm just curious.
Anyways, thank you so much for your time. I really learnt something
There is a section that covers this in the manual under the part on security (in my copy it is chapter 29)
Essentially it will allow a cracker to try and manipulate your site by setting variable values that shouldn't be set. The help file chapter on Using Register Globals has a few example of how this can happen by sending the data in as a GET variable (that is include the data on the URL: In the example with the $authorized variable the URL might be tweaked as follows: www.mysite.org/results.php?authorized=true, with register globals on $authorized would be set to true, otherwise it would be $_GET['authorized'] that is set to true)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.