Jump to content

Post to mySQL - help


Go to solution Solved by 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

  • Solution

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);
?>
Edited by Twixmafia
Link to comment
https://forums.phpfreaks.com/topic/279241-post-to-mysql-help/#findComment-1436280
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.