Hi there, am a new member and i have some questions relating to php and mysql. I have designed a form to beused to aply for various courses offered in my college. when the users click the submit button the information is supposed to be sent to my local server in the registration Database created with mysql. I tried to test the connection to the database while at my local server using the following code but the computer does not display anything:
<?php
$name="patric";
$hostname="localhost";
$pass=":depash";
$conn=mysql_connect($pass);
or die("Unable to connect to MySQL");
echo "Connected to MySQL";
//select a database to work with
$selected = mysql_select_db("StudReg",$conn)
or die("Could not select patric");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM feedback");
//fetch tha data from the database
while ($row = mysql_fetch_array($result))
{
echo "name:".$row{'name'}." comments:".$row{'comments'}.; //display the results
<br>
}
?>
What is the problem with my code?
Is it Ok to test the connection to the database while at the host?
Why didn't i get an error message if it failed to connect or the confirmaton message after success?
Help me create a successful connection to the database please. The database name is StudReg and the table is feedback. I tested my php installation and it was fine.
Thanks alot Shakeel for your quick reply. After i entered the code you supplied i received the following on the screen when i open the file:
;}
?>
What would this imply cause after i check the code this happens to be the last semicolon to terminqte the last statement and the php close statement? Is it fine to try and run the page on the same place where the database is?
Your first script has several errors (mysql_connect() requires 3 parameters: host, user and password, and you're missing a semicolon on the echo statement). I don't see any errors in shakeel's code, so check closely for a missing semicolon or closing quotation mark. There is nothing at all wrong with connecting on the same computer as the web server and database are on, indeed that's what is meant by "localhost".
If you include code in a subsequent post, please enclose it in [ code=php] and [ /code] tags (without the space following the opening bracket), to display it as I have just edited your original post, to make it easier for us to read. Thank you.