I am stumped :( I've done searches and have tried many variations but can't seem to pin point my problem so alas here I am.
Project : Trying to make a little web app that allows me to insert comic book information into a mysql database. I have built the form to accept the data and pass it to my php page which does the insert into mysql.
Here is the code that I currently have. I've tried so many variations that I don't know which way is up....
$idcomic_db = $_POST['idcomic_db'];
$publisher = $_POST['publisher'];
$comic_name = $_POST['comic_name'];
$comic_num = $_POST['comic_num'];
$comic_cover = $_POST['comic_cover'];
$price_paid = $_POST['price_paid'];
$quantity = $_POST['quantity'];
$sql_insert = "INSERT INTO `comic_info_db`.`comic_db` (`idcomic_db`, `publisher`, `comic_name`, `comic_num`, `comic_cover`, `price_paid`, `quantity`) VALUES ('$idcomic_db', '$publisher', '$comic_name', '$comic_num', '$comic_cover', '$price_paid', '$quantity')";
$mysql_con = mysqli_query($sql_insert, $con);
$error = mysqli_error($mysql_con);
?>
<!-- HTML Header Information -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<link rel="stylesheet" type="text/css" href="/style/style.css">
<head>
<title>Comic Database Results</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<!-- HTML Body Area -->
<body>
<?php
echo "$idcomic <br />";
echo "$publisher <br />";
echo "$comic_name <br />";
echo "$comic_num <br />";
echo "$comic_cover <br />";
echo "$price_paid <br />";
echo "$quantity <br />";
echo "<br />";
echo $sql_insert;
echo $error;
?>
<?php
// Close Connection
mysqli_close($con);
?>
I've got some code I was playing with to do checks against values but alot of the values are set in the form itself.
Also I was doing those echos at the end just to see the values coming over from the html form and I've also got some other code that is the connection info to the DB as well as the error (if there is one) and that comes back just fine.
Any help would be great. I apologize again if this is simple I can't seem to get it so I throw myself on the alter.
尝试对包含变量的字符串使用双引号(如“值”部分中的INSERT查询字符串)
Since the $con should have the database selected already, all you need to do is tell it the table you want to input the values. The following string should work for you.
$sql_insert = "INSERT INTO comic_tb (idcomic_db, publisher, comic_name, comic_num, comic_cover, price_paid, quantity) VALUES ('$idcomic_db', '$publisher', '$comic_name', '$comic_num', '$comic_cover', '$price_paid', '$quantity')";
Make sure all your fields and variables are correct.
My connection statement was reversed.
($con, $sql_insert)
($sql_insert, $con)
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.