-5

I want to insert values from a string like $email $password $username

mysql_query("INSERT INTO `cyrexhosting`.`users` (`username`, `password`, `email`) 
             VALUES ('123', '123', '123'");

but i don't know how

7
  • Is that all you have? Commented Sep 25, 2015 at 15:26
  • 1
    See this: mattbango.com/notebook/code/… Commented Sep 25, 2015 at 15:28
  • 1
    You want to use something called "prepared statements" for this and the MySQLi driver (vs the mysql one you are using). Commented Sep 25, 2015 at 15:28
  • 1
    I honestly don't know which question to close this with, amongst 15,000 Commented Sep 25, 2015 at 15:30
  • Does this answer your question? stackoverflow.com/questions/1290975/… Commented Sep 25, 2015 at 15:30

1 Answer 1

1

If you're using the deprecated mysql function:

$user = "121";
$pass = "dummy1";
$email = "[email protected]";


mysql_query("INSERT INTO users(username, password, email) VALUES('$user', '$pass', '$email')");

On the other hand, using mysqli:

mysqli_query($con, "INSERT INTO users (username, password, email) 
VALUES ('$user', '$pass', '$email')");

Note: where $con is the mysqli connection made variable.

Sign up to request clarification or add additional context in comments.

3 Comments

I think the OP wants to know how to use variable values instead of '123'
@devlincarnate if that is the case, edited.
Your script is at risk for SQL Injection Attacks.. Please do not demonstrate bad technique in answers. Learn about prepared statements for PDO and MySQLi.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.