kristiankeith Posted March 1, 2012 Share Posted March 1, 2012 If anyone can assist me I would appreciate it. I have been trying to make this work for the past 3 days. I am doing a simple guestbook with PHP into MySQl and it connects, the ID and Date stamps work and appear in the guestbook but the name, email, hometown and comments do not. Here is the code. Again thank you in advance for any assistance. <body bgcolor="#000000"> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server"); mysql_select_db("$db_name")or die("cannot select DB"); $date=date("y-m-d"); //date $sql="INSERT INTO $tbl_name(name, email, hometown, comments, date)VALUES('$name','$email','$hometown','$comments','$date')"; $result=mysql_query($sql); //check if query successful if($result){ echo "Successful"; echo "<BR>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/ Share on other sites More sharing options...
mikosiko Posted March 1, 2012 Share Posted March 1, 2012 in the posted code, none of this variables '$name','$email','$hometown','$comments' has been defined... how are you getting their values? Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1322920 Share on other sites More sharing options...
phppup Posted March 2, 2012 Share Posted March 2, 2012 I recognize the code (i was on that website TOO). And what I got needed to be tinkered with before it would work. Try re-reading the webpages before it to make sure any files or code that was used in a tutorial PRIOR to this one, are written properly and in your pocession. Check to make sure all the file names and field names follow the same structure. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1322941 Share on other sites More sharing options...
phppup Posted March 2, 2012 Share Posted March 2, 2012 I see what mikosiko is saying. Your DATE is being GIVEN on the same page. So date and ID (which I assume is automated by the table) are sort of a guarantee. If you're putting data in for the other fields from a form, you need to MATCH the 'name' in the form with the 'name' in this script so that it can be put into the table (make sense). Backtrack your steps, and make sure the form ACTION is naming THIS FILE with EXTENSION. Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1322942 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2012 Share Posted March 2, 2012 phpeasystep.com is a horrible site. Their examples are about 10 years out of date; don't use that site as a learning resource. Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1322989 Share on other sites More sharing options...
phppup Posted March 2, 2012 Share Posted March 2, 2012 Does out of date mean the code will NOT work?? They do have a friendly look and easy to follow instructions (even if they are WRONG... LOL) What sites DO you RECOMMEND as a learning tool? Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1323259 Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 Does out of date mean the code will NOT work?? They do have a friendly look and easy to follow instructions (even if they are WRONG... LOL) What sites DO you RECOMMEND as a learning tool? php.net and mysql.com Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1323260 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2012 Share Posted March 2, 2012 How do you think it came to be that I can recognize their code so easily? In many cases, it does mean the code will NOT work, then it ends up posted here. The best resource for php is the manual. http://www.php.net, IMO. Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1323262 Share on other sites More sharing options...
phppup Posted March 5, 2012 Share Posted March 5, 2012 Unfortunately, php.net is sometimes tOo 'technically oriented for a beginner to wade through, and their are no easy to understand example for the BEGINNERS. The other sites are EASILY understood..... although the code is flawed... LOL. Quote Link to comment https://forums.phpfreaks.com/topic/258078-only-id-and-date-is-writing-to-mysql/#findComment-1324163 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.