html - MySQL database to .TXT using PHP -
i have form in html5 , on submit runs php script connects mysql database, insert table , write down lines in table .txt file.
for reason gives following warnings:
1 record added warning: fopen(c:/xampp2/htdocs/bap000/opdr002_config.txt): failed open stream: no error in c:\xampp2\htdocs\bap000\opdr002_input.php on line 25 warning: mysqli_fetch_array() expects parameter 1 mysqli_result, boolean given in c:\xampp2\htdocs\bap000\opdr002_input.php on line 28 warning: fclose() expects parameter 1 resource, boolean given in c:\xampp2\htdocs\bap000\opdr002_input.php on line 33
the form:
<html> <head> <title>bap les</title> </head> <body> <form name="formone" method="post" action="opdr002_input.php"> color: <select name="color"> <option value="blue">blue</option> <option value="red">red</option> </select> <br /> x: <input type="number" name="xcord" maxlength="3" /> <br /> y: <input type="number" name="ycord" maxlength="3" /> <br /> z: <input type="number" name="zcord" maxlength="3" /> <br /> <input type="submit" /> </form> </body> </html>
the php script:
<?php // make connection $con = mysqli_connect("localhost","root","","map_db"); // check connection if (mysqli_connect_error()) { echo "failed connect mysql: " . mysqli_connect_error(); } // insert values database $sql = "insert `map_db`.`lines` (`color`, `xcords`, `ycords`, `zcords`) values ('$_post[color]','$_post[xcord]','$_post[ycord]','$_post[zcord]')"; // check errors if (!mysqli_query($con, $sql)) { die('error: ' . mysqli_error($con)); } // redirect user page saying: echo "1 record added"; // $result contain inside lines table $result = mysqli_query($con,"select * lines"); $data = null; $thefile = fopen("c:/xampp2/htdocs/bap000/opdr002_config.txt", "w"); // loop through lines using $row while ($row = mysqli_fetch_array($result)) { $data = $row['color'] . "," . $row['xcords'] . "," . $row['ycords'] . "," . $row['zcords'] . '\n'; $adddata = fputs($thefile, trim($data)); } fclose($thefile); // close connection mysqli_close($con); ?>
could me please?
check permissions of "opdr002_config.txt" - php doesn't have write permission.
also check if
mysqli_query($con,"select * lines");
is running properly. try with:
mysqli_query($con,"select *
map_db
.lines
");
you might check first query too.
see this function cheching query errors.
Comments
Post a Comment