Jump to content

Recommended Posts

Hi: i have 2 files, the first one is ok, and in the second I receive an error telling me that "undefined index...", I´m sure that is a stupid thing, but I don´t see it... can you help me??

 

I write comments on the code to see the errors that I receive... and to find them better instead read all the code...

Of course are only in this post, not in the code...

 

File1:

<?php

session_start();


// database conection...

$conn=mysql_connect ('zzzzz','xxx','yyy' );
mysql_select_db('jjjjjj');

if (!$conn)
{
die ("no conn".mysql_error() );
}

//echo "ok";

?>


<title>trying</title>
</head>

<body>

<?php

// conect... ( false values to post this comment...)

$cadena="SELECT * FROM mytabla WHERE CAT='APOL' ";
$result=mysql_query($cadena) or die(mysql_error());

$totalreg=mysql_num_rows($result);

$i=0;

?>

<div align="center">

<img src="im/titapol.jpg" alt="" /><br>
<br>

----------------> HERE IS THE FORM...MAYBE I NEED THE ACTION="" ????????

<form method="post">

<table summary="galfot">
<tbody>
<tr class="par">

<?php

$camino="im/pic/apol/thumbs/";

while ($fila=mysql_fetch_array($result))
{
$iden=$fila['ID'];
$nompic=$fila['NOMFOTO'];
$desc=$fila['DESCRIPCION'];
$titulo=$fila['TITULO'];

$thumb="th";

$foto="$camino$thumb$iden.jpg";


list($ancho,$alto)=getimagesize($foto);

$nuevo_ancho=110;
$nuevo_alto=round($nuevo_ancho*$alto/$ancho);


	 if ( $i % 6 == 0 ) 
	 {
	 if ( $i == 1 )
	 {
	 echo "<tr class=par>";
	 }
	 else
	 {
	 echo "</tr><tr class=par>";
	 }
	 }
echo "<td>";
echo "<a href=gala_f1_v1.php>";
?>

// ---------------->>>> HERE IS THE ERROR...WHY?????
<input type="hidden" name="valf" value='".$iden."'> 

<?php

echo" <img src=$foto width=$nuevo_ancho height=$nuevo_alto alt=$titulo border=0></a>";
echo "</td>";

$i++;

}

?>

</tr>
</tbody>
</table>

</form>

<br>

<?php
mysql_close();
?>

</body>
</html>

 

And the second file where I receive the error "undefined index...."...

 

<?php

session_start();

// conect... ( false values to post this comment...)

$conn=mysql_connect ('zzzzz','xxx','yyy' );
mysql_select_db('jjjjjj');


if (!$conn)
{
die ("no conecto".mysql_error() );
}

//echo "ok";


?>


<title>result</title>
</head>

<body>

<div align="center">

<p class="texto_normal_blanco">


<?php


// MAYBE THIS IS THE ERROR??? -----> Why????
$mivar=$_POST['valf'];   

// HERE I WANT TO USE THE VALUE FROM THE FORM USED IN FIRST PAGE AND RECEIVE UP HERE-------------
$cadena="SELECT * FROM fotss WHERE ID=$mivar";

$result=mysql_query($cadena) or die(mysql_error());

while ($fila=mysql_fetch_array($result))
{
$desc=$fila['DESCRIPCION'];
$titulo=$fila['TITULO'];
}

///---------- 

$nomfotoact="image$mivar.jpg";
$dir="im/pic/apol/";

$foto="$dir$nomfotoact";

list($ancho,$alto)=getimagesize($foto);

$nuevo_ancho=1000;
$nuevo_alto=round($nuevo_ancho*$alto/$ancho);

echo "$titulo<br><br>";
echo "<img src=$foto width=$nuevo_ancho height=$nuevo_alto><br><br>";
echo "$desc<br>";

?>

</p>

</div>


<?php
mysql_close();

session_destroy();

?>

</div>


</body>
</html>


 

Help, please!

Thanks.

Regards

 

 

Link to comment
https://forums.phpfreaks.com/topic/249509-why-doesn%C2%B4t-work-2-file/
Share on other sites

The error means that $_POST['valf'] is undefined - the 'valf' index that is. It doesn't exist and you're trying to use it. Although if that's the case it should mean that the query following it is failing?

 

The solution is to check it exists, and in this situation it would make sense to also ensure it has a value, so use empty to check this before using it:

 

if (!empty($_POST['valf'])) {
    $mivar = $_POST['valf'];
} else {
    // Handle error here or define a default value..
    $mivar = 'default value here';
}

 

empty() also performs an internal isset check, to first ensure the variable or array index exists.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.