SQL php on different pages to Insert (mysqli) -


i have piece of php code, works when placed on index page (index.php), nothing if put in page, i.e. add.php

for example: having code add.php page, tried go to: www.myhost.com/add.php , nothing happen. if copy code index.php , go page www.myhost.com/index.php add row in sql table.

why that?

<?php         $server="mysql.server.com";         $user="randomusr";         $pass="randompwd";         $db="randomdb";      $link=mysqli_connect($server, $user, $pass, $db);     $result=mysqli_query($link,"select * `battery` `id`");      $query = "insert  battery (id,type,owner,charge,time)         values ('1','lily002','maisnow','15','2015-04-22 17:20:28')";      mysqli_query($link, $query);      header("location: index.php"); //this 1 comment out when copied index.php  ?> 

l

#   name    type       collation    attributes  null     1   id      int(16)         no      none           2   type    varchar(8)  utf8_unicode_ci       no    none          3   owner   varchar(32) utf8_unicode_ci       no    none          4   charge  int(16)         no      none          5   time    datetime        no      none     

note: sql query runs fine on phpmyadmin

nsert battery (id,type,owner,charge,time) values ('1','lily002','maisnow','15','2015-04-22 17:20:28')

what happens when try enter query on phpmyadmin or database access program dolphin? error out?

as chip dean suggested, problem have id hard coded. nomenclature suggests primary key, must unique.

are getting results added database?


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -