Dear all
I have a few questions. I would be grateful if you could take the time to answer.
I have installed on windows xp home apache2, php 5 and mysqlserver 5. The http://localhost page of apache works fine.
The <?php echo phpinfo(); ?> page works fine. However when i am trying to query a database i have in mysql i get a blank page.
I cannot find what is the problem.
For example:
html>
<body>
<?php
$host = "localhost";
$user = "user";
$pass = "hello";
$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server");
mysql_create_db("test") or mysql_error();
?>
</body>
</html>
I am getting back a blank page.
I've also noticed the following problem
<HTML>
<FORM>
Please type your name here:<BR>
<INPUT TYPE="TEXT" NAME="username"><BR><BR>
<INPUT TYPE=SUBMIT VALUE="Submit data">
You typed:
<?php
echo ($username);
?>
</FORM>
</HTML>
I use the above test.php script located in apache's htdocs. However although i can see the value i submit in the url of the page
i can't see it after the string You typed:
I put both examples so maybe someone could tell me what to try.

Many thanks in advance
Cheers

well im not sure about the mysql part because I just use WAMP server which sets it all up for you.
But for the form I can see what is wrong you need to set a form method and a form action so here is how I believe you would do it to set it to use local php

<html>
<head>
</head>
<body>
 <form method="post" action="SEVER_[PHP_SELF]">
Please input your name here: <br />
<input type="text" name="username" />
<input type="submit" value="Submit Data" />
</form>
<p> You typed </p>
<?php
 $username = $_POST['username'];
 echo $username;
?>
</body>
</html>

Now im not sure about the action but i believe that is how you do it.

<html>
<body>
<?php
$host = "localhost";
$user = "user";
$pass = "hello";
$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server");
mysql_create_db("test") or mysql_error();
?>
</body>
</html>

There is no problem here, you are just not generating any content to display on the page. You will only get generated content if there is an error in either the connection to the server, or there is an error in your sql.

<HTML>
<FORM>
Please type your name here:<BR>
<INPUT TYPE="TEXT" NAME="username"><BR><BR>
<INPUT TYPE=SUBMIT VALUE="Submit data">
You typed:
<?php
echo ($username);
?>
</FORM>
</HTML>

The problem with the form page is that you need to reference the REQUEST object to collect data from it. In this case, as you have not specified an ACTION for the form, then the default GET action is used. You can then retrieve values from the REQUEST object by using:

<?php
echo ($_GET['username']);
?>

Alternatives to this are to set the form ACTION to POST, then use:

<?php
 echo ($_POST['username']);
 ?>

or if you are uncertain as to whether the data will come from a POST or GET, then you can use the generic REQUEST:

<?php
 echo ($_REQUEST['username']);
 ?>

GET is more used if you are getting information from a url or something like something like
http://www.somesite.com/script.php?image=3

then you could use like
$image = $_GET;

and if you then said
echo $image;

it would say 3.

and to see a return to wether or not the mysql is working do this

$host = "localhost";
$user = "user";
$pass = "hello";
$connect = mysql_connect($host, $user, $pass) or die("Could not connect to mysql server");
$sql = mysql_create_db("test");
if (!sql) {
  echo "there was an error" . mysql_error();
}
else {
 echo "database test was created";
}

or something like that. but your form isnt doing anything with the data base so to put it further you need to create a table and insert the value into the table.

hello,
i have a website and it works with mysql but i can`t set this mysql i have it saved and i import it on phpmyadmin create username and password but still dosen`t work.also i change the config file... please help me with this issue.
I can provide you the information to look at it because i don`t know very good to work with it.
i only need to lear like a robot wat i have to do!
:)
THX

This article has been dead for over six months. Start a new discussion instead.