{"id":26582,"date":"2022-12-18T19:08:48","date_gmt":"2022-12-18T13:38:48","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/"},"modified":"2022-12-18T19:08:48","modified_gmt":"2022-12-18T13:38:48","slug":"solved-preventing-duplicates-in-the-database-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/","title":{"rendered":"[Solved] Preventing duplicates in the database  [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-11202539\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"11202539\" data-parentid=\"11200978\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>I update your code.<\/p>\n<pre><code>&lt;?php\n    mysql_connect(\"localhost\", \"root\", \"\") or die(mysql_error()); \n    mysql_select_db(\"database\") or die(mysql_error());\n?&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Student list&lt;\/title&gt;\n&lt;link href=\"https:\/\/stackoverflow.com\/questions\/11200978\/stylesheets\/public.css\" media=\"all\" rel=\"stylesheet\" type=\"text\/css\"\/&gt;\n&lt;\/head&gt;\n&lt;body id=\"background\"&gt;\n&lt;table &gt;\n  &lt;tr&gt;\n    &lt;td&gt;&lt;img src=\" images\/Picture3.png\" width=\"1300\" height=\"150\"\/&gt;&lt;\/td&gt;\n  &lt;\/tr&gt;\n&lt;\/table&gt;\n&lt;table&gt;\n  &lt;tr&gt;\n    &lt;td id=\"structure\"&gt;\n    &lt;? \n    \/\/ check for post data\n    if( isset($_POST['name']) &amp;&amp; isset($_POST['email']) &amp;&amp; isset($_POST['shift']) &amp;&amp; isset($_POST['class']) &amp;&amp; isset($_POST['id']) )\n    {\n        $name=$_POST['name']; \n        $email=$_POST['email']; \n        $shift=$_POST['shift'];\n        $class=$_POST['class'];\n        $id=$_POST['id'];\n\n        $username = $_POST['name']; \/\/ you must escape any input. Remember.\n\n        $query = \"SELECT * FROM `data` WHERE `name` = '\".$username.\"'\";\n\n        $result = mysql_query($query);\n        \/\/ check for duplicate\n        if ( mysql_num_rows ( $result ) &gt; 1 )\n        {\n            echo 'Username already exists';\n        }\n        else\n        {\n            \/\/ insert new record\n            mysql_query(\"INSERT INTO `data`(name,email,shift,class) VALUES ('\".$name.\"', '\".$email.\"', '\".$shift.\"','\".$class.\"')\");  \n            print \"Your information has been successfully added to the database.\"; \n        }\n    }\n\n    \/\/ list data\n    $data = mysql_query(\"SELECT * FROM data\")  or die(mysql_error()); \n    print \"&lt;table border cellpadding=5&gt;\"; \n    while($info = mysql_fetch_array( $data )) \n    {\n        print \"&lt;tr&gt;\";\n        print \"&lt;th&gt;Id:&lt;\/th&gt;&lt;td&gt;\".$info['id'].\"&lt;\/td&gt;\";\n        print \"&lt;th&gt;Name:&lt;\/th&gt; &lt;td&gt;\".$info['name'] . \"&lt;\/td&gt; \"; \n        print \"&lt;th&gt;Email:&lt;\/th&gt; &lt;td&gt;\".$info['email'] . \" &lt;\/td&gt;\";\n        print \"&lt;th&gt;shift:&lt;\/th&gt; &lt;td&gt;\".$info['shift'] . \" &lt;\/td&gt;\";\n        print \"&lt;th&gt;class:&lt;\/th&gt; &lt;td&gt;\".$info['class'] . \" &lt;\/td&gt;\";\n        print \"&lt;tr&gt;&lt;td&gt;&lt;a href=\"update.php?id={$info[\"id']}'&gt;EDIT&lt;\/a&gt;&lt;\/td&gt;&lt;\/tr&gt;\";\n        print \"&lt;tr&gt;&lt;td&gt;&lt;a href=\"delete.php?id={$info[\"id']}'&gt;DELETE&lt;\/a&gt;&lt;\/td&gt;&lt;\/tr&gt;\";\n    } \n    print \"&lt;\/table&gt;\"; \n\n  ?&gt;\n  &lt;\/td&gt;\n  &lt;\/tr&gt;\n&lt;\/table&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">3<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Preventing duplicates in the database  [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I update your code. &lt;?php mysql_connect(&#8220;localhost&#8221;, &#8220;root&#8221;, &#8220;&#8221;) or die(mysql_error()); mysql_select_db(&#8220;database&#8221;) or die(mysql_error()); ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Student list&lt;\/title&gt; &lt;link href=&#8221;https:\/\/stackoverflow.com\/questions\/11200978\/stylesheets\/public.css&#8221; media=&#8221;all&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text\/css&#8221;\/&gt; &lt;\/head&gt; &lt;body id=&#8221;background&#8221;&gt; &lt;table &gt; &lt;tr&gt; &lt;td&gt;&lt;img src=&#8221; images\/Picture3.png&#8221; width=&#8221;1300&#8243; height=&#8221;150&#8243;\/&gt;&lt;\/td&gt; &lt;\/tr&gt; &lt;\/table&gt; &lt;table&gt; &lt;tr&gt; &lt;td id=&#8221;structure&#8221;&gt; &lt;? \/\/ check for post data if( isset($_POST[&#8216;name&#8217;]) &amp;&amp; isset($_POST[&#8217;email&#8217;]) &amp;&amp; isset($_POST[&#8216;shift&#8217;]) &amp;&amp; isset($_POST[&#8216;class&#8217;]) &#8230; <a title=\"[Solved] Preventing duplicates in the database  [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/\" aria-label=\"More on [Solved] Preventing duplicates in the database  [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[546,339],"class_list":["post-26582","post","type-post","status-publish","format-standard","hentry","category-solved","tag-database","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] Preventing duplicates in the database [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Preventing duplicates in the database [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I update your code. &lt;?php mysql_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;) or die(mysql_error()); mysql_select_db(&quot;database&quot;) or die(mysql_error()); ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Student list&lt;\/title&gt; &lt;link href=&quot;https:\/\/stackoverflow.com\/questions\/11200978\/stylesheets\/public.css&quot; media=&quot;all&quot; rel=&quot;stylesheet&quot; type=&quot;text\/css&quot;\/&gt; &lt;\/head&gt; &lt;body id=&quot;background&quot;&gt; &lt;table &gt; &lt;tr&gt; &lt;td&gt;&lt;img src=&quot; images\/Picture3.png&quot; width=&quot;1300&quot; height=&quot;150&quot;\/&gt;&lt;\/td&gt; &lt;\/tr&gt; &lt;\/table&gt; &lt;table&gt; &lt;tr&gt; &lt;td id=&quot;structure&quot;&gt; &lt;? \/\/ check for post data if( isset($_POST[&#039;name&#039;]) &amp;&amp; isset($_POST[&#039;email&#039;]) &amp;&amp; isset($_POST[&#039;shift&#039;]) &amp;&amp; isset($_POST[&#039;class&#039;]) ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-18T13:38:48+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Preventing duplicates in the database [closed]\",\"datePublished\":\"2022-12-18T13:38:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/\"},\"wordCount\":20,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"database\",\"php\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/\",\"name\":\"[Solved] Preventing duplicates in the database [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-12-18T13:38:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-preventing-duplicates-in-the-database-closed\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Preventing duplicates in the database [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Preventing duplicates in the database [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Preventing duplicates in the database [closed] - JassWeb","og_description":"[ad_1] I update your code. &lt;?php mysql_connect(\"localhost\", \"root\", \"\") or die(mysql_error()); mysql_select_db(\"database\") or die(mysql_error()); ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Student list&lt;\/title&gt; &lt;link href=\"https:\/\/stackoverflow.com\/questions\/11200978\/stylesheets\/public.css\" media=\"all\" rel=\"stylesheet\" type=\"text\/css\"\/&gt; &lt;\/head&gt; &lt;body id=\"background\"&gt; &lt;table &gt; &lt;tr&gt; &lt;td&gt;&lt;img src=\" images\/Picture3.png\" width=\"1300\" height=\"150\"\/&gt;&lt;\/td&gt; &lt;\/tr&gt; &lt;\/table&gt; &lt;table&gt; &lt;tr&gt; &lt;td id=\"structure\"&gt; &lt;? \/\/ check for post data if( isset($_POST['name']) &amp;&amp; isset($_POST['email']) &amp;&amp; isset($_POST['shift']) &amp;&amp; isset($_POST['class']) ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/","og_site_name":"JassWeb","article_published_time":"2022-12-18T13:38:48+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Preventing duplicates in the database [closed]","datePublished":"2022-12-18T13:38:48+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/"},"wordCount":20,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["database","php"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/","name":"[Solved] Preventing duplicates in the database [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-12-18T13:38:48+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-preventing-duplicates-in-the-database-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Preventing duplicates in the database [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/26582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=26582"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/26582\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=26582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=26582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=26582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}