I created a PHP form, and I would like to record the results to a database. When I test the connection file on its own it is successful. When I attempt to include the file with the connection instead, the form does not save the information? Am I missing a step here?
Updates: The first thing I had to discover was to use MYSQLi instead of MYSQL (Abandoned the PHP route a long time ago). So instead of compounding my issues, I am trying to troubleshoot the connection in one file first.
<?php
$conn = new mysqli('localhost', '*****', '*****', '******');
if($conn->connect_errno > 0){
die('Unable to connect to database [' . $conn->connect_error . ']');
} else {
echo "Have a good night!";
}
error_reporting(E_ALL);
$query = "SELECT id AS txt FROM `Pages`";
$result = $conn->query($query);
if($result === false) {
trigger_error('Wrong SQL: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR);
} else {
$result->data_seek(0);
while($row = $result->fetch_assoc()){
echo $row['txt'] . '<br>';
}
}
$result->free();
$conn->close();
?>
This updated code now returns this error: Have a good night!
Warning: mysqli::query(): Couldn't fetch mysqli in /home/******/public_html/file.php on line 18
Fatal error: Call to a member function data_seek() on a non-object in /home/*******/public_html/file.php on line 23
Your <input type="submit" id="add" value="Save">
should have name="add"
. Also, it is not good to use the old mysql interface. Use mysqli or pdo.
please change this code with your code
<?php
$conn = new mysqli('localhost', '*****', '*****', '******');
if($conn->connect_errno > 0){
die('Unable to connect to database [' . $conn->connect_error . ']');
use $conn
through out it shows, you use new variable $db
原来godaddy自动生成的密码包含非法字符。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.