954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php/mysql configuration? queries do not return anything.


<?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();
?>

tzan2833
Newbie Poster
6 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 



Please input your name here:

You typed



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

mikeandike22
Nearly a Posting Virtuoso
1,496 posts since May 2004
Reputation Points: 33
Solved Threads: 19
 
<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]<?php
echo ($_GET['username']);
?>[/PHP]
Alternatives to this are to set the form ACTION to POST, then use:
[PHP]<?php
echo ($_POST['username']);
?>[/PHP] 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]<?php
echo ($_REQUEST['username']);
?>[/PHP]

Lafinboy
Junior Poster
172 posts since Jul 2004
Reputation Points: 16
Solved Threads: 7
 

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['image'];

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
[PHP]
$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";
}
[/PHP]

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.

mikeandike22
Nearly a Posting Virtuoso
1,496 posts since May 2004
Reputation Points: 33
Solved Threads: 19
 

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

grandgoodel
Newbie Poster
2 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Do you have the mysqli extension installed in your php.ini file?

Check it and if it's not follow the instructions here:
http://uk.php.net/mysqli

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 

i sent a private message... see if you can help me!

grandgoodel
Newbie Poster
2 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You