Pages: 12Next
Current Page: 1 of 2
cannot connect to database
Posted by: emick (183.171.163.---)
Date: March 26, 2013 04:08AM

somebody help me to find way how to resolve my prob. this is my code.

<html>
<head>
<title>Contact Us</title>
<link rel = "stylesheet" type = "text/css" href = "cssmenu.css">
<link rel = "stylesheet" type = "text/css" href = "table.css">
<link rel = "stylesheet" type = "text/css" href = "body.css">
<link rel = "stylesheet" type = "text/css" href = "toplink.css">

<body id = 'body'>
<img src = "../images/banner.jpg" align = "left" width = "20%" id = 'banner'>
<center><form method="post" action="<?php echo $PHP_SELF?>" id = 'textlogin'>
User ID <input type="Text" name="UserId" id = 'tb'>
Password <input type="Text" name="Name" id = 'tb'>
<input type="Submit" name="submit" value="Sign In" id = 'button'>
<input type="Submit" name="submit" value="Sign Up" id = 'button1'>
<br>

</a>
</form></center>
<br><br><br>
<div id='cssmenu'>
<ul>
<li><a href='index.html'><span>Home</span></a></li>
<li><a href='#'><span>About</span></a></li>
<li><a href='#'><span>Menu</span></a></li>
<li class='has-sub'><a href='#'><span>Services</span></a>
<ul>
<li><a href='#'><span>Services List</span></a></li>
<li><a href='#'><span>New Services</span></a></li>
<li class='last'><a href='#'><span>Featured Services</span></a></li>
</ul>
</li>
<li><a href='#'><span>Recipes</span></a></li>
<li><a href='#'><span>What Is New</span></a></li>
<li class='last'><a href='contact.html'><span>Contact Us</span></a></li>
</ul>
</div>
<br>
<?php
//$db = mysql_connect("localhost", "root"winking smiley;
//mysql_select_db("coffeehouse",$db);
//$result = mysql_query("SELECT * FROM comment",$db);

if(isset($_POST['submit'])) {
// process form
$db = mysql_connect("localhost", "root"winking smiley;
mysql_select_db("coffeehouse",$db);
$sql = "INSERT INTO comment (UserId, Name, Email, Comment)
VALUES
('$UserId','$Name','$Email','$Comment')";

$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>
<center><table><tr><td>
<form method="post" action="<?php $PHP_SELF?>">
User ID: <input type="Text" name="UserId"><br><br>
Name: <input type="Text" name="Name"><br><br>
Email: <input type="Text" name="Email"><br><br>
Comment: <TextArea name="Comment"></textarea><br><br>
<input type="Submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</form></td><tr></table></center>
<?php
} // end if
?>
</body>
</html>

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 26, 2013 09:16AM

So what is the actual error you are getting?

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.175.---)
Date: March 26, 2013 09:48AM

the data that user input in form didt save in database. may you help me?

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.175.---)
Date: March 26, 2013 09:50AM

there is no error on my coding.

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 26, 2013 10:02AM

Possibly you see no errors because you are not checking for them.

Can you add this code after the connect please.


if ( ! $db ) {
    die( 'Could not connect: ' . mysql_error() );
}
echo 'Connected successfully';


Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.175.---)
Date: March 26, 2013 10:20AM

it doesnt working, or maybe i have problem in my database? i have 1 table in my db and 4 columns. primary key is UserId. 2

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 26, 2013 10:33AM

What was the result of adding the test i suggested?

An error message or a display of 'Connected successfully' ????

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.175.---)
Date: March 26, 2013 10:48AM

the msg didnt appear, only "Thank you! Information entered" that appear.

$db = mysql_connect("localhost", "root"winking smiley;
if ( ! $db ) {
die( 'Could not connect: ' . mysql_error() );
}
echo 'Connected successfully'
mysql_select_db("coffeehouse", $db);
$sql = "INSERT INTO comment (UserId, Name, Email, Comment)
VALUES
('$UserId','$Name','$Email','$Comment')";

$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>

is my coding true?

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 26, 2013 12:36PM

It must have output 1 of those messages. Either 'Could not connect: ' OR 'Connected successfully'

Have you looked at your php error log ??

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.169.---)
Date: March 26, 2013 06:27PM

no the msg didnt appear either 'Could not connect: ' or 'Connected successfully'. i've look at my php error log, thre is nothing there.

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 26, 2013 07:02PM

Well then you are not running this script !! Is that possible ??

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.175.---)
Date: March 26, 2013 08:24PM

i hv no idea bout this coding. i've it try on xampp then got nothing error and it was connected to db. btw i have to use wamp for this project. sad smiley

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 27, 2013 11:30AM

Did you properly uninstall XAMPP, this may be causing the strange results.
XAMPP and WAMP are basically the same thing and if xampp's apache and mysql are running it could be causing problems.

By the way, what colour is the wamp manager icon in the system tray??

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.168.---)
Date: March 28, 2013 05:37AM

no, im use wamp on my laptop and xampp on my another pc. the icon color when it's online is green on red on offline.

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 28, 2013 10:06AM

Forget online and offline that is not relevent!

What colour is the wamp manager icon when you launch it from the desktop icon??

If should be green if both Apache and MySQL have started.


I just had a thought, do a search for these files and if you find them outside the \wamp folder then delete them.

Search for:-

my.ini
my.cnf

You may find them somewhere in the C:\windows folder structure.

DONT delete the ones you find below your \wamp folder

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.167.---)
Date: March 28, 2013 10:39AM

pink. ok now i have another prob. i reinstall the wamp, but i cant access phpMyAdmin.

#2002 - No connection could be made because the target machine actively refused it.

The server is not responding (or the local server's socket is not correctly configured).

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 28, 2013 10:59AM

If wamp icon is NOT green then one of the services has not started. FIND OUT WHICH!

wampmanager -> Apache -> Service
If the Restart/Resume service if GREEN then Apache has not started

wampmanager -> MYSQL -> Service
If the Restart/Resume service if GREEN then MYSQL has not started


Which one is not started???

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.167.---)
Date: March 28, 2013 11:19AM

MYSQL

Options: ReplyQuote
Re: cannot connect to database
Posted by: RiggsFolly (---.as13285.net)
Date: March 28, 2013 11:23AM

Ok re my previous post

search for my.ini and my.cnf in strange places, please read the previous port before deleting anything

Options: ReplyQuote
Re: cannot connect to database
Posted by: emick (183.171.167.---)
Date: March 28, 2013 11:26AM

i've deleted it. but i still have same prob. do you have teamviewer?

Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


Sorry, only registered users may post in this forum.