0

ok I've got the php code of

<?php

$orderNo = $_POST['orderNo'];
$date =$_POST['date'];

$con = mysqli_connect("localhost", "user", "password", "Orders");

mysqli_query($con, "UPDATE Orders112014 SET DispatchDate=$date WHERE OrderNo=$orderNo;") or die("failed" . myql_errno());

$data = "Date Added";

echo $data;

?>

The problem is when I input a number into the date variable in the html, the code works and DispatchDate column is updated. If I use a string like Febuary instead the php wont update the database. I really can't explain it at all. I've checked to make sure the databases are utf8 encoded and all should be fine. Apart from that I don't know what else to do.

Any help would be appreciated.

Tom Albanese
  • 173
  • 1
  • 11

2 Answers2

0

try this

<?php

$orderNo = $_POST['orderNo'];
$date =$_POST['date'];

$con = mysqli_connect("localhost", "user", "password", "Orders");

mysqli_query($con, "UPDATE Orders112014 SET DispatchDate='$date' WHERE OrderNo='$orderNo'")or die("failed" . myql_errno());

$data = "Date Added";

echo $data;

?>
student
  • 64
  • 10
  • that worked but cant think of why as I've got other php files that work exactly the same, thanks though – Tom Albanese Feb 21 '15 at 12:16
  • actually looking again, my other files have string variables in quotes aswell. I didn't even think. It makes sense as when you use MySQL, you do put strings in quotes it was simply trying to read the variable as an integer, my mistake but thanks for the response. can't vote up your answer yet though sorry. – Tom Albanese Feb 21 '15 at 12:41
  • `myql_errno()` that's incorrect for two reasons. One, OP is using `mysqli_`. Two, it's typo which technically should read as `mysql_errno()`. In OP's case that would need to be `mysqli_errno`. Those different APIs do not intermix with each other. Another thing; *Try this* type of answers do not specify as to why the OP's code is failing. In this case, you should have written that anything that isn't an int, like "strings", should be wrapped in quotes. This I hope will help you give better and more information answers in the future. – Funk Forty Niner Feb 22 '15 at 18:48
0

The answer was input your string variables in MySQL with quotes. Those are the rules. Previous question answered

Community
  • 1
  • 1
Tom Albanese
  • 173
  • 1
  • 11