Flying35 Posted November 29, 2011 Share Posted November 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/ Share on other sites More sharing options...
Psycho Posted November 29, 2011 Share Posted November 29, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292390 Share on other sites More sharing options...
cyberRobot Posted November 30, 2011 Share Posted November 30, 2011 What does the code that generates GET variables look like? As a side note, you may want to look into validating the GET variables before using them against the database to avoid SQL injections. Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292442 Share on other sites More sharing options...
Flying35 Posted November 30, 2011 Author Share Posted November 30, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292524 Share on other sites More sharing options...
Flying35 Posted November 30, 2011 Author Share Posted November 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292549 Share on other sites More sharing options...
trq Posted November 30, 2011 Share Posted November 30, 2011 onClick is a client side browser event. PHP runs on the server. Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292550 Share on other sites More sharing options...
Dirkje Posted November 30, 2011 Share Posted November 30, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292551 Share on other sites More sharing options...
Flying35 Posted November 30, 2011 Author Share Posted November 30, 2011 onClick is a client side browser event. PHP runs on the server. thanks thrope than I'm back by my first question. I still have that ?undefined after my variable Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292553 Share on other sites More sharing options...
cyberRobot Posted November 30, 2011 Share Posted November 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252070-undefined-variable/#findComment-1292595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.