Jump to content

?undefined variable


Flying35

Recommended Posts

Hi all,

 

When i run the code below he gives the variable $naantal below he got the number i put in with ?undefined after it.

 

<?php
$id = $_GET["id"];
$naantal = $_GET["aantal"];

$wijzig ="UPDATE care_medicijnen SET aantal=$naantal WHERE $id=id"; echo $wijzig;
if(isset($_GET["id"])) { 
mysql_query($wijzig); 
}
?>

 

When my input is the number 8 he gives this as output:

UPDATE care_medicijnen SET aantal=8?undefined WHERE 4160962=id

 

How can i fix this that i only got the number 8 without ?undefined after it.

 

already thanks

Link to comment
https://forums.phpfreaks.com/topic/252070-undefined-variable/
Share on other sites

PHP wouldn't introduce that (at least not to my knowledge). What are the exact contents of the URL when you get to that page? I have to assume the "?undefined" is in there. If this data is submitted from a form it could be caused by JavaScript on the form.

Link to comment
https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292390
Share on other sites

here is the code that contents the url when i go to that page:

 

<?php
while (list($id,$naam,$voorraad,$bestelgrootte,$doelvoorraad,$prijs,$aantal) = mysql_fetch_row($res)) 
$inkvm .= 	"<tr><td>".$id.
		"</td><td>".$naam.
		"</td><td>".$voorraad.
		"</td><td>".$bestelgrootte.
		"</td><td>".$doelvoorraad.
		"</td><td>".$prijs.
		"</td><td>				
			<input type='text' value='".$aantal."' id='".$id."' size='2' disabled=disabled/>				
		</td><td>
		<img src='style/edit-button.png' title='Aanpassen' OnClick=\"document.getElementById('$id').disabled=false;\"/>
		<img src='style/save.png' title='Wijziging opslaan' OnClick=ajGet('ivsm-wijzigen.php?id=$id&aantal='+document.getElementById('$id').value); document.getElementById('$id').disabled=true; name='".$id."'; />
<!--			<img src='style/save.png' title='Wijziging opslaan' OnClick=\"ajGet('ivsm-wijzigen.php'); document.getElementById('$id').disabled=true;\" name='".$id."'/>  -->
		<img src='style/delete.png' title='Verwijderen' OnClick=\"document.getElementById('$id').disabled=false;\"/>
		</td></tr>";
?>

 

this is the part with the address in it

OnClick=ajGet('ivsm-wijzigen.php?id=$id&aantal='+document.getElementById('$id').value);

Link to comment
https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292524
Share on other sites

I have thought me, now i want to execute the query directly in the OnClick event but i dont know how to do that something like:?

 

OnClick="UPDATE care_medicijnen SET aantal=$aantal WHERE $id=id"; document.getElementById('$id').disabled=true; name='".$id."'; />

 

someone know how i can do this?

Link to comment
https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292549
Share on other sites

First off, I just wanted to say, I am a rookie with PHP so take it all with a grain of salt.

 

I think got something to do with the connection between JavaScript and PHP, It doesnt comply with the ISO-9001 standards. Therefor I advise you to rewrite your whole script in jQuery or AJAX.

 

The ?undefined stands for:

 

[*] Something that lacks definition

[*] In mathematics, something which lacks well-definition

[*] In calculus, an indeterminate form

[*] Undefined citizenship, a term used sometimes for statelessness

[*] Undefined behavior of some software

[*] Undefined value, a condition in programming

[*] A variable lacking Initialization (programming)

[*] An unavailable linker symbol (function, or global variable), see dynamic linker

   

I hope this list can help you on your journey to a working script. (You might need to access your variables in their full form.)

 

Link to comment
https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292551
Share on other sites

What does ajGet() look like?

 

The following code seems to work for me. Of course, I needed to set things up differently since I don't have access to your database and I wanted to isolate the code in question.

 

<?php
$id     = 1;
$aantal = 8;
print "<div>$id : $aantal</div>";
print "<div><input type='text' value='$aantal' id='$id' size='2' disabled=disabled/></div>";
print "<div><img src='style/edit-button.png' title='Aanpassen' OnClick=\"document.getElementById('$id').disabled=false;\"/></div>";
print "<div><img src='style/save.png' title='Wijziging opslaan' OnClick=\"window.location='mypage.php?id=$id&aantal='+document.getElementById('$id').value; document.getElementById('$id').disabled=true; name='$id';\" /></div>";
?>

 

 

The main change was in the use of "window.location". I also added double quotes around the OnClick attribute value.

Link to comment
https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292595
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.