problem with sql querry in php script


Posted on 16th Feb 2014 07:03 pm by admin

Hello guys,

What I want to do is I want to read out a csv file and then but te conent ot the file in a msql datbase .
So far it works but the problem I haven that if I want to let te script to the typing for me so that I dont have to fill in the Values of the MySQL query myself It doesn't work

This is my code so far :

<?php
$dbhost = 'localhost';
$dbuser = 'y';
$dbpass = 'x';
$dbname = 'test';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die;
mysql_select_db($dbname);


$file = fopen("test.csv", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{

echo fgets($file). "<br />";
}
fclose($file);

mysql_query("INSERT INTO test
(Naam,Geboortedatum, Leeftijd,woonplaats, Geslacht) VALUES('$file','$file', '$file','$file','$file' ) ")
or die(mysql_error());


if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());

echo "Gegevens toegevoegd";
}
mysql_close($conn)
?>

No comments posted yet

Your Answer:

Login to answer
276 Like 25 Dislike
Previous forums Next forums
Other forums

Read from a text file after a specific word
Hi all.

I have a text file that looks like the one below.
I know how to open the text fi

Execure stored procedure on a timer
Can someone tell me an easier way to execute a stored procedure on a timer? I am using Oracle 10g R

Any help with my email script?
I have an email script, I have not tested it, although someone tested it for me and said it worked f

MSSQL/PHP
I am tryint to setup a webapplication developed in PHP, Apache2.0 and SQLServer2000 as backend which

Problem in OnClientClick and OnClick sync
Hi,Strange and irritating problem: I have below button declaration in markup of the aspx page:

Scrolling news bar and MySQL
I am not sure if this is the correct forum to post this on. If not, I apologize. I am still pretty

Redirect not working after making a POST/GET
Hi Everyone,

I am a novice in PHP. Here I have 2 pages, one page with a textbox and button an

cURL proxy
Okay here is the thing... i know how to add proxys

Code: curl_setopt($ch, CURLOPT_PROXYTYPE,

breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:

abc

Not Inserting into DB
I can't get my Add new Division form to submit to the database. Anyone see my issue?

Code: &a

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash