/    Sign up×
Community /Pin to ProfileBookmark

Notice : Undefined index: id line 4

Hello, I am in a problem and it is that it appears to me that I have indefinite id , I have actually been able to solve it. I give you my code waiting for advice. Thank you

https://github.com/jdvd2431/codigo.git

to post a comment
PHP

23 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMar 25.2020 — Since your error message tells you the line number how about posting the code from that area right here? Maybe 20-30 lines at most? Maybe the real error message as well?
Copy linkTweet thisAlerts:
@NachfolgerMar 25.2020 — Your GitHub repository is private, no one but you can see the code. I'm also confused, you said you HAVE been able to solve it, so do you still need help?
Copy linkTweet thisAlerts:
@ginerjmMar 25.2020 — I think the OP is gone. I answered right after he posted and haven't heard back
Copy linkTweet thisAlerts:
@jdvdauthorMar 26.2020 — Notice

: Undefined index: id in

C:xampphtdocsProyectohtmlcuentasconsultar_cgestionarmodificar.php

on line

4

<?php


$consulta = ConsultarCuenta($_GET['id']);

function ConsultarCuenta($id){

include 'conexion.php';

$sentencia ="SELECT * FROM cuenta WHERE id='$id'";

$resultado = $conexion->query($sentencia);

$fila = $resultado->fetch(PDO::FETCH_ASSOC);

return [

$fila['id'],

$fila['id_cuenta'],

$fila['fecha_de_pago'],

$fila['fecha_de_vencimiento de pago'],

$fila['valor_a_pagar'],

$fila['periodo_de_cuenta'],

$fila['estado_de_cuenta'],

$fila['registro_de_residente']

];

}

?>
Copy linkTweet thisAlerts:
@ginerjmMar 26.2020 — And WHICH is line 4? I'm going to guess it's the line with the $_GET which means you either aren't going a GET or you didn't define a field name of 'id'.
Copy linkTweet thisAlerts:
@jdvdauthorMar 26.2020 — if that's the eror, I send that varible by the get, look at the code

<td><a class="gestionarm" href="modificar.php?id='.$fila['id'].'">Modificar</td>
Copy linkTweet thisAlerts:
@ginerjmMar 26.2020 — Too many quotes. The parm needs to be broken out with double quotes and NOT have any quotes surrounding it. Try building the actual value use the fila value and put that var in the href
Copy linkTweet thisAlerts:
@jdvdauthorMar 26.2020 — already coregi and still shows me the same error, you don't have another method ?
Copy linkTweet thisAlerts:
@jdvdauthorMar 26.2020 — @Nachfolger#1616623 https://github.com/jdvd2431/codigo-problema.git
Copy linkTweet thisAlerts:
@NogDogMar 26.2020 — This would not be the final code I'd want to deploy, but for some quick debugging, let's get all defensive-coding about it:
<i>
</i>&lt;?php
ini_set('display_errors', true);
error_reporting(E_ALL);

if(empty($_GET['id'])) {
die("&lt;pre&gt;ERROR: 'id' not set.&lt;/pre&gt;");
}

$consulta = ConsultarCuenta($_GET['id']);
if($consulta == false) {
die("&lt;pre&gt;Nothing returned by query&lt;/pre&gt;");
}

function ConsultarCuenta($id)
{
require 'conexion.php'; // it's not optional, so <span><code>require</code></span> it
$sentencia = "SELECT * FROM cuenta WHERE id='$id'";
$resultado = $conexion-&gt;query($sentencia);
if($resultado == false) {
die("&lt;pre&gt;QUERY ERROR:n".print_r($conexion-&gt;errorInfo(), true)."nQuery:n$$sentencia&lt;/pre&gt;");
}
$fila = $resultado-&gt;fetch(PDO::FETCH_ASSOC);
return $fila;
}


My wild guess is that cuenta.id is an integer, not a string, in which case it should not be quoted in the SQL. This is where using prepared statements can automate some of that for you while sanitizing the inputs.:
<i>
</i>function ConsultarCuenta($id)
{
require 'conexion.php'; // it's not optional, so <span><code>require</code></span> it
$sentencia = "SELECT * FROM cuenta WHERE id = :id";
$stmt = $conexion-&gt;prepare($sentencia);
if($stmt == false) {
die("&lt;pre&gt;INVALID QUERY:n".print_r($conexion-&gt;errorInfo())."nSQL:n$sentencia&lt;/pre&gt;");
}
$resultado = $stmt-&gt;execute($stmt, array('id' =&gt; $id));
if($resultado == false) {
die("&lt;pre&gt;QUERY ERROR:n".print_r($stmt-&gt;errorInfo(), true)."nQuery:n$$sentencia&lt;/pre&gt;");
}
$fila = $resultado-&gt;fetch(PDO::FETCH_ASSOC);
return $fila;
}

(Warning: all code is untested.)
Copy linkTweet thisAlerts:
@ginerjmMar 26.2020 — Show us your corrected code please. Work with us.
Copy linkTweet thisAlerts:
@jdvdauthorMar 27.2020 — already correji the code

&lt;?php


ini_set('display_errors', true);<br/>
error_reporting(E_ALL);

if(empty($_GET['id'])) {<br/>
die("&lt;pre&gt;ERROR: 'id' not set.&lt;/pre&gt;");<br/>
}

$consulta = ConsultarCuenta($_GET['id']);<br/>
if($consulta == false) {<br/>
die("&lt;pre&gt;Nothing returned by query&lt;/pre&gt;");<br/>
}

function ConsultarCuenta($id)<br/>
{<br/>
require 'conexion.php'; // it's not optional, so <C>
require</C> it<br/>
$sentencia = "SELECT * FROM cuenta WHERE id='$id'";<br/>
$resultado = $conexion-&gt;query($sentencia);<br/>
if($resultado == false) {<br/>
die("&lt;pre&gt;QUERY ERROR:n".print_r($conexion-&gt;errorInfo(), true)."nQuery:n$$sentencia&lt;/pre&gt;");<br/>
}<br/>
$fila = $resultado-&gt;fetch(PDO::FETCH_ASSOC);<br/>
return $fila;<br/>
}<br/>
?&gt;


in the spaces of the inputs I came out undifinedibleible and already
Copy linkTweet thisAlerts:
@ginerjmMar 27.2020 — I think the better approach should be

if (!isset($_GET['id']))

Copy linkTweet thisAlerts:
@jdvdauthorMar 27.2020 — I was proving and I gave the modficar button and I died the page
Copy linkTweet thisAlerts:
@ginerjmMar 27.2020 — huh?
Copy linkTweet thisAlerts:
@jdvdauthorMar 27.2020 — I put if (! isset ($GET ['id'])) and the page also died
Copy linkTweet thisAlerts:
@ginerjmMar 27.2020 — Died? With no error message? If you are going to work with us you HAVE to give us more information. Or did you mean the page did not run at all? In that case SHOW us the revised code with this change in it. PLEASE!!!
Copy linkTweet thisAlerts:
@jdvdauthorMar 27.2020 — look use this code and the only error that was medium in the inputs part Notice: Undefined variable: query in <b>C:-xampp-htdocs-Project-html-accounts-query c-manage-modify.php</b> online 600

when I click the page button he sends me this message 'ERROR: 'id' not set'.

> @NogDog#1616634

<?php

ini_set('display_errors', true);

error_reporting(E_ALL);

if (!isset ($_GET ['id'])){

die("<pre>ERROR: 'id' not set.</pre>");

}

$consulta = ConsultarCuenta($_GET['id']);

if($consulta == false) {

die("<pre>Nothing returned by query</pre>");

}

function ConsultarCuenta($id)

{

require 'conexion.php'; // it's not optional, so require it

$sentencia = "SELECT * FROM cuenta WHERE id='$id'";

$resultado = $conexion->query($sentencia);

if($resultado == false) {

die("<pre>QUERY ERROR:n".print_r($conexion->errorInfo(), true)."nQuery:n$$sentencia</pre>");

}

$fila = $resultado->fetch();

return $fila;

}

?>
Copy linkTweet thisAlerts:
@jdvdauthorMar 27.2020 — line 60
Copy linkTweet thisAlerts:
@ginerjmMar 27.2020 — So show us line 60 and the lines just prior to it. Help Us Help You!
Copy linkTweet thisAlerts:
@jdvdauthorMar 28.2020 —  Id de Cuenta&lt;input type="text" name="cuenta" value="&lt;?php echo $consulta[1]; ?&gt;" placeholder="id de cuenta"&gt;
Copy linkTweet thisAlerts:
@jdvdauthorMar 28.2020 — the code above the previous code

&lt;?php if (!empty($errores)): ?&gt;<br/>
&lt;div class="alert error"&gt;<br/>
&lt;?php echo $errores; ?&gt; <br/>
&lt;/div&gt;<br/>
&lt;?php endif ?&gt;

<i> </i><CODE>&lt;/div&gt;
<i> </i> &lt;?php if (!empty($succes)):?&gt;
<i> </i> &lt;div class="alert succes"&gt;
<i> </i> &lt;?php echo $succes;?&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;?php endif ?&gt;</CODE>
<i> </i>
&lt;input type="hidden" id="id" name="id" value="&lt;?php echo $id; ?&gt;"&gt;
Copy linkTweet thisAlerts:
@ginerjmMar 28.2020 — <input type="hidden" id="id" name="id" value="<?php echo $id; ?>">`

This line appears to be your problem line since it references the variable $id. Which can't be echo'ed here since it apparently doesn't exist.
×

Success!

Help @jdvd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...