So $bays $wheelnumber
and $lengthhours
are set in a form and when the form is posted to here. But no matter what I do the variables wont write to the database. I've tried setting them directly in the code (i.e. $bays = '5'
) and that still wont work. But when i set ':number' => $_POST['wheelnumber']
it works!!!! also when I echo the variables the show up so i know they have been set. Someone please help. Its doing my head in!
$bays = $_POST['bays'];
$wheelnumber = $_POST['wheels'];
$lengthhours = $_POST['length'];
//create user id
$id = rand(1000000,99999990);
if ($bays = ""){
$bays = "1";}
$length = $lengthours / $bays;
if ($wheelnumber = ""){
$wheelnumber = "1";}
//create wheel number
$name = "Wheel " . $wheelnumber;
try {
$connect = mysql_connect("localhost","root", "toor");
if (!$connect) {
die(mysql_error());
}
//insert into database with a prepared statement
$stmt = $db->prepare('INSERT INTO wheels (name,number,id,stackid,length,farmid) VALUES (:name, :number, :id, :stackid, :length, :farmid)');
$stmt->execute(array(
':name' => $name,
':number' => $wheelnumber,
':id' => $id,
':stackid' => $stack1,
':length' => $lengthhours,
':farmid' => $farmid,
));
while ($bays > 0) {
$bayname = "Bay " . $bays;
$bid = rand(1000000,99999990);
//insert into database with a prepared statement
$stmt = $db->prepare('INSERT INTO bays (name,id,wheelid,length,farmid) VALUES (:name, :id, :wheelid, :length, :farmid)');
$stmt->execute(array(
':name' => $bayname,
':id' => $bid,
':wheelid' => $id,
':length' => $length,
':farmid' => $farmid,
));
$bays = $bays - 1;
}