caps1277 Posted December 12, 2006 Share Posted December 12, 2006 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? Quote Link to comment Share on other sites More sharing options...
trq Posted December 12, 2006 Share Posted December 12, 2006 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] Quote Link to comment Share on other sites More sharing options...
sanfly Posted December 12, 2006 Share Posted December 12, 2006 Here dir(mysql_error());should be die(mysql_error());Obviously just a typo ;D Quote Link to comment Share on other sites More sharing options...
caps1277 Posted December 13, 2006 Author Share Posted December 13, 2006 entering that code, this is what i get:[color=blue]Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[/color] Quote Link to comment Share on other sites More sharing options...
sanfly Posted December 13, 2006 Share Posted December 13, 2006 so the problem lies in your connection code?Try posting it (NOT including user name and password) Quote Link to comment Share on other sites More sharing options...
sanfly Posted December 13, 2006 Share Posted December 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
caps1277 Posted December 13, 2006 Author Share Posted December 13, 2006 <?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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.