LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-01-2007, 06:41 AM   #1
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Rep: Reputation: 15
Question PHP-mySQL Issues.


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 08:25 AM.
 
Old 05-01-2007, 08:36 AM   #2
asommer
Member
 
Registered: Mar 2003
Location: North Carolina
Distribution: Gentoo
Posts: 168

Rep: Reputation: 30
You probably don't have the MySQL bindings for PHP. Try:

Quote:
rpm -qa | grep php
You should see a package called php-mysql or something similar. If you don't you can install it by:

Quote:
yum install php-mysql
Then retry your program.
 
Old 05-01-2007, 09:51 AM   #3
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Original Poster
Rep: Reputation: 15
Well, it seems to be working now! The second option worked!
Thank you so much!
 
Old 05-05-2007, 08:55 AM   #4
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Original Poster
Rep: Reputation: 15
Question

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'

First, we have an html form that looks like this:
Quote:
<html>
<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>
</html>
And mypage.php is:
Quote:
<?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 10:14 AM.
 
Old 05-05-2007, 12:08 PM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
You aren't supposed to post the same thing in two threads.
 
Old 05-07-2007, 01:23 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
Old 05-07-2007, 07:46 AM   #7
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Original Poster
Rep: Reputation: 15
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.

Thank you anyway.
 
Old 05-07-2007, 10:14 PM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
Old 05-08-2007, 01:27 AM   #9
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Original Poster
Rep: Reputation: 15
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
 
Old 05-08-2007, 02:53 AM   #10
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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)
 
Old 05-09-2007, 01:12 PM   #11
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Original Poster
Rep: Reputation: 15
Thanks man. Now that is interesting. I had thought about the same potential problems, but I was thinking that it had to be something more complex.

Thank you for your time again!
 
  


Reply

Tags
fedora, functions, mysql, php


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
Issues with saving PHP session in MySQL on Fedora tonyl Fedora 1 08-01-2006 01:46 AM
Upgrade From FC3 to FC5: Issues with PHP/MYSQL windisch Programming 7 06-27-2006 02:36 PM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 09:54 PM
Apache 2, PHP and MYSQL Issues. carpediem Linux - Distributions 3 04-17-2004 09:11 AM
php-mysql-4.2.2-8.0.7 RPM issues, should I switch to redhat 9? jstander Linux - Software 1 05-20-2003 04:31 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration