redarrow Posted February 18, 2009 Share Posted February 18, 2009 advance thank you. i need to no if i am using enum correct in the database, if a user selected 3 answer from a question i want it to match the database with insert, using enum, showing the correct results. is this the correct way please cheers. say i created this table mydata with a b c d $sql="CREATE TABLE mydata (questions ENUM('a', 'b', 'c', 'd') NOT NULL)"; $res1=mysql_query($sql)or die(mysql_error()); use this code to get the entry's write in the database from the posted form. <?php if(isset($_POST['submit'])){ $a=$_POST['a']; $b=$_POST['b']; $c=$_POST['c']; $d=$_POST['d']; $data=$a.$b.$c.$d; $sql1="INSERT INTO mydata(quistion)VALUES('$data')"; $res=mysql_query($sql1)or die(myysql_error()); } ?> <form method="POST" action=""> please choose three ansaws. <br><br> <input type="checkbox" name="a">A <input type="checkbox" name="b">B <input type="checkbox" name="c">C <input type="checkbox" name="d">D <br><br> <input type="submit" name="submit" value="send"> </form> if i inserted abc from the form will i get out from the database abc Link to comment https://forums.phpfreaks.com/topic/145722-solved-working-in-php-with-enum-help-please/ Share on other sites More sharing options...
Cal Posted February 18, 2009 Share Posted February 18, 2009 Not sure about you enum thing but you spelt the mysql_error() function wrong $res=mysql_query($sql1)or die(myysql_error()); Link to comment https://forums.phpfreaks.com/topic/145722-solved-working-in-php-with-enum-help-please/#findComment-765091 Share on other sites More sharing options...
redarrow Posted February 18, 2009 Author Share Posted February 18, 2009 ok spelling wrong it a quick example how to match enum with insert that all. forget spelling mistakes. i am guess you caternate the form data to match the database data using a insert i think i am wrong theo. Link to comment https://forums.phpfreaks.com/topic/145722-solved-working-in-php-with-enum-help-please/#findComment-765093 Share on other sites More sharing options...
redarrow Posted February 18, 2009 Author Share Posted February 18, 2009 tried it does not work why. i wont it to match abc from a insert then show the abc out put using enum. <?php if(isset($_POST['submit'])){ $a=$_POST['a']; $b=$_POST['b']; $c=$_POST['c']; $d=$_POST['d']; $data=$a.$b.$c.$d; $sql1="INSERT INTO mydata(quistion)VALUES('$data')"; $res=mysql_query($sql1)or die(mysql_error()); } ?> <form method="POST" action=""> please choose three ansaws. <br><br> <input type="checkbox" name="a" value="a">A <input type="checkbox" name="b" value="b">B <input type="checkbox" name="c" value="c">C <input type="checkbox" name="d" value="d">D <br><br> <input type="submit" name="submit" value="send"> </form> database info enum $sql="CREATE TABLE mydata (questions ENUM('a', 'b', 'c', 'd') NOT NULL)"; $res1=mysql_query($sql)or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/145722-solved-working-in-php-with-enum-help-please/#findComment-765102 Share on other sites More sharing options...
redarrow Posted February 18, 2009 Author Share Posted February 18, 2009 Dont work also strange. <?php if(isset($_POST['submit'])){ foreach($_POST['data'] AS $go ){ $sql1="INSERT INTO mydata(quistion)VALUES('$go')"; $res=mysql_query($sql1)or die(mysql_error()); } } ?> <form method="POST" action=""> please choose three ansaws. <br><br> <input type="checkbox" name="data[]" value="a">A <input type="checkbox" name="data[]" value="b">B <input type="checkbox" name="data[]" value="c">C <input type="checkbox" name="data[]" value="d">D <br><br> <input type="submit" name="submit" value="send"> </form> database info $sql="CREATE TABLE mydata (questions ENUM('a', 'b', 'c', 'd') NOT NULL)"; $res1=mysql_query($sql)or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/145722-solved-working-in-php-with-enum-help-please/#findComment-765111 Share on other sites More sharing options...
redarrow Posted February 18, 2009 Author Share Posted February 18, 2009 solved works lovely. SOLVED create dataabse test_enum; create table enum(quistion enum('a','b','c','d')); <?php $db=mysql_connect("localhost","root","passord") or die("Databse connection problam".mysql_error()); $c=mysql_select_db("test_enum",$db)or die("enum error".mysql_error()); if(isset($_POST['submit'])){ foreach($_POST['data'] as $go ){ $sql1="INSERT INTO enum(quistion)VALUES('$go')"; $res=mysql_query($sql1)or die(mysql_error()); } } ?> <form method="POST" action=""> please choose three ansaws. <br><br> <input type="checkbox" name="data[]" value="a">A <input type="checkbox" name="data[]" value="b">B <input type="checkbox" name="data[]" value="c">C <input type="checkbox" name="data[]" value="d">D <br><br> <input type="submit" name="submit" value="send"> </form> Link to comment https://forums.phpfreaks.com/topic/145722-solved-working-in-php-with-enum-help-please/#findComment-765121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.