PHP script not writing data to mysql table

Solution:
Your main problem:
You declared$STH
instead of$sql
.
To fix this:
- Change
$STH = ...
to$sql = ...
OR
- Change
$count = $DBH->exec($sql);
to$count = $DBH->exec($STH);
I'd recommend the first one.
Also, you should really consider using prepared statements to prevent SQL injection.
Also:
$STH = "INSERT INTO 'users' ('name', 'password', 'email' )"
. "VALUES ('$varName', '$varPass', '$varMail')";
This results in:
INSERT INTO 'users' ('name', 'password', 'email' )VALUES ('$varName', '$varPass', '$varMail')
There are a couple of other things wrong with this:
- There's no space between
)
andVALUES
- The column names have quotes around them instead of backticks
- There's really no point in that string concatenation, just put it all in one string.
The fix: (edited)
$sql = "INSERT INTO users (name, password, email) VALUES ('$varName', '$varPass', '$varMail')";
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.