DEV Community

Lalit Kumar
Lalit Kumar

Posted on

How to store radio button value in database PHP?

Solution:

Step 1: Create Database

Code

<?php  
$con = mysql_connect("localhost","root","");  
if (!$con)  
  {  
  die('Could not connect: ' . mysql_error());  
  }   
if (mysql_query("CREATE DATABASE ABC",$con))  
  {  
  echo "Your Database created !!";  
  }  
else  
  {  
  echo "Error creating database: " . mysql_error();  
  }  
mysql_close($con);  
?>  
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Table

Code

<?php  
$con = mysql_connect ("localhost","root","");  
if (!$con)  
  {  
  die ('Could not connect: ' . mysql_error());  
  }  
mysql_select_db ("ABC", $con);  
$sql = "CREATE TABLE employee  
(  
name VARCHAR( 50 ) ,  
sex VARCHAR( 50 ) ,  
)";  
mysql_query($sql,$con);  
echo "Your Table Created !!";  
mysql_close($con);  
?>  
Enter fullscreen mode Exit fullscreen mode

Read more

Top comments (4)

Collapse
 
_garybell profile image
Gary Bell

Please do not use mysql_* functions. Doing so is insecure due to the nature of the library. It also means using an unsupported version of PHP.

The mysql_* library was removed in PHP 7. At worst this should be replaced with mysqli_* functions.

Really, it should use a parametised queries to reduce the risks of SQL injection.

Collapse
 
sloan profile image
Sloan the DEV Moderator

Hi there, we encourage authors to share their entire posts here on DEV, rather than mostly pointing to an external link. Doing so helps ensure that readers don’t have to jump around to too many different pages, and it helps focus the conversation right here in the comments section.

If you choose to do so, you also have the option to add a canonical URL directly to your post.

Collapse
 
whataluckyguy profile image
Lalit Kumar

sure i will take care of that

Collapse
 
erhankilic profile image
Erhan Kılıç

Please don't write just for the sake of writing, don't publish poor quality articles.