Jump to content

[SOLVED] working in php with enum help please.


redarrow

Recommended Posts

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

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());

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());

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.