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
https://forums.phpfreaks.com/topic/30415-help-with-db/
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
https://forums.phpfreaks.com/topic/30415-help-with-db/#findComment-140006
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
https://forums.phpfreaks.com/topic/30415-help-with-db/#findComment-140013
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
https://forums.phpfreaks.com/topic/30415-help-with-db/#findComment-140014
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.