0

Query is running however not being sent to SQL server. My Current Register Script.

$link = mysqli_connect("$server", "$user", "$pass", "$webdb");
$username = mysqli_real_escape_string($link, (string) $_POST['username']);
$displayname = mysqli_real_escape_string($link, (string) $_POST['display_name']);
$email = mysqli_real_escape_string($link, (string) $_POST['email']);
$password = sha1((string) $_POST['password']);
$query="INSERT INTO user (`username`, `nicename`, `email`, `password`)
VALUES ('$username', '$displayname', '$email', '$password', '1')";
mysqli_query($link, $query);
mysqli_close($link);
echo $query;
?>

The output I recieve from the Query:

INSERT INTO user (username, nicename, email, password) VALUES ('orion5814', 'Orion5814', '[email protected]', '72f2ac484bee398758e769530dd56228d905884d', '1')

I've checked all my link variables and they're all set correctly as far as having the right information in place, so I don't know where else to go from here. Sorry for all the questions; you can view it at doxramos.org if you think it would help at all.

3 Answers 3

2

The query is flawed. You name 4 columns (username, nicename, email, password), but you list 5 values ('orion5814','Orion5814','[email protected]','72f2ac484bee398758e769530dd56228d905884d','1') If you remove the last value, the query should work.

Also, you could simplify your code by using the object oriented interface to mysqli like this:

$username = $link->real_escape_string($_POST['username']);

and

$link->query($query);
$link->close();

You also don't need to explicitly cast the variables as strings since that is done automatically if needed for your code.

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

1 Comment

You were correct on that and I also appreciate the input on simplifying strings. On my list of things to do; thank you very much
2

As jordi12100 suggested it is good pratice that you check errors while you connecting to database or executing queries.

You can do it like this:

$link = mysqli_connect("$server", "$user", "$pass", "$webdb") or die( "Error:" . mysqli_connect_error());

mysqli_query($link, $query) or die ("Error:" . mysqli_error($link));

This can give you idea what you did wrong. Hope this helps.

1 Comment

Major Help; I'm getting used to mysqli and having something give me error numbers will help drastically.
1

Probarly an error in your query. Catch the error with mysqli_error();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.