ChaosKnight Posted April 17, 2010 Share Posted April 17, 2010 Hi, can somebody see why this code does absolutely nothing? <?php session_start(); include("dbstuff.inc"); $link = mysql_connect($host,$username,$password) if (!$link) die("Couldn't connect to server"); echo "Connected successfully"; $select = mysql_select_db($db); if (!$select) die("couldn't connect to database"); echo "Connected to database"; $date = date("Y-m-d H:i:s"); foreach ($_POST as $field => $value) { $$field = strip_tags(trim($value)); } $sql = "INSERT INTO contact (name,email,heading,message,unread,date_created) VALUES ('$name','$email','$heading','$message','yes','$date')"; mysql_query($sql,$link); mysql_close($link); header("Location: index.php?page=contact"); ?> It gets sent via a normal HTML post form. When I tried it on localhost without the database lines and echoed the variables it worked perfectly.. So I guess something is wrong with the database lines? The database host, username, password and database name also gets returned as expected, so nothing is wrong with that. The problem is that absolutely nothing else gets returned... The page is completely blank, it doesn't even execute the header("location: ...") command. Oh, and the shared host that I'm on doesn't support mysqli, just for in case you wondered... Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 17, 2010 Share Posted April 17, 2010 Messy code. Try this. <?php session_start(); include("dbstuff.inc"); $link = mysql_connect($host,$username,$password) if (!$link) { die("Couldn't connect to server"); } else { echo "Connected successfully"; } $select = mysql_select_db($db); if (!$select) { die("couldn't connect to database"); } else { echo "Connected to database"; } $date = date("Y-m-d H:i:s", time()); foreach ($_POST as $field => $value) { $$field = strip_tags(trim($value)); } $sql = "INSERT INTO contact (name,email,heading,message,unread,date_created) VALUES ('$name','$email','$heading','$message','yes','$date')"; mysql_query($sql,$link) or die(mysql_error()); mysql_close($link); header("Location: index.php?page=contact"); ?> Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted April 17, 2010 Author Share Posted April 17, 2010 Mmm... It still doesn't work, it sends back a completely blank page, no code, no nothing... Any suggestions? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2010 Share Posted April 17, 2010 Line 3 missing semicolon. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 17, 2010 Share Posted April 17, 2010 Could of been your issue in the first place Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted April 17, 2010 Author Share Posted April 17, 2010 Do you know how much I love you right now?? Thanks to TeddyKiller and Pikachu2000 for all your help! And to Pikachu's eagle eyes LOL Problem solved!! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2010 Share Posted April 17, 2010 It may behoove you to enable error reporting. Also, you should rename your dbstuff.inc file to a .php extension so it isn't viewable in a web browser, for obvious reasons. 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.