LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP-mySQL Issues. (https://www.linuxquestions.org/questions/programming-9/php-mysql-issues-550336/)

ashesh0326 05-01-2007 05:41 AM

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.

asommer 05-01-2007 07:36 AM

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.

ashesh0326 05-01-2007 08:51 AM

Well, it seems to be working now! The second option worked!
Thank you so much! :D

ashesh0326 05-05-2007 07:55 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'

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!

jiml8 05-05-2007 11:08 AM

You aren't supposed to post the same thing in two threads.

graemef 05-07-2007 12:23 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.

ashesh0326 05-07-2007 06:46 AM

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.

graemef 05-07-2007 09:14 PM

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.

ashesh0326 05-08-2007 12:27 AM

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

graemef 05-08-2007 01:53 AM

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)

ashesh0326 05-09-2007 12:12 PM

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!


All times are GMT -5. The time now is 10:29 AM.