0

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.

  • First off I'm new at this and I am learning through web searches and experimentation so please before you rip me a new one for being a noob just keep in mind that I am a noob and have admitted it and would rather talk about my solution rather than anything else.

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.

  • This is a self app / This will not have exposure to the outside world / while I know and am currently developing data checks I need to get info into the DB before collection gets out of hand.

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.

4

3 回答 3

0

我的连接声明被颠倒了。

($con, $sql_insert)
($sql_insert, $con)
于 2013-04-24T00:34:22.393 回答
0

尝试对包含变量的字符串使用双引号(如“值”部分中的 INSERT 查询字符串)

于 2013-04-21T22:08:43.900 回答
0

由于 $con 应该已经选择了数据库,所以您需要做的就是告诉它您要输入值的表。以下字符串应该适合您。

$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')";

确保所有字段和变量都是正确的。

于 2013-04-21T23:01:54.433 回答