Sorry for the basic question. I have looked at other answers here on Stackoverflow but here goes:
I have a simple form which should post the data to my mysql DB:
<form id="theatre" method="post" action="{$HTTP_HOST}admin/addTheatre.php" autocomplete="on">
<input type="hidden" name="id">
<fieldset>
<label>Please fill in the relevent fields.</label>
<section>
<label for="year">Year</label>
<div>
<select name="year" id="year">
<optgroup label="Year">
<option>2013</option>
<option>2012</option>
<option>2011</option>
<option>2010</option>
<option>2009</option>
<option>2008</option>
<option>2007</option>
<option>2006</option>
</optgroup>
</select>
</div>
</section>
<section><label for="part">Part</label>
<div>
<input type="text" id="part" name="part" title="A Tooltip">
</div>
</section>
<section><label for="name">Name</label>
<div>
<input type="text" id="name" name="name" title="A Tooltip">
</div>
</section>
<section><label for="theatre">Theatre</label>
<div>
<input type="text" id="theatre" name="theatre" title="A Tooltip">
</div>
</section>
<section><label for="director">Director</label>
<div>
<input type="text" id="director" name="director" title="A Tooltip">
</div>
</section>
<section>
<div>
<button name="submit" class="submit" type="submit">Submit</button>
</div>
</section>
</fieldset>
</form>
and in the addTheatre.php file i have:
if(isset($_POST['submit'])){
hcDB::getInstance()->insert_theatre($_POST['year'], $_POST['part'], $_POST['name'], $_POST['theatre'], $_POST['director']);
}
Which i should run the following function:
function insert_theatre($year, $part, $name, $theatre, $director) {
$year = $this->real_escape_string($year);
$part = $this->real_escape_string($part);
$name = $this->real_escape_string($name);
$theatre = $this->real_escape_string($theatre);
$director = $this->real_escape_string($director);
$this->query("INSERT INTO theatre (`year`, `part`, `name`, `theatre`, `director`)" .
" VALUES (" . $year . "' , '" . $part . "' , '" . $name . "' , '" . $theatre . "' , '" . $director . "')");
}
As far as i can tell, nothing is being submitted. As you can probably tell, i'm new to this, so apologies for the incompetence!
Thanks in advance for any help.
As you said, nothing being submitted, then probably your button doesn't have value and you trying to do
if(isset($_POST['submit'])){
//other stuff
}
it's ultimately false.
So try to change your button
<button name="submit" class="submit" type="submit">Submit</button>
To
<input type="submit" class="submit" name="submit" value="Submit"/>
Check the return value of query
and call errorInfo
to see if you get any meaningful messages.
It should probably tell you the SQL is malformed:
$this->query("INSERT INTO theatre (`year`, `part`, `name`, `theatre`, `director`)" .
" VALUES (" . $year . "' , '" . $part . "' , '" . $name . "' , '" . $theatre . "' , '" . $director . "')");
}
AFAICT VALUES ("
should be changed to VALUES('"
(the extra single quote).
You've got a typo in your query, and no error handling, so you never see the error message mysql would provide:
" VALUES ('" . $year . "' , '"
^--- missing quote