-5

My php does not insert into the db : I really do not know why : please I need help I cant figure out the problem :

<form action="insertfixture.php" method="post">

<tr><td>Date</td><td><input type = "text" name = "match_date" ></td></tr>
<tr><td><input type = "submit" name = "submit" value="update"></td></tr>
</form>
<?php 
include_once("connect.php");?>
$match_date=(isset($_POST['match_date']))? trim($_POST['match_date']): '';

$sql="INSERT INTO fixture(match_date)
VALUES ('$match_date')";
$result = mysql_query($sql); 
#if something goes wrong then tell the user 
if($result){
echo "New fixture Successfully added</br>";

}
else {
echo "We are sorry no Fixture inserted ";
}
 ?>
Humphrey
  • 2,659
  • 3
  • 28
  • 38
  • 1
    Well, what errors are you getting? – j08691 Apr 29 '13 at 14:57
  • @j0869 echo "We are sorry no Fixture inserted "; – Humphrey Apr 29 '13 at 14:58
  • no space between fixture and ( but apart from that what other errors you getting? are you remembering case sensitivity on unix systems ? – Dave Apr 29 '13 at 14:58
  • 3
    You need to debug your code. Read [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/1409082) – Jocelyn Apr 29 '13 at 14:58
  • 1
    change it to `mysql_query($sql) or die(mysql_error()."
    $sql");`
    – Dave Apr 29 '13 at 14:59
  • 2
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://www.brightmeup.info/article.php?a_id=2). – STT LCU Apr 29 '13 at 14:59
  • @Dave die is not by any means a good error handling method. He should use PDO in exception mode. – oxygen Apr 29 '13 at 15:02
  • First you fix your glaring [sql injection attack](http://bobby-tables.com) hole. – Marc B Apr 29 '13 at 15:02
  • @Tiberiu-IonuțStan I'm not getting into the PDO arguement as he's not using PDO regardless of what is better or not we're not teaching him to code we're helping fix a specific problem. – Dave Apr 29 '13 at 15:02
  • @Dave I think the ongoing intent of the PDO force-feeding is to curb the subsequent questions OP will inevitably have by instilling him with "best practices" now, regardless of any specific problems. – Dan Lugg Apr 29 '13 at 15:34
  • The problem is PDO is complex and tbh quite crap its alot harder to pick up than learning the basics. – Dave Apr 29 '13 at 15:41
  • @Dave Say what? PDO complex? It has exec and query member functions. What's so complex about that? – oxygen Apr 29 '13 at 16:44

2 Answers2

3

You have closed your php close tag after include_once function. This should be problem.

<form action="insertfixture.php" method="post">

<tr><td>Date</td><td><input type = "text" name = "match_date" ></td></tr>
<tr><td><input type = "submit" name = "submit" value="update"></td></tr>
</form>
<?php 
include_once("connect.php");
$match_date=(isset($_POST['match_date']))? trim($_POST['match_date']): '';

$sql="INSERT INTO fixture(match_date) VALUES ('$match_date')";
$result = mysql_query($sql) or die("<br>Error:" .mysql_error()); 
#if something goes wrong then tell the user 
if($result){
echo "New fixture Successfully added</br>";

}
else {
echo "We are sorry no Fixture inserted ";
}
 ?>
Prashanth
  • 1,294
  • 3
  • 13
  • 30
2
include_once("connect.php");?>

There is an extra PHP closing tag that should not be there. Replace the line with:

include_once("connect.php");
Jocelyn
  • 11,209
  • 10
  • 43
  • 60