Jump to content

help with db


caps1277

Recommended Posts

hey guys, i've been working on a guestbook and i got it to work fully on my computer under the localhost address.  I have just tried to upload it to my site and have gotten some complications.  I have created a database on my webspace and also a table underneath it.  here is my code:

include 'connect.php';

[code=php:0]
if (isset($_POST["submit"]))
{
foreach ($_POST as $key => $value)
{
mysql_real_escape_string($value);
}

$name = $_POST["name"];
$country = $_POST["country"];
$email = $_POST["email"];
$im = $_POST["im"];
$comment = $_POST["comment"];

$addtodb = "insert into $dbname (name,country,email,im,comment)
values ('$name','$country','$email','$im','$comment')";

if (mysql_query($addtodb,$con))
{
header('Location: view.php');
}
else
{
echo "Sorry we could not add your message";
}

}
[/code]
for some reason, it doesn't add it to the db, all i get is the echo statement.  any ideas?
Link to comment
Share on other sites

Try some debugging. Firstly, the way your setup this piece of code does nothing.

[code=php:0]
foreach ($_POST as $key => $value)
{
mysql_real_escape_string($value);
}
[/code]

as for debugging, try....

[code=php:0]
$result = mysql_query($addtodb) or dir(mysql_error());
if ($result) {
  header('Location: view.php');
} else {
  echo "Sorry we could not add your message";
}
[/code]
Link to comment
Share on other sites

Actually, take a look at [url=http://www.tech-recipes.com/mysql_tips762.html]this page[/url]

if this doesnt help, try [url=http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&rls=GGGL,GGGL:2006-20,GGGL:en&q=Can't+connect+to+local+MySQL+server+through+socket+'%2Fvar%2Flib%2Fmysql%2Fmysql.sock'+(2)]this page[/url]
Link to comment
Share on other sites

<?php

$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'pw';

$con = mysql_connect($dbhost, $dbuser, $dbpass) or die("Error " . mysql_error());

$dbname = 'db189965288';

mysql_select_db($dbname,$con)or die("Error " . mysql_error());

?>

i made the database in the control panel of my website... someone told me i have to put:

cpusername_databasename or something like that to get it to work.  tried that, didn't work either.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.