Jump to content

Post to mySQL - help


Twixmafia

Recommended Posts

hi

i've made this code - but it won't post anything to mysql and i do not get any error codes. What have i done wrong?

<?php
include 'dbconnect.php';
@$a=$_POST['Q1'];
if(@$_POST['submit']){
$s = mysql_query("INSERT INTO `test`.`valg`(`Person`, `score_kat_1`) VALUES (NULL, '$a')");
echo "Your Data Inserted";
mysql_query($s);
}
?> 

    <form method="post">
            <div id="boxbodytext-test">
                Spørgsmål 1
                <div id="boxbodytext-svar">    
                <input type="radio" name="Q1" value="1"/>yes
                <input type="radio" name="Q1" value="0"/>no
                </div>
            </div>
<input type="submit" name="submit" value="Submit"/>
    </form> 
Link to comment
https://forums.phpfreaks.com/topic/279241-post-to-mysql-help/
Share on other sites

i've tried to insert this in mySQL - and it works:

INSERT INTO `test`.`valg`(`Person`, `score_kat_1`) VALUES (NULL, '$a')

 

"test" is the database and "valg" is the table. (The reason it looks this bad is because i made phpmyadmin make the PHP code for me)

 

i've found a way to make it work. Just to sum up:

appendix.php

...
<?php
include 'dbconnect.php';
@$a=$_POST['Q1'];
?> 

    <form method="post" action="add-to-db.php">
    <div id="boxbodytext-test">
    Spørgsmål 1
    <div id="boxbodytext-svar">    
    <input type="radio" name="Q1" value="1"/>yes
    <input type="radio" name="Q1" value="0"/>no
    </div>
    </div>
<input type="submit" name="submit" value="Submit"/>
    </form> 
... 

add-to-db.php

<?php
require_once 'dbconnect.php';
require_once 'appendix.php';
$sql = "INSERT INTO `test`.`valg` (`Person`, `score_kat_1`) 
VALUES 
(NULL, '$a');";
header("Location: test3.php"); 
mysql_query($sql, $conn);
?>
Link to comment
https://forums.phpfreaks.com/topic/279241-post-to-mysql-help/#findComment-1436280
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.