Create Table ( With PHP/MySQL)

Most of the Virtual-host would not allow using external php-code to create or delete databases or tables. However, there are 3rd party software like MySQL Connect or MyphpAdmin (most providers like Godaddy.com would offer) to admin and manipulate your databases

This is a series of documents while figuring out the different aspect of php/mysql functions. we we experienced some unique constraints  with "auto-increment" function of mysql data base, where the delete does not remove the number from the series.
$create_table=("DROP TABLE admininfo IF EXISTS") OR die(mysql_error());$member_t="CREATE Table memberinfo (
m_id int(11) not null auto_increment,
m_fname varchar(50) not null,
m_lname varchar(50) not null,
m_address varchar(100),
m_city varchar(20),
m_state varchar(2),
m_zip varchar(8),
m_email varchar(20),
m_phone varchar(12),
m_pass varchar(15),
m_position varchar(20),
PRIMARY KEY (m_id)
)";
$results= mysql_query($member_t) or die(mysql_error());
$create_table=("DROP TABLE admininfo IF EXISTS") OR die(mysql_error());
$admin_t="CREATE Table admininfo (
m_id int(11) not null,
m_fname varchar(50) not null,
m_lname varchar(50) not null,
m_address varchar(100),
m_city varchar(20),
m_state varchar(2),
m_zip varchar(8),
m_email varchar(20),
m_phone varchar(12),
m_pass varchar(15),
m_position varchar(20),
PRIMARY KEY (m_id)
)";
$results= mysql_query($admin_t) or die(mysql_error());
 
data inserted

data updated as show below: since it was manual insertion than suing "autoincrement " funcion you may enter any number you like enter. The use of this kind of data insertion make sense when you have given an option to the player to choose their jersey/uniform number

Now let us delete a record

data deleted

 
Now test adding another row
Note that you get whatever you entered as "id",

Let us update the recond
Note the orignial entry

Now compare with the unedited and edited row:

Unedited

Edited

Code editor

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Master all In One Editor</title>
</head>

<body>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="683" id="table1">
<tr>
<td width="681" colspan="2"></td>
</tr>
<tr>
<td width="321"><?php include "multiple_inserts.htm"; ?></td>
<td width="356"><?php include "multiple_update.htm"; ?></td>
</tr>
<tr>
<td width="321">&nbsp;</td>
<td width="356">&nbsp;</td>
</tr>
<tr>
<td width="681" colspan="2">

<form action="Master_DB_Editor.php" style="background-color: #99CCFF; ">
<p align="center">Search Items By ID</p>
<p align="center">
<input type="text" name="search" id="search" /><br />
<input type="submit" value="Search >>">
</p>
</form>

<?php
if(!isset($_GET['sort'])){
$sort="m_id";
}else{
$sort=$_GET['sort'];
}
if(!isset($_GET['search'])){
$search=0;
}else{
$search = $_GET['search'];
}
function searchFunc($search){
if($search){
$where="WHERE m_id Like '%$search%' ";
return $where;
}
}
$table="admininfo";
$link = mysql_connect("manas8x", "root","Manas8")or die(mysql_error());
echo 'Connected successfully';
mysql_select_db('admin') or die('Could not select database');

// Performing SQL query
$query = "SELECT * FROM $table " . searchFunc($search) . "ORDER BY $sort";
//$query = 'SELECT * FROM admininfo';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
//echo"<div style='position: absolute; width: 837px; height: 370px; z-index: 1; left: 3px; top: 150px' id='layer1'>";
echo "<table border='1' width='1000' >\n";
echo "<tr><td>ID</td><td>First Name</td><td>Last Name</td><td>Address</td><td>City</td><td>State</td>
<td>ZIP</td>
<td>Email</td>
<td>Phone</td>
<td>PWD</td><td>Position</td></tr>";

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
if($col_value==" " or $col_value==''){ echo "<td>NA</td>";} else {
echo "<td>$col_value</td>\n";}
}
echo "\t</tr>\n";
}
echo "</table></body>\n";

// Free resultset
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows<br/>";

mysql_free_result($result);

// Closing connection
mysql_close($link);
print ("<h3 style='text-align: center'><a href='Master_DB_Editor.php'>Reload </a> |_|/<a href='delete_row.php'>Need To delete data?</a></h3>");
?>
</td>
</tr>
</table>
</body>
</html>