guestbook online [Solved]

Problems with the Windows version of XAMPP, questions, comments, and anything related.

guestbook online [Solved]

Postby MANGANIX » 07. August 2012 21:17

Hi,

I couldn't find a clear answer to my following problem:

I made a guestbook, which works just fine in localhost and connects without problem to the guestbook DB (phpMyAdmin).
Code: Select all
(mysql_connect ('localhost','root','password') && mysql_select_db ('guestbook'))


But when I put my guestbook.php on my online server, I can't connect to the guestbook DB, even when I change the localhost to the online server.

Beside my guestbook document (guestbook.php), which XAMPP-items (folder, docs, ..) should be uploaded to the webserver?

I'm very very new to (PHP/SQL/webdev, ...), thanks for helping me out!

Regards

Full code guestbook:

Code: Select all
<?php

if (mysql_connect ('localhost','root','password') && mysql_select_db ('guestbook')) {
   $time = time();
   $errors = array();
   
if (isset($_POST['guestbook_name'], $_POST['guestbook_email'],$_POST['guestbook_message'])) {
   $guestbook_name = mysql_real_escape_string (htmlentities ($_POST['guestbook_name']));
   $guestbook_email = mysql_real_escape_string (htmlentities ($_POST['guestbook_email']));
   $guestbook_message = mysql_real_escape_string (htmlentities ($_POST['guestbook_message']));

if (empty ($guestbook_name) || empty ($guestbook_email) || empty ($guestbook_message)) {
   $errors[] = 'All fields are required.';
}
      
if (strlen ($guestbook_name)>25 || strlen ($guestbook_email)>255 || strlen ($guestbook_message)>255) {
   $errors[] = 'One or more feelds exceed the character limit.';
}
      
if (empty ($errors)) {
   $insert = "INSERT INTO entries VALUES ('', '$time', '$guestbook_name', '$guestbook_email', '$guestbook_message')";
         
if (mysql_query ($insert)) {
   header ('Location: '.$_SERVER ['PHP_SELF']);
} else {
   $errors[] = 'Something went wrong, please try again later. Thanks.';
}
} else {
   foreach($errors as $error) {
   echo '<p><strong>'.$error.'</strong></p>';
}
}
}
   
   $entries = mysql_query ("SELECT `timestamp`, `name`, `email`, `message` FROM `entries` ORDER BY `timestamp` DESC");
if (mysql_num_rows ($entries)==0) {
   echo '<br>No messages posted yet.';
} else {
   while ($entries_row = mysql_fetch_assoc ($entries)) {
   $entries_timestamp = Date ('D, d-M Y @ h:i:s', $entries_row ['timestamp']);
   $entries_name = $entries_row ['name'];
   $entries_email = $entries_row ['email'];
   $entries_message = $entries_row ['message'];
   
   echo '<p><strong>Message posted by:</strong> <br> <strong>Name:</strong> '.$entries_name.' <br> <strong>Email:</strong> '.$entries_email.' <br> <strong>Date:</strong> '.$entries_timestamp.'</strong> <br> '.$entries_message.'<hr width="600" style="border: 1px dotted #0099CC" color="#66FFFF" size="1"></p>';
   
}
}
   
} else {
   echo 'Could not establish connection.';
}
?>

<!--<hr>-->

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">
<!--<strong> Share your thouhgts with us by leaving a message.</strong><br><br>-->
<br><br>Name:<br><input type:"text" name="guestbook_name" maxlength="25"><br>
Email:<br><input type:"text" name="guestbook_email" maxlength="255"><br>
Message:<br><textarea name="guestbook_message" rows="10" cols="70" maxlength="255"></textarea><br>
<input type="submit" value="Submit Comment">
</form>
MANGANIX
 
Posts: 3
Joined: 07. August 2012 20:26
Operating System: windows 7

Re: guestbook online

Postby Altrea » 07. August 2012 21:28

Hi MANGANIX,

MANGANIX wrote:But when I put my guestbook.php on my online server, I can't connect to the guestbook DB, even when I change the localhost to the online server.

relating to your online database:
  • Does the database exists?
  • Does the database user exists?
  • Is the username password combination correct?
  • Does the user have the correct permission from the host you connect?
  • Do you get any error messages?

MANGANIX wrote:Beside my guestbook document (guestbook.php), which XAMPP-items (folder, docs, ..) should be uploaded to the webserver?

All files and folders that are needed by your guestbook script. nothing more static files are needed.
But you need to create the database structure your script needs, so this have to be created too.

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8293
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: guestbook online

Postby MANGANIX » 07. August 2012 22:28

thanks for the quick reply.
The database + password + user exist in localhost ... is accessible in localhost.
How to get this phpMyAdmin database from local to online?

Thanks!
MANGANIX
 
Posts: 3
Joined: 07. August 2012 20:26
Operating System: windows 7

Re: guestbook online

Postby Altrea » 08. August 2012 00:45

MANGANIX wrote:How to get this phpMyAdmin database from local to online?

That depends on your hoster.
very common you can export your local database structure and data and reimport it to your online database with phpMyAdmin too.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8293
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: guestbook online

Postby MANGANIX » 08. August 2012 02:33

OK I've got it working, finally!

I was missing the whole point of local vs online databases.

Import / export didn't work out for me or my hoster, so I had to replicate my local database online.

Thx for the help!
MANGANIX
 
Posts: 3
Joined: 07. August 2012 20:26
Operating System: windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 59 guests