Jump to content

[NOVICE] PHP 5.2.1 cannot recognize mysql functions


freakofphp

Recommended Posts

Hi everyone,

 

I am new to PHP/mySQL. I was wanting to test out whether PHP, mySQL and Apache HTTP Server work together, so I coded out a very basic "guestbook" application. It consists of the files "sign.php" and "create_entry.php". The former has a simple html form, and the latter processes this form and tries to add the contents of the form to a table "guestbook". The cope snippets for these are given below:

 

---sign.php---

 

<h2> Sign the Guestbook! </h2>

 

<form method=post action="create_entry.php">

 

<b> Name: </b>

<input type=text size=40 name=name>

<br>

<b> Location :</b>

<input type=text size=40 name=location>

<br>

<b> Email: </b>

<input type=text size=40 name=email>

<br>

<b> Home page URL: </b>

<input type=text size=40 name=url>

<br>

<b> Comments: </b>

<textarea name=comments cols=40 rows=4 wrap=virtual></textarea>

<br>

 

<input type=submit name=submit value="Sign!">

<input type=reset name=reset value="Start Over">

 

</form>

 

---end sign.php---

 

 

---create_entry.php---

<?php

 

mysql_connect("localhost", "root", "admin") or

die ("Could not connect to database");

mysql_select_db("guestbook") or

die ("Could not select the database");

 

if ($submit == "Sign!")

{

$query = "insert into guestbook(name, location, email,url,comments) values

('$name', '$location', '$email', '$url', '$comments')"

;

 

mysql_query($query) or die(mysql_error());

 

?>

 

<h2> Thanks!! </h2>

<h2> <a href="view.php"> View My Guestbook!!! </a> </h2>

 

<?php

}

 

else

{

include("sign.php");

}

?>

 

---end create_entry.php---

 

When I fill up the form on the "sign.php" page, all I get is a redirection to "create_entry.php", and the page is completely blank. The data is not inserted into the guestbook table either (I checked using the command line client bundled with mySQL).

 

I'm fairly sure that this is happening because of the fact that PHP does not recognize the mysql_connect() and mysql_select_db(). This is because I initially had these commands on a separate file called "dbconnect.php". When I ran the application, all I got after clicking submit on the form in the page "sign.php" was a redirection to "create_entry.php" with the commands typed as they are and an inclusion of the "sign.php" page. So I doubt if this is a problem connecting to the database because the message given under "die" did not get printed in the browser window.

 

I then discovered that mySQL functions are not built-in extensions with PHP 5.2.1. So, I enabled this from the control panel ---> add remove programs by installing the mySQL functions extension. This appeared to have no effect. I've even tried reinstalling Apache Server and PHP.

 

I'm now unsure of how to proceed as everything appears to be fine. Could there be an issue with my php.ini file?

 

Here are some more details which I hope will help resolve the issue:

 

PHP Version: 5.2.1

mySQL Version: 5.0

Apache HTTP Server Version: 2.2.4

 

mySQL instance username: root, password: admin (I use this to log in from the command line client, and every thing works fine)

I have also tried using localhost and 127.0.0.1 alternatively in the mysql_connect() function, but both don't work

My apache server listens on port 8000

My PHP scripts get executed normally otherwise

 

I've thrown in all the info I can muster. If there's anything more to be revealed, I will be glad to do so. Please help me out :( !

 

Warm Regards,

Sridhar

Link to comment
Share on other sites

Make a page with:

 

<?php phpinfo(); ?>

 

in it. Now look through the results for MySQL, if it is not there (which I don't think it is by default on Red Hat) you need to download the php source code and compile it yourself.

 

Yes. Ugh.

 

Or try using SQLite which I think is bundled with PHP by default.

 

monk.e.boy

Link to comment
Share on other sites

Thanks for your inputs monk.e.boy

 

I actually cut out only the database connectivity script and the sql insertion query into a new file and attempted to make it run. And it works!

 

That means the problem lies in my code in the two pages. I "beautified" the code by adding comas to the values of all the html attributes, checked the whether the form field names match etc.

 

But I still get the blank page when I fill out some sample data. I can now say that it isn't a problem with PHP recognizing mySQL (I set that right by reading the PHP manual), but I'm still puzzled as to why my application does not work (there's no errors with database connectivity, but neither does the data get added to the "guestbook" table nor do I get to view the HTML in the "create_entry.php" page after I submit the form) . Can anyone spot something which I seem to miss each time I check?

 

Your help is greatly appreciated.

 

Regards,

Sridhar

Link to comment
Share on other sites

Do a :

 

echo $sql

 

I use this *all* the time. Then use SQLog or whatever you use to debug the database, and copy and paste the SQL into this tool and run it. If it runs, then your PHP is wrong. If it errors, then your SQL construction is buggered.

 

Isolate the error, make a simple test case. Fix the error. Rise. Repeat.

 

monk.e.boy

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.