{"id":147,"date":"2012-03-15T18:00:20","date_gmt":"2012-03-15T18:00:20","guid":{"rendered":"http:\/\/codebangers.com\/?p=147"},"modified":"2012-03-15T18:26:16","modified_gmt":"2012-03-15T18:26:16","slug":"php-script-that-inserts-into-mysql-easy","status":"publish","type":"post","link":"https:\/\/codebangers.com\/php-script-that-inserts-into-mysql-easy\/","title":{"rendered":"PHP Script that inserts into Mysql Easy"},"content":{"rendered":"<p>Simple enough. You need to have a php script that inserts into your mysql database.<\/p>\n<p>Example:<br \/>\n<code><br \/>\n<!--?php $con = mysql_connect(\"localhost\",\"peter\",\"abc123\"); if (!$con)   {\n   die('Could not connect: ' . mysql_error());   } mysql_select_db(\"my_db\", $con);\n mysql_query(\"INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin',35)\");\n mysql_query(\"INSERT INTO Persons (FirstName, LastName, Age)  VALUES ('Glenn', 'Quagmire',33)\");\n mysql_close($con); ?--><br \/>\n<\/code><\/p>\n<p>Here&#8217;s the Html for the form<br \/>\n<code><\/p>\n<form action=\"insert.php\" method=\"post\">\nFirstname:<input type=\"text\" name=\"firstname\" \/><br \/>\nLastname: <input type=\"text\" name=\"lastname\" \/><br \/>\nAge: <input type=\"text\" name=\"age\" \/> <input type=\"submit\" \/><\/form>\n<p><\/code><br \/>\nHere is your insert script. I would name it &#8220;insert.php&#8221;.<br \/>\n<code><br \/>\n<!--?php $con = mysql_connect(\"localhost\",\"peter\",\"abc123\"); if (!$con)   {   die('Could not connect: ' . mysql_error());\n   } mysql_select_db(\"my_db\", $con); $sql=\"INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')\";\n if (!mysql_query($sql,$con))   {   die('Error: ' . mysql_error());   } echo \"1 record added\"\n; mysql_close($con) ?--><br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple enough. You need to have a php script that inserts into your mysql database. Example: Here&#8217;s the Html for the form [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":41,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":6,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/147\/revisions\/153"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/media\/41"}],"wp:attachment":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}