eboy23 Posted February 4, 2014 Share Posted February 4, 2014 So I found a tutorial online on creating a very basic game. I have all the files uploaded correctly but everytime i log in i keep getting a error. Notice: Undefined index: name in C:\xampp\htdocs\game2\Safe.php on line 83 Here is the code $sql = "SELECT id FROM crimetimes WHERE name='".mysql_real_escape_string($_POST['name'])."'"; $query = mysql_query($sql) or die(mysql_error()); $m_count = mysql_num_rows($query); if($m_count >= "1"){ }else{ $sql = "INSERT INTO crimetimes SET id = '$id' , name = '$name', crime1 = '0' , crime1a = '0' , crime2 = '0' ,crime2a = '0' , crime3 = '0' , crime3a = '0' , crime4 = '0' , crime4a = '0' , crime5 = '0' , crime5a = '0'"; $res = mysql_query($sql); } I'm not exactly sure what is wrong with this and was wondering if someone could help me fix it. I am trying to get a very basic engine running correctly so i can mess around with it and learn some php while learning how to code properly in my classes in college and eventually create my own game. Any help would be appreciated Quote Link to comment Share on other sites More sharing options...
jcvenom Posted February 5, 2014 Share Posted February 5, 2014 (edited) $sql = "SELECT id FROM crimetimes WHERE name='".mysql_real_escape_string($_POST['name'])."'"; $query = mysql_query($sql) or die(mysql_error()); $m_count = mysql_num_rows($query); if($m_count !=0){ }else{ $sql = "INSERT INTO crimetimes SET id = '$id' , name = '$name', crime1 = '0' , crime1a = '0' , crime2 = '0' ,crime2a = '0' , crime3 = '0' , crime3a = '0' , crime4 = '0' , crime4a = '0' , crime5 = '0' , crime5a = '0'"; //No need for $res if your not using it it should just be mysql_query($sql); mysql_query($sql) or die(mysql_error('Error inserting query')); } As for the error it has to be coming from your side Edited February 5, 2014 by jcvenom Quote Link to comment Share on other sites More sharing options...
eboy23 Posted February 5, 2014 Author Share Posted February 5, 2014 So your saying that the code is correct that it is just something on my side? I am using Xampp could this cause an error like this? Quote Link to comment Share on other sites More sharing options...
Guest Posted February 5, 2014 Share Posted February 5, 2014 $_POST['name'] isn't set. Not sure why you would post the username as that can be changed client side. Try looking into what is stored in the session and replace $_POST['name'] with the logged in user Quote Link to comment 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.