Mysql !!

Status
Not open for further replies.

allan16

In Runtime
Messages
378
Hi:

I have created a database in MYSQL. it has 3 tables .

how could I do to interact with it graphicaly ?

Thx
 
Ok...that was cool. !

How could I develop an application where the user will enter the information that will be stored on the database.
 
first you need to know how to run select, insert, and/or update queries for mysql.

then you need to know how to code the app to run the queries.

i know with asp, you would need to create an ADO connection to the db and run your queries based on user input. i got some sample scripts at work that i cant get to now.
 
actually i found some php code that i have laying around

im posting text data from a html form.

PHP:
<?php 

//table field lengths

//server info
$location = "serverip:3306"; 
$username = "mysqluser"; 
$password = "mysqlpass"; 
$database = "mysqldbname"; 

//Connect to the DB
$conn = mysql_connect("$location","$username","$password"); 
if (!$conn) die ("Could not connect MySQL"); 
mysql_select_db($database,$conn) or die ("Could not open database"); 
echo "db connected
";//Report DB connected

$stack = array();//create list for receiveing data
$agtname = $_POST["agtname"];//save for multiuse

function insert($x, $stack, $table) { 
$query = "insert into ".$table." set ";//move data into table
for ($i=0;$i<$x;$i+=2) {
  if (substr(pos($stack), 0, 4) == "com_") // is field name prefixed with com_?
    $query = $query.substr_replace(pos($stack),"",0,4)."='";//Shave com_ & Add field name to the query
  else 
    $query = $query.pos($stack)."='";//Get field name & add it to the query
  next($stack);//Move to data entry
  if(is_array(pos($stack))) { //Is data entry from checkboxes?
    foreach(pos($stack) as $element) // Each checkbox entry
      $query = $query.$element.","; //gets added to the query
    $query= $query."',";//finish query
  }  
  else 
    $query= $query.pos($stack)."',";//Get data entry & add it to the query
  next($stack);//Get next field name
  //echo $i."
";
}
$query = substr($query,0,(strlen($query)-1));//shave last comma
return $query;//Send query back to program
}

function exequery($query) {//Use function to execute queries
  //echo $query."

";//Show execute string
  $sqlresult = mysql_query($query);//Execute
  //Check For Errors
  if (!$sqlresult) 
    echo "Error running query 
".$query."

".mysql_errno().": ".mysql_error()."

";
  else
    echo "query executed
".$query."

";
}


function multi_add($slice, $names, $how_many, $table, $agtname) {
next($slice);//Skip field name
for ($i=0;$i<$how_many;$i++) {
  if (pos($slice) != "") {
    $query = "insert into ".$table." set ";//Put data in this table
    $query = $query."agtname='".$agtname."',";//Define agency
    foreach($names as $field) {
      $query = $query.$field."='".pos($slice)."',";//Get data entry
      next($slice);next($slice);//Move To Next Field Name; Skip field name
    }
  $query = substr($query,0,(strlen($query)-1));//shave last comma
  if ($table == "persinfo") // For the persinfo query
    $query = $query.",indexed='".md5($query)."'"; // Add unique value to query
  exequery($query);//Execute
  } else {
    foreach($names as $field) {
      next($slice);next($slice);//Move To Next Field Name; Skip field name
    }
  }
  //echo pos($slice)."

";
} }

$count = 0;
foreach ($_POST as $key => $value) { //take name&data pair 
  array_push($stack, $key, $value);//and put it on into two save piles
  echo $count.": ".$key." - ".$value."
";// Show data entry
  $count++;
}

echo "
";
reset($stack);//point to first in both save piles

//INFO
$slice = array_slice($stack, 0);
$query = insert(28, $slice, "info");
exequery($query);//Execute

//AGENCY PRINCIPALS
$slice = array_slice($stack, 28);
$fields = array("name", "title", "dob", "yearsagy");
multi_add($slice, $fields, 3, "principals", $agtname);

//MARKETING
$slice = array_slice($stack, 52);
$query = insert(50, $slice, "marketing");
$query = $query.",agtname='".$agtname."'";
exequery($query);//Execute

//PERSONEL INFO
$slice = array_slice($stack, 102);
$fields = array("keyperson", "title", "hiredate", "yearsinforce", "prof_desg", "lic_num");
multi_add($slice, $fields, 10, "persinfo", $agtname);

//OFFICE
$slice = array_slice($stack, 222);
$query = insert(22, $slice, "office");
$query = $query.",agtname='".$agtname."'";
exequery($query);//Execute

//PERSONAL LINES INFO
$slice = array_slice($stack, 244);
$query = insert(46, $slice, "plinfo");
$slice = array_slice($stack, 291);
$terr = "";
for($i=0;$i<3;$i++) {
  $terr = $terr.pos($slice).",";
  next($slice);next($slice);
}
$terr = substr($terr,0,(strlen($terr)-1));//shave last comma
$query = $query.",agtname='".$agtname."'";
$slice = array_slice($stack, 397);//Get discontiued
$query = $query.",discontinued='".pos($slice)."',primary_terr='".$terr."',pc='p',indexed='".md5($query)."'";
exequery($query);//Execute

//PERSONAL LINES CO'S
$slice = array_slice($stack, 296);
$fields = array("company", "years", "volume", "3year", "pc");
multi_add($slice, $fields, 10, "company", $agtname);

//COMMERICAL LINES INFO
$slice = array_slice($stack, 398);
$query = insert(46, $slice, "plinfo");
$slice = array_slice($stack, 445);
$terr = "";
for($i=0;$i<3;$i++) {
  $terr = $terr.pos($slice).",";
  next($slice);next($slice);
}
$terr = substr($terr,0,(strlen($terr)-1));//shave last comma
$query = $query.",agtname='".$agtname."'";
$slice = array_slice($stack, 551);//Get discontiued
//echo md5($query);
$query = $query.",discontinued='".pos($slice)."',primary_terr='".$terr."',pc='c',indexed='".md5($query)."'";
exequery($query);//Execute

//COMMERICAL LINES CO'S
$slice = array_slice($stack, 450);
$fields = array("company", "years", "volume", "3year", "pc");
multi_add($slice, $fields, 10, "company", $agtname);


//AUTOMATION
$slice = array_slice($stack, 552);
$query = insert(30, $slice, "automation");
$query = $query.",agtname='".$agtname."'";
exequery($query);//Execute


/*//Get names of columns in table
$field_names = array();
$res = mysql_query("SHOW COLUMNS FROM info");
for($i=0;$i<mysql_num_rows($res);$i++){
   array_push($field_names,mysql_result($res, $i));
} 
foreach($field_names as $value) {
  echo array_pop($field_names)."
";
}*/

//mysql_query($query); 
?>
 
Status
Not open for further replies.
Back
Top Bottom