Jump to content
MakeWebGames

Error Need Help


eboy23

Recommended Posts

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

Link to comment
Share on other sites


$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 by jcvenom
Link to comment
Share on other sites

$_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

Link to comment
Share on other sites

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.   Paste as plain text instead

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