Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fopen

Status
Not open for further replies.

cryrep

Programmer
Oct 18, 2005
56
CA
php 5.1.4 under windows xp

I try to have php ask for two questions and post data to mssql

it's work a part, i ask the two question where the 2nd one is done i strat to print print only the quetions until i use ctrl-c

is some one could tell me what i did wrong

-*-*-*-*-*- the bug -*-*-*-*
Entrez le departement :
Entrez le numero de commade :
Entrez le departement :
Entrez le numero de commade :
Entrez le departement :
Entrez le numero de commade :

---*-*-* the script -*-*-*-

<?php
$blnRunning = true;
$rsConnect = odbc_connect("GPS_TESTCOMPAGNIE", "ship", "ship");
do {

echo "Entrez le numero de commade :\n ";
$rsInput = fopen("php://stdin", "r");
$strNoCommand = trim(fread($rsInput, 12));
fclose ($rsInput);

echo "Entrez le departement :\n";
$rsInput1 = fopen("php://stdin", "r");
$strNoDepartment = trim(fread($rsInput1, 4));
fclose ($rsInput1);

$rsUpdate = odbc_exec ($rsConnect, "insert into hsl_suividecmd (sop_order, datein, dep, isactive)
values ( '{$rsInput}', getdate() , '1234' , '1')");
} while($blnRunning);

?>
 
you are not resetting $blnRunning so it looks like you will end up in a never ending loop.

i'm not sure that the "php://" protocol wrapper exists in windows. i've never come across it, anyway.
 
What i whant to do exacly is whant my script ask both question insert to database and restart the script

if i took off the do while option is't work the only thing i have to fix is re-start the script it self or simply loop
1rst, 2nd question and mssql insert


 
a quoi sert le php://stid?

tu pourrais le refaire avec un form html en utilisant soit le superglobal $_POST soit $_GET. Plus simple, je suppose; et plus claire.
 
i understand what you're trying to do now. sorry for being slow.

i think your query is wrong
Code:
values ( '{$rsInput}',  getdate() , '1234' , '1')");
it looks like you are trying to insert a resource handle ($rsInput) rather than the Order no $strNoCommand

et je remarque que tu ne fait rien avec $strNoDepartment?
 
C'est sur pour le HTML ca vas etre plus simple , je voulais le moin de piton possible. c'est pour ca que jai choisit de le faire de cette facon

le probleme c'est pas le insert, je sait qu'il fonctionne. des que je met le do while c'est la que ca se gate!

il se met a ecrire le texte suivant sans arret!
Entrez le departement :
Entrez le numero de commade :


Je voudrais que une fois que le update est fait, que le script recommance!

si tu as une autre idee!

Si non je crois que je vais aller avec le Web!

Merci de ton aide
 
alors, je l'ai refait. essaye le code dessous :

Code:
<?php
function read ($length='255')
{
   if (!isset ($GLOBALS['StdinPointer']))
   {
     $GLOBALS['StdinPointer'] = fopen ("php://stdin","r");
   }
   $line = fgets ($GLOBALS['StdinPointer'],$length);
   return trim ($line);
}
function demandez() {
   
    echo "Entrez le numero de commade :\n ";
    $numero = read();
    echo "Entrez le departement :\n";
    $department=read ();
    writedata($numero, $department);
}
function writedata($numero, $department) {
    //write data here
    $str = "Command: $numero ,Department: $department;\r\n";
    $fh = fopen("outputfile.txt", "a");
    fwrite ($fh, $str);
    fclose ($fh);
}

$blntest = true;
while ($blntest):
	demandez();
endwhile;
?>

tu verras que ce code ecrit a un fichier text - c'est facile a remplacer les lignes dans writedata avec un appel db.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top