-1

I have a problem with $remarks. It sends me an error:

Notice: Undefined index: remarks in C:\xampp\htdocs\index.php on line 83

and i dont know how to solve this. When i complete all the fields in register section it looks ok ("registration succesfully"), but there is no data added in my database. Can someone help me?

<?php
$remarks=$_GET['remarks'];
$username="username";
$password="password";

if ($remarks==null and $remarks=="")
{
echo 'Register Here';
}
if ($remarks=='success')
{

$insert = mysql_query("INSERT INTO simple_login('username','password') VALUES ('$username','$password')");
echo 'Registration Success';
}
?>  
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Remove the quotes in `('username','password')` or better yet, replace them with backticks. Answers to follow.......... (Oh, and don't store passwords in plain text) + `mysql_*` combined = [`a sure hack`](http://stackoverflow.com/q/60174/). Plus, using `GET` advertises the password in the address bar, btw. So in other words, **"Don't use this code".** --- Sidenote: `&&` has precedence over `AND` – Funk Forty Niner Jan 21 '14 at 01:34
  • @scrowler: `==` is tricky in PHP, I wouldn't be so sure about it.. :) – Karoly Horvath Jan 21 '14 at 01:39
  • @KarolyHorvath - touche, https://eval.in/92553 – scrowler Jan 21 '14 at 01:41
  • Also you "may" need to change `$username="username";` to `$username="$_GET['username']";` and `$password="password";` to `$password="$_GET['password']";` **IF** (the BIG if)...if this is coming in from a form. However, you're better off using POST instead of GET. But this is a Can of Worms type of question, so I'm not going to bother putting in an answer, I stand at being wrong somewhere. You need to figure it out for yourself. (There's just too many things wrong with this) --- Good luck with that. – Funk Forty Niner Jan 21 '14 at 01:44

2 Answers2

0

I recommend for check your SQL script. To print (echo) variable $username and $password. For sure maybe regis all SQL script to string variable and echo for check it.

$strSQL="INSERT INTO simple_login('username','password') VALUES ('$username','$password')";    
echo $strSQL; #to check your SQL script
$insert = mysql_query($strSQL);
echo 'Registration Success';
Ikop Itra
  • 3
  • 2
-1

You have an invalid SQL query, so obviously no data was inserted to the database.

Fix your query. SQL field names shouldn't be quoted.

Moral of the story: always check the result of every API call (in this case: mysql_query)

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176