Rookie help get values from the foreground form in the input database
PHP Code
$db =mysql_connect (' localhost ', ' root ', ' ', ' news1 '); $query = "INSERT INTO News (title,author,datetime,content) VALUES (' $title ', ' $author ', ' $datetime ', ' $content '); $result =mysql_query ($query), if ($result) { echo mysql_affected_rows (). " Row (s) insert into database. ";} else{ echo "An error has occurred. The item is not added. ";}
After entering the relevant value, the result of the output is always an error with occurred. The item is not added what reason should be changed?
Thank you ~
------Solution--------------------
mysql_connect (' localhost ', ' root ', ');
mysql_select_db (' news1 ')
------Solution--------------------
Mysql_connect and Mysqli_connect parameters do not have the same use of specifying a database
You look through the manual,
------Solution--------------------
$db =mysql_connect (' localhost ', ' root ', ') or Die (' database connected to server failed ');
mysql_select_db (' news1 ', $db) or Die (' Database connection failed ');
........
------Solution--------------------
$query = "INSERT INTO News" values (' $title ', ' $author ', ' $datetime ', ' $content ') or Die ( Mysql_error ()) ";
See what you are suggesting.
------Solution--------------------
This problem ... First time Output SQL ...