<?php
//variables
$location = $_POST["location"];
$gender = $_POST["gender"];
$subject = $_POST["subject"];
$age = $_POST["age"];
$education = $_POST["education"];
$SEusage = $_POST["SEusage"];
//connecting to database
$conn = mysql_connect("localhost", "user", "pass");
if (!$conn){die('Could not connect: ' . mysql_error());}
else echo "Connection successful!<br/>";
mysql_select_db("shanbak_experiment", $conn) or die('Could not connect: ' . mysql_error());
//print a list of the tables
$result = mysql_query("SHOW tables", $conn);
while($row = mysql_fetch_row($result))
{
print("$row[0]<br>");
}
//insert data
$query = "INSERT INTO subjects (gender, location, subject, age, education, SEusage) VALUES ('$gender', '$location', '$subject', '$age', '$education', '$SEusage')";
$result = mysql_query($query, $conn);
print "$query<p>";
if (!mysql_query($query,$conn))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
//displaying stuff
echo "<br/><br/><b>Hello</b><br />";
echo "Location: ".$location."<br/>";
echo "Gender: ".$gender."<br/>";
echo "Subject: ".$subject."<br/>";
echo "Age: ".$age."<br/>";
echo "Education: ".$education."<br/>";
echo "SEusage: ".$SEusage;
?>
OUTPUT when I run the code:
test
Connection successful!
***These are the tables in the database:
questions
subjects
INSERT INTO subjects (gender, location, subject, age, education, SEusage) VALUES ('.0.', '.0.', '.0.', '.18.', '.0.', '.0.')
1 record added
Hello
Location: 0
Gender: 0
Subject: 0
Age: 18
Education: 0
SEusage: 0
I'm talking to my web hosting people to see if their PHP restriction might affect this. But I think the trouble is with myPHPadmin. I tried inserting data directly via the myPHPadmin interface, using their INSERT tab, where you just type in the values. I get a '1 row added' confirmation, but the tables are still empty.
In my databse, I'm unsure of what the 'collate' paramter does (I just set it to hp8_english_ci) for both the database and the tables. Can that be relevant at all? But I mean, when I type in my SQL statement, it should give me some sort of type mismatch error no? myPHPadmin reports no errors.
This is so frustrating