Forum Moderators: coopster
I have a situation that need to do
$sql2="select * from agents where id='$id' limit 1 ";
$result2=mysql_db_query("DB",$sql2);
$regist2=mysql_fetch_array($result2);
$name=$regist2["name"];
and so on....
TO CHANGE EXISTENT USER DATA:
<table>
<tr>
<td>
<? if($id){ ?>
ID: <? echo $id ?>
</td>
</tr>
<? } ?>
TO CREATE A NEW USER:
<tr>
<td>
<? } else if ($activ==0 ) { ?>
Register: New User
</td>
</tr>
<? } ?>
</table>
DATA COMMON TO BOTH SITUATIONS:
<table>
<tr>
<td width="121" align="right"><span class="style3">Nome (Broker/Agent)</span></td>
<td colspan="2" align="left"><input name="nome" type="text" class="input" id="nome" value="<? echo $nome ?>" size="62" /></td>
</tr>
and so on...
<tr>
<td align="center"> </td>
<td align="left"><input type="submit" name="<? if(!$id) { echo "Save"; } else { echo"Change"; } ?>" id="button" value="<? if(!$id) { echo "Save"; } else { echo"Change"; } ?>" >
</td>
</tr>
</table>
Now: The first situation is no problem. The changes are saving in the DB.
But the second is not saving.
can somebody explain-me why?
thanks
********************
<?php
$sql2="select * from agents where id='$id' limit 1 ";
$result2=mysql_db_query("DB",$sql2);
$regist2=mysql_fetch_array($result2);
$name=$regist2["name"];
and so on.... echo '<table><tr><td>';
if($id){
echo $id . '</td></tr>';
} else if($activ==0 ) {
echo 'Register: New User</td></tr>';
}
echo '</table>';
DATA COMMON TO BOTH SITUATIONS: ...
********************
Thanks for your reply.
But sorry could not understand what do you mean.
Here it is the two codes (files)
first code named test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<? session_start();
include ("calldb.inc.php");
$sql2="select * from inter_agents where id='$id' limit 1 ";
$result2=mysql_db_query("dbname",$sql2);
$regist2=mysql_fetch_array($result2);
$name=$regist2["name"];
$bi=$regist2["bi"];
$nif1=$regist2["nif1"];
$country=$regist2["country"];
$type=$regist2["type"];
$activ=$regist2["activ"];
?>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 20px;
background-color: #008000;
}
.Btns {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: bold;
color: #000000;
text-decoration: none;
}
.Btns:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: bold;
color: #666666;
text-decoration: none;
}
.bordinhas {
border: 1px solid #FFFFFF;
}
.asinhos {font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
color: #000000;
text-decoration: none;
}
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
color: #FFFFFF;
}
}
.style2 {
color: #000000;
font-size: 9px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-decoration: none;
}
.style3 {
color: #ffffff;
font-size: 12px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-decoration: none;
}
.style4 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF; }
.style5 {font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
color: #000000;
}
.style12 {
font-size: 12px;
font-family: "Courier New", Courier, monospace;
color: #000000;
}
-->
</style></head>
<body>
<form action="test1.php" method="post" enctype="multipart/form-data" name="form1">
<table width="80%" border="0" align="center">
<tr>
<td colspan="2" width="80%" align="left">
<table width="80%" border="0" align="center">
<tr>
<td width="114"> </td>
<td width="44" align="left"> </td>
<td colspan="2" width="633" align="left"><input type='hidden' name='tipo' value='<? echo $tipo ?>'>
<input type='hidden' name='id' value='<? echo $id ?> '>
</span></td>
</tr>
<? if($id){ ?>
<tr>
<td width="114" align="right"> <span class="style3">ID:</span></td>
<td width="44" align="left"> </td>
<td width="633" align="left"><span class="style3"><?php echo $id ?></span></td>
</tr>
<tr>
<td width="114" align="right"> <span class="style3">TYPE/span></td>
<td width="44" align="left"> </td>
<td width="633" align="left"><span class="style3"><?php echo $type ?></span></td>
</tr>
<? } else if ($activ==0 and $id==0) { ?>
<tr>
<td width="114" align="right"><span class="style3">Type</span></td>
<td width="44" align="left"> </td>
<td width="633"><span class="style3">New User</span></td>
</tr>
<tr>
<td colspan="2" width="121" align="right"><span class="style3">TYPE:</span></td>
<td colspan="2" align="left"><select name="tipo" size='1' class="input">
<option value="">Select</option>
<option value='Seller'<? if ($type=="Seller") echo "selected"; ?>>Seller</option>
<option value='Buyer'<? if ($type=="Buyer") echo "selected"; ?>>Buyer</option>
</select>
</td>
</tr>
<? } ?>
</table>
<table width="80%" border="0" align="center">
<tr>
<td width="121" align="right"><span class="style3">COUNTRY</span></td>
<td colspan="2" align="left"><select name='country' size='1' class="input" id="country">
<option selected>Select Country</option>
<option value='Acapulco' <? if($country=="Acapulco") echo "selected"; ?> >Acapulco</option>
<option value='Afghanistan' <? if($country=="Afghanistan") echo "selected"; ?> >Afghanistan</option>
and so on....
</select></td>
</tr>
<tr>
<td width="121" align="right"><span class="style3">Name</span></td>
<td colspan="2" align="left"><input name="name" type="text" class="input" id="name" value="<? echo $name ?>" size="62" /></td></tr>
<tr>
<td width="121" align="right"><span class="style3">ID Nš</span></td>
<td colspan="2" align="left"><input name="bi" type="text" class="input" id="bi" value="<? echo $bi ?>" size="62" /></td></tr>
<tr>
<td width="121" align="right"><span class="style3">NIF Nš </span></td>
<td colspan="2" align="left"><input name="nif1" type="text" class="input" id="nif1" value="<? echo $nif1 ?>" size="62" /></td>
</tr>
<tr>
<td align="center"> </td>
<td width="79" align="center"> </td>
<td width="772" align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td colspan="2" align="left"><input type="submit" name="<? if(!$id) { echo "Save"; } else { echo"Change"; } ?>" id="button" value="<? if(!$id) { echo "Save"; } else { echo"Change"; } ?>" ></td>
</tr>
</table>
</form>
</BODY>
</html>
2nd code called test1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<? session_start();
if ($estado_sessao!=1){
header("location: ../login.htm");
die();
}
include ("calldb.inc.php");
if($change=="change"){
$sql="update inter_agents set tipo='$type', country='$country', agent='$agent', name='$name', bi='$bi', nif1='$nif1' WHERE id='$id' limit 1";
$query=mysql_db_query("namedb",$sql);
header("location: main1.php");
die();
}
if ($Salvar=="Save") {
$sql2="INSERT INTO inter_agents
(
agent,
activ,
type,
country,
name,
bi,
nif1
)
values
(
'$agent',
'1',
'$type',
'$country',
'$name',
'$bi',
'$nif1'
)";
$results=mysql_db_query("namedb",$sql2) or die("Base error :".mysql_error());
header("location: main1.php");
die();
}
?>
</body>
</html>