Please help. Is this php script wrong?
From: John Wrate (lolo8000_at_hotmail.com)
Date: 03/09/04
- Next message: Gary Smith: "PHP 4.3.4 and Apache 2.0.48"
- Previous message: Shawn Wilson: "Re: Office document upload to website (and inserting in MySQL if possible)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Mar 2004 14:52:45 -0800
Hi all,
I have a customer who wants his site to reside in one of my hosts. The
host I have assigned for him is a Windows NT server with the latest
binary PHP and MySQL servers.
The people that made the site are a**holes and want to host the site
themselves and are resorting to all sorts of lies about our server not
working porperly.
They sent this script. I don't know any PHP but I feel something is
not right with the script. And I get an error:
Notice: Undefined variable: ok in C:\.....\test.php on line 3
This is the test.php script:
$bdConexion=mysql_pconnect("localhost","xxxx","11122"); // usr & pswd
mysql_select_db("datos_prueba",$bdConexion);
if(!$ok){
$sql="CREATE TABLE Empleados (ID INT PRIMARY KEY,Nombre VARCHAR (50)
, Apellidos VARCHAR (70), Edad INT(4))";
if(!($reg=mysql_query($sql,$bdConexion)))
echo "ERROR CREATING TABLE.";
else
{
?>
<form name="forma1" ENCTYPE="multipart/form-data" method="post"
action="">
Nombre:<input type="text" name="name"><br>
Apellido:<input type="text" name="last"><br>
Edad:<input type="text" name="year"><br>
Selecciona una Imagen:<input name="imagen" type="file">
<br>
<br><input type="submit" name="ok" value="Enviar"><br>
</form>
<?}
}else if($ok){
$sql2="INSERT INTO Empleados(ID,Nombre,Apellidos,Edad) VALUES
(".'1'.",'".$name."','".$last."',".$year.")";
if(!($reg2=mysql_query($sql2,$bdConexion)))
echo "ERROR AL INSERTAR EN LA TABLA.".$sql2;
$sql3="UPDATE Empleados SET Nombre='Perlita' WHERE ID=1";
if(!($reg3=mysql_query($sql3,$bdConexion)))
echo "ERROR AL ACTUALIZAR LA TABLA";
$sql4="SELECT * FROM Empleados";
if(!($reg4=mysql_query($sql4,$bdConexion)))
echo "ERROR AL SELECCIONAR DE LA TABLA";
ELSE{
echo "<BR>TUS DATOS FUERON:<BR><BR>";
IF($regis=mysql_fetch_array($reg4))
{
echo "Nombre:".$regis[Nombre]."<br>";
echo "Apellido:".$regis[Apellidos]."<br>";
echo "Edad:".$regis[Edad]."<br>";
}
}
echo "Imagen=".$imagen_name;
echo "<br>";
$pathSeccion="../media/";
$pathfin=$pathSeccion."1";
echo "<BR>== GRABANDO UNA IMAGEN ==<BR>";
if(!file_exists($pathfin))
{
mkdir($pathfin,0777);
if($imagen!=""){
copy($imagen,$pathfin."/".$imagen_name);
}
}
ECHO "<BR>LEYENDO LA IMAGEN<BR><br>";
if(file_exists($pathfin))
{
$dir = opendir($pathfin);
while($arch = readdir($dir)){
if($arch != '.' && $arch != '..')
echo "Imagen: <img src=\"".$pathfin."/".$arch."\"><br>";
}
closedir($dir);
}
echo "<BR><h1>==TEST OK ==</h1><BR>";
}//ok
In the first "If" it is very strange to me to see that if the
mysql_select_db falied if(!$ok), then a table is being created! How is
that possible, and should't ok be assigned the value of the
my_select_db(xxxx,xxx) in order to test it later. Like I said, I get
the error and although the table is created the first time the
test.php script is opened/run, the data is not inserted in the second
run (after filling the form).
Any comments will be very much appreciated.
Wrate
- Next message: Gary Smith: "PHP 4.3.4 and Apache 2.0.48"
- Previous message: Shawn Wilson: "Re: Office document upload to website (and inserting in MySQL if possible)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|