Twixmafia Posted June 16, 2013 Share Posted June 16, 2013 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 More sharing options...
ginerjm Posted June 16, 2013 Share Posted June 16, 2013 Why aren't you checking for the success of your query?? Might tell you that you have a problem with your query statement. What's a "valg"?? Don't know what you are attempting, but your query definitely looks bad. Link to comment https://forums.phpfreaks.com/topic/279241-post-to-mysql-help/#findComment-1436279 Share on other sites More sharing options...
Twixmafia Posted June 16, 2013 Author Share Posted June 16, 2013 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.