Google search

Basic and advanced computer skills like Excel with macros, How to speed up your PC, C, CPP, Java programming, HTML, JavaScript, PHP, Wordpress, all web tools, Android tutorials, MySQL Tutorials, WAMP server installation. etc.
Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Inserting radio button value to mysql database through php script

In the below example shows that  "Inserting radio button value to mysql database through php script"  

Before we begin let us understand brief about radio buttons, radio buttons are used to select single value from a group or it is for single selection or true / false type of values. 

Step 1 : Create table as following screen shot in MySql database with all fields set to varchar type.





Step 2 : Create a configuration file for connection purpose as following and name it config2.php (as per my example)
<?php
      $host="localhost";
      $username="root";
      $password="";
      $dbname="demo";
      $con=mysql_connect("$host","$username","$password");
      mysql_select_db("$dbname",$con);
?>

Step 3:  Create main html/php page to display radio buttons and name it "radio2mysql.php" and follow the below code.


<html>
<head> 
</head> 
<body>
<center>
<table style="border: 1px solid yellowgreen;">
 <h2>Inserting Radio button value to MySQL database in 
php</h2>
 <form method="post" action="">
<tr> 
<td> Register No: </td> <td> <input type=text 
name=t1> </td> </tr>
<tr><td>  <input type="radio" name="status" 
value="Booked">Booked 
 <input type="radio" name="status" 
value="Pending">Pending </td> </tr>
<tr> <td> 
<input type="submit" name="submit" Value="submit"> 
</td> </tr> </table>
 </form>
 </body>
</html>
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php
include 'config2.php';
$t1=$_POST['t1'];
$st=$_POST['status'];
$query=mysql_query("select * from booked_status where 
regno='".$t1."' ") or die(mysql_error());
$duplicate=mysql_num_rows($query);
if (isset($_POST['submit']))
{
if($duplicate==0)
   {
$query = "INSERT INTO booked_status (regno, status) 
VALUES ('$t1','$st')";
mysql_query($query) or die(mysql_error());
echo "<center><h2 style='background-color:green; 
color:white; display:inline'><span>Successfully 
updated.</span>";
 }
 else
    {
      echo "<center><h2 style='background-color:red; 
color:white; display:inline'><span>The Register No. '$t1' is 
already present in the booking table";
    }
}
?>

Step 4: Output of the above program is...








Step 5: After successful submit with register number and radio button value following output can be generated. 

Step 6 : After unsuccessful submit with register number and radio button value following output can be generated(duplicate values). 

Thank you for referring above example! 

Display and Update records using PHP

In this tutorials you'll able to List / Display records and Update records using PHP program with MySQL as a back-end database. 

First of all we will display list of all records entered into MySQL database using PHP page. Here is the code for that.

1. File name : list_records.php
<?php
$host="localhost"; 
$username="root";
$password=""; 
$db_name="mars_db"; 
$tbl_name="list"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>

<h1> Update records </h1> <hr color="yellow">
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List of Employee Records </strong> </td>
</tr>

<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>First name</strong></td>
<td align="center"><strong>Last Name</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['fname']; ?></td>
<td><?php echo $rows['lname']; ?></td>


<td align="center"><a href="update.php?id=<?php echo $rows['id']; ?>">update</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>
<img src=icons/k.png>
<img src=icons/b.png>
<img src=icons/y.png>

2. Out put from above code looks as following.

















3. Now, copy the below code and save as "update.php".
<?php
$host="localhost"; 
$username="root";
$password=""; 
$db_name="mars_db"; 
$tbl_name="list"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$id=$_GET['id'];

$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Last Name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center">
<input name="id" type="text" id="id" value="<?php echo $rows['id']; ?>">
</td>
<td align="center">
<input name="fname" type="text" id="fname" value="<?php echo $rows['fname']; ?>" size="15">
</td>
<td>
<input name="lname" type="text" id="lname" value="<?php echo $rows['lname']; ?>" size="15">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="id" type="hidden" id="id" value="<?php echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
mysql_close();
?>


4. The out put of the above file looks as below.











5. When you want to update, just click on Submit button and it will take you to next page called "update_ac.php", refer the below code.
<?php
$id=$_POST["id"];
$fname=$_POST["fname"];
$lname=$_POST["lname"];

$host="localhost"; 
$username="root";
$password=""; 
$db_name="mars_db"; 
$tbl_name="list"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="UPDATE $tbl_name SET fname='$fname', lname='$lname' WHERE id='$id'";
$result=mysql_query($sql);

if($result)
{
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}

else 
{
echo "ERROR";
}
?>

6. The above code is having following output.







7. once you click on "View result" link as per above image, it will redirect to the "list_records.php", hence you'll have updated records. 

Thank you for reading and referring my blog. Keep reading mitindia blog for latest updates and don't forget to subscribe!. 

Wordpress on Local server

How to run / create a blog/website using Wordpress.

Brief About Wordpress:  It is a CMS(Content Management System), The most powerful open source plat-form for creating blogs and professional websites with over 24% of entire web share out of nearly 1 billion websites world wide. Over 26,000 plug-ins to use and enhance your Wordpress site features and stunning themes to look and feel.

In this tutorials you'll able to install, create and design website/blog using wordpress on local pc/laptop.

Step1:
Install WAMP (server) on your windows PC/Laptop.
Here is an tutorial to install wamp 

Step2:
After installing, open browser and type : http://localhost

Step3: You'll see following screen shot with WAMP Home page.

Step4: Click on "phpmyadmin" as per above image and create a database on mysql as following screen image.

After successfully creating the database "mywpsite", now go for next step.

Step5: Now download the wordpress software from here or
you can also refer below image for that.






Step 6: Unzip the folder and place that folder in C:\wamp\www location. [it looks like c:\wamp\www\mywpsite]

Step 7: Now open above site in the browser by typing : http://localhost/mywpsite (refer following image)












Step 8: Click on "Continue" then Click on Letsgo" button 
















Step 9: Put here database name (which was just created), user name (commonly "root"), password (commonly blank) and local host, leave this as it is.[follow below screen image]
















Step 10: Click on "Submit" button then you'll see following screen image.











Step 11: Click on "Run the Install" then you'll be redirected  to following page.












Step 12: provide all user details with email id as per above image. And Click on "Install Wordpress" button.

Finally you'll see following success page.















Now login with user name and password to create your local wordpress sites.

Thank you for reading my blog.