Inserting databasecontent within the same form

Inserting databasecontent within the same form

am 26.09.2007 17:32:14 von Ruprecht Helms

Hi,

How can I overtake the fieldvalues of city and the first part of the
phonenumber. It should read out the value of the zipfield and check them
with the content of the table "ort". If there is found a recordset with
the same plz the formfields city and the the field "vorwahl" should get
the values of the fields of the recordset.


This is my code:




















style="color : #ed662c;">Lange technische Hotline





































Kunde bearbeiten
Call bearbeiten
Call
schließen/abrechnen













Kunde hinzufügen

 



width="33%"> 
  
































































Kundennr. $sql="SELECT * FROM Kunden";
$result=mysql_db_query($datenbank,$sql);
$zahl=mysql_num_rows($result);
echo $zahl;
?>
Name
Vorname
Strasse
PLZ
$sql_ort="SELECT * FROM Orte WHERE PLZ='$plz'";
$result_ort=mysql_db_query($datenbank,$sql_ort);
while ($row_ort = mysql_fetch_object($result_ort))
{
$ort = $row_ort->Bezeichnung;
$vorwahl = $row_ort->Vorwahl;
}
?>


type="submit" name="plz_uebernehmen" value="übernehmen">
Ort
Land



Ansprechpartner
Telefon ()   type="text" name="telefon" value="">
Mobil
Fax (nur Rufnummer)
email






 









erstellt v.

Ruprecht Helms IT-Service & Softwareentwicklung

Lörrach



Regards,
Ruprecht Helms

Web: http://www.rheyn.de

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Inserting databasecontent within the same form

am 27.09.2007 03:32:06 von Niel Archer

> How can I overtake the fieldvalues of city and the first part of the
> phonenumber. It should read out the value of the zipfield and check them
> with the content of the table "ort". If there is found a recordset with
> the same plz the formfields city and the the field "vorwahl" should get
> the values of the fields of the recordset.

I'm having troubling understanding exactly what you want and I don't
have time to decipher all the code in the hope it will tell me. My best
guess is you want to use the zipcode from one table, to automatically
add the city name into a form from another table. If that is so, you
can do it with your query using a join.

SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
USING (zipcode)

This assumes that `zipcode` exists in both tables and is unique in the
"City" table. You should also process the City.name and City.vorwahl
results for NULL results where `zipcode` does not exist in the "City"
table.

--
Niel Archer

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Inserting databasecontent within the same form

am 27.09.2007 10:22:51 von Ruprecht Helms

Hi Niel,

> SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
> USING (zipcode)

I'm understanding you this is a way for designing the sql-statement.
My customer want that they have inserted the city after typing in the
zipcode in the zipfield. The city should be searched in a database and
inserted in the field city automaticly.

I think the only way is to do that with some ajax-code combined with a
short phpscript.

Actually I have these codes, but the automatic inserting fails, I don't
know why.

---------------------

ajax.js

function Ajax() {
//Eigenschaften deklarieren und initialisieren
this.url="";
this.params="";
this.method="GET";
this.onSuccess=null;
this.onError=function (msg) {
alert(msg)
}
}

Ajax.prototype.doRequest=function() {
//Üeberpruefen der Angaben
if (!this.url) {
this.onError("Es wurde kein URL angegeben. Der Request wird
abgebrochen.");
return false;
}

if (!this.method) {
this.method="GET";
} else {
this.method=this.method.toUpperCase();
}

//Zugriff auf Klasse für readyStateHandler ermöglichen
var _this = this;

//XMLHttpRequest-Objekt erstellen
var xmlHttpRequest=getXMLHttpRequest();
if (!xmlHttpRequest) {
this.onError("Es konnte kein XMLHttpRequest-Objekt erstellt werden.");
return false;
}

//Fallunterscheidung nach Übertragungsmethode
switch (this.method) {
case "GET": xmlHttpRequest.open(this.method,
this.url+"?"+this.params, true);
xmlHttpRequest.onreadystatechange = readyStateHandler;
xmlHttpRequest.send(null);
break;
case "POST": xmlHttpRequest.open(this.method, this.url, true);
xmlHttpRequest.onreadystatechange = readyStateHandler;
xmlHttpRequest.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
xmlHttpRequest.send(this.params);
break;
}

//Private Methode zur Verarbeitung der erhaltenen Daten
function readyStateHandler() {
if (xmlHttpRequest.readyState < 4) {
return false;
}
if (xmlHttpRequest.status == 200 || xmlHttpRequest.status==304) {
if (_this.onSuccess) {
_this.onSuccess(xmlHttpRequest.responseText,
xmlHttpRequest.responseXML);
}
} else {
if (_this.onError) {
_this.onError("["+xmlHttpRequest.status+"
"+xmlHttpRequest.statusText+"] Es trat ein Fehler bei der
Datenbertragung auf.");
}
}
}
}

//Gibt browserunabhängig ein XMLHttpRequest-Objekt zurück
function getXMLHttpRequest()
{
if (window.XMLHttpRequest) {
//XMLHttpRequest für Firefox, Opera, Safari, ...
return new XMLHttpRequest();
} else
if (window.ActiveXObject) {
try {
//XMLHTTP (neu) für Internet Explorer
return new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
//XMLHTTP (alt) für Internet Explorer
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return null;
}
}
}
return false;
}
-----------------------------------------

einfuegen.js

//Instanz der Klasse Ajax erzeugen und mit der Datenübertragung starten
function load()
{

var plz=document.getElementById("plz").value;

with (new Ajax()){

url="ort_suchen.php";
method="POST";
params="plz="+plz;
onSuccess=successHandler;
onError=errorHandler;
doRequest();
}


//Den Text in die Seite einfügen
function successHandler(txt,xml){
document.getElementById("ort").innerHTML=txt;

}

//Fehler
function errorHandler(msg){
document.getElementById("text").innerHTML=msg;
}

}

-----------------------------------------------
ort_suchen.php

include("authentication.php");
$plz = mysql_real_escape_string ( $_POST['plz'],$link);



$ort="";

$result=mysql_db_query($datenbank,"SELECT * from Orte WHERE PLZ = '$plz'");

while ($row=mysql_fetch_object($result)){


$ort= $row->Bezeichnung;


}

echo $ort;

?>

-----------------------------------------

in the source-phpscript that do the request I have this

html-header
databaseconnection

....


....

some formcode
....

PLZ



Ort

Ort

....


Regards,
Ruprecht Helms

Web: http://www.rheyn.de

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Inserting databasecontent within the same form

am 28.09.2007 01:48:00 von Niel Archer

Hi Ruprecht,

> > SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
> > USING (zipcode)
>
> I'm understanding you this is a way for designing the sql-statement.

Yes.

> My customer want that they have inserted the city after typing in the
> zipcode in the zipfield. The city should be searched in a database and
> inserted in the field city automaticly.

> I think the only way is to do that with some ajax-code combined with a
> short phpscript.
>
> Actually I have these codes, but the automatic inserting fails, I don't
> know why.



Dynamically changing the fields, I'm afraid I can't help. You would be
better trying a list dedicated to ajax.


--
Niel Archer

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php