hi the once again
hope you can help me again like you did last time, ok i have a form that insert's data to a MySQL database, so i get some of the data to this form from other table named clientes (it means clients) in the mysql structure. so what i wanna do is:
when the user select a client from a combobox that have clients list the form auto refresh and fills the adress("morada" in portuguese), location("localidade") and some others...
so i came up with this code to the entire form page but it dosen't make the refresh...
[PHP]
<?php
require_once('general/dbinfo.php');
require_once('general/common.php');
global $MyDb_debito;
if ((!(isset($_POST)))
and (!(isset($_POST)))) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php $title ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="scripts/wdw.js"></script>
<script language="javascript" type="text/javascript" src="scripts/insert.js"></script>
</head>
<body bgcolor="#CCCCCC" onmousemove="overhere()">
<div id="ToolTip"></div>
<script language="JavaScript" type="text/javascript">
<!--
function checkFormErrors(){
formErrors = new Array();
checkComboSelect(document.wdwInsertForm.tipo_de_factura,'selectione a delegação',true);
checkComboSelect(document.wdwInsertForm.cliente,'selectione a delegação',true);
var errorText = '';
if (formErrors.length > 0){
for (var i=0; i<formErrors.length; i++)
errorText = errorText + formErrors + '\n';
alert(errorText);
return false;
}
return true;
}
-->
</script>
<?
$nome=$_GET["nome"]?$_GET["nome"]:"";
if($nome) list($id_cliente,$nif,$morada,$localidade,$distrito)=query("select id_cliente,nif,morada,localidade,distrito from tab where nome='.$nome.'");
?>
<form name="wdwInsertForm" method="post" action="<?php echo $PHP_SELF ?>" onSubmit="return checkFormErrors()">
<table align="left" class="cssInsertFormBorder" id="wdwInsertFormBorder" cellpadding="0" cellspacing="0">
<tr><th height="20" class="cssHeader">Insert data: facturas</th></tr><tr><td align="center">
<table align="center" class="cssInsertTable" id="wdwInsertTable" cellpadding="3" cellspacing="0">
<tr>
<td>
<input name="id_cliente" id="id_cliente" type="text" class="cssInput" size="11" maxlength="11" value="<? =&id_cliente ?>"> </td>
<td>
<input name="nif" id="nif" type="text" class="cssInput" size="50" maxlength="50" value="<? =$nif ?>"></td>
<td>
<select name="cliente" id="cliente" class="csscombo">
<?php getComboItemsFromDb($MyDb_debito,'SELECT DISTINCT cliente ,cliente FROM '.$dbname_debito.'.clientes ORDER BY cliente ASC','cliente','cliente'); ?>
</select>
</td>
<td>
<input name="morada" id="morada" type="text" class="cssInput" size="50" maxlength="50" value="<? =$morada ?>"></td>
<td>
<input name="localidade" id="localidade" type="text" class="cssInput" size="50" maxlength="50" value="<? =$localidade ?>"></td>
<td>
<input name="distrito" id="distrito" type="text" class="cssInput" size="50" maxlength="50" value="<? =$distrito ?>">
</TR>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php } else if (isset($_POST)) {
$insertSql = "INSERT INTO ".$dbname_debito.".facturas (
id_cliente
,nif
,cliente
,morada
,localidade
,distrito
,valor
) VALUES ( "
."'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.",'".$_POST."'"
.")";
$MyDb_debito->f_ExecuteSql($insertSql);
echo '<SCRIPT language="javascript"> javascript:history.go(-2) </SCRIPT>';
}
else if (isset($_POST)) {
echo '<SCRIPT language="javascript"> javascript:history.go(-2) </SCRIPT>';
}
?>
[/PHP]
so what am i doing wrong? evrery thing work except for the refresh and data
hope you can help me
thanks in advanced
cheers...
Comments
If you mean that the form doesn't update when the combobox changes, that's a JavaScript issue.
PHP doesn't work like that, it only runs through a script when it's loading, not when it's already finished loading (the server sends the data to php.exe, which sends the server the output vfrom the script, which is plain HTML that's loaded into the browser).
You can make PHP work on demand by making use of AJAX techniques (AJAX being a way to combine JavaScript, XML and so on to create a feature rich and almost instant interface without refreshing when commands are executed or when actions run), but you'd need to know how to use the technology required (JavaScript, XML the XMLHTTPRequest thingy and so on).
If you're having problems getting your script to link back to itself when the user submits the form, try using:
[php]$_SERVER["PHP_SELF"][/php]
In the forms action attribute.
It's generally thought of as good practice to use the semicolon ( ; ) whenever you end a piece of PHP code as it helps prevent any errors that may occur from multi-line pieces of PHP code.
Current project: CMS Object.
Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
Release date: NEVER!!!
[php]
<?
$nome=$_GET["nome"]?$_GET["nome"]:"";
if($nome) list($id_cliente,$nif,$morada,$localidade,$distrit o)=query("select id_cliente,nif,morada,localidade,distrito from tab where nome='.$nome.'");
?>
[/php]
´to this one:
[php]
<?
$nome=$PHP_SELF["nome"]?$PHP_SELF["nome"]:"";
if($nome) list($id_cliente,$nif,$morada,$localidade,$distrit o)=query("select id_cliente,nif,morada,localidade,distrito from tab where nome='.$nome.'");
?>
[/php]
but by what you said i still have the same problem the page dont reloads when the user select a value from the combobox.
and what is that javascript code you've talk?
can you show me an example of that code?
because, you see, what a realy need is to take some data from a client, stored in the clients table and put it in the processe table, so with a combo to the user select the client name a solve a part of the problem.
But in the other hand i need other info from the client not just the name, so if when a user select a client name in the combo, the fields morada (adress) localidade (location) Fax telefone (phone) and telemóvel (mobile) be auto field with that clients data.
its a little hard to explain sinse my english is not very good.
i can show you my all code is posted in:
entire code
I don't actually know much JavaScript, so you'd need to look up that code yourself.
Current project: CMS Object.
Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
Release date: NEVER!!!