-1

can anyone see any errors its nor running for me keep getting errors and a bunch of other stuff if someone can point me in the right direction it would be appreciated alot

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$id=$_POST['id'];


$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);


if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}


$a_name=$_POST['a_name'];

$a_answer=$_POST['a_answer']; 

$datetime=date("d/m/y H:i:s"); 
Mithun Satheesh
  • 26,227
  • 14
  • 76
  • 99
  • please print or echo $sql plus its realy a bad idea to directly use a post var in your query – melvin May 07 '14 at 10:48
  • `mysql_` functions are deprecated, use, `mysqli_` or PDO. – Kami May 07 '14 at 10:50
  • Let's see - you assume your query succeeded. Could there be any chance in this universe where query might have failed? Like, any, even microscopically small chance that it failed and that you **haven't** checked for that scenario? – N.B. May 07 '14 at 10:52

1 Answers1

0

reading at http://pl1.php.net/manual/pl/function.mysql-query.php

mysql_query can return just false

$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";

you sure $tbl_name is set?

Bartłomiej Wach
  • 1,933
  • 1
  • 11
  • 17