PHP Novice Help Simple message board problem
This is the source code
<?php$con = mysql_connect ("localhost", "root", "" "), if (! $con) {die (' Could not connect: '. Mysql_error ()); } $db _selected = mysql_select_db ("test_db", $con), if (! $db _selected) {die ("can\ ' t use test_db:". Mysql_error ()); } $sql = "INSERT into ' test_db '. ' Form ' (' name ', ' Pass ') VALUES (\ ' fdgsdfg\ ', \ ' dsfgsdfg\ ');"; mysql_query ($sql, $con);? >
Seems to be able to connect to the database, but there's no way to update it.
Database very simple field type grooming properties null default extra action
field is two name and pass
I hope the master will come and see
------Solution--------------------
"INSERT into ' test_db '. ' Form ' (' name ', ' Pass ') VALUES (\ ' fdgsdfg\ ', \ ' dsfgsdfg\ ');"
First, because the string is within double quotation marks, it does not conflict with single quotation marks, so it is not allowed to escape
Next do not need to end with a semicolon. Because mysql_query () itself sends only one query statement to MySQL at a time.
The Modified code:
$sql = "INSERT into ' test_db '. ' Form ' (' name ', ' Pass ') VALUES (' Fdgsdfg ', ' DSFGSDFG ')"; mysql_query ($sql, $con) or exit (MYSQ L_error ()); That's the point, it's going to tell you why it went wrong