Problems reading mysql with php.
Posted by: 00stuff (---.rgv.res.rr.com)
Date: December 28, 2009 09:01AM

I installed Wampserver2.0 on my winxp laptop. I wanted to practice my php with mysql without having to upload and and edit my code every time to my webspace. I installed it and php seems to work fine but I created a database and made a table with some info in it so i can display it on a page. When I run the page it doesn't display anything from the mysql database. it's like if has trouble connecting. I put the script to connect to localhost and user I set to root and password left blank. Is that how it is suppost to work if I left the user and pass default? Here is a copy of the script i used.



<?
// Use session variable on this page. This function must put on the top of page.
session_start();

////// Logout Section. Delete all session variable.
session_destroy();

$message="";

////// Login Section.
$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$md5_password=md5($_POST['password']); // Encrypt password with md5() function.

// Connect database.
$host="localhost"; // Host name.
$db_user="root"; // MySQL username.
$db_password=""; // MySQL password.
$database="tutorial"; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

// Check matching of username and password.
$result=mysql_query("select * from admin where username='$username' and

password='$md5_password'"winking smiley;
if(mysql_num_rows($result)!='0'){ // If match.
session_register("username"winking smiley; // Craete session username.
header("location:main.php"winking smiley; // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}

} // End Login authorize check.
?>

<html xmlns="[www.w3.org];
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<? echo $message; ?>
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table>
<tr>
<td>User : </td>
<td><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td>Password : </td>
<td><input name="password" type="password" id="password" /></td>
</tr>
</table>
<input name="Login" type="submit" id="Login" value="Login" />
</form>
</body>
</html>




Can anyone tell me if it is right? please.

Options: ReplyQuote
Re: Problems reading mysql with php.
Posted by: yfastud (Moderator)
Date: December 28, 2009 11:55PM

use full tag <?php if short_open_tag is not enable in php.ini file

to setup password w/ md5, follow this
[jlbn.net]

btw, this forums is for wampserver, not coding, so you should join some other coding forums for coding discussions; thanks winking smiley

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote


Sorry, only registered users may post in this forum.