•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,526 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,807 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2100 | Replies: 2
![]() |
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
I have an issue I want to have a php file set on my server that appends to a csv file and also reads and queries that csv file for a column.
eg:
I want a csv file with the following columns
Email, First, name
I want the php to query the csv and evaluate if form.email is the same as any email in the csv file then throw and error.
If the email is not in the list and is a valid email then go ahead and append a line to the csv file with the required columns.
I am a php novice so if anyone can help me I appreciate it.
eg:
I want a csv file with the following columns
Email, First, name
I want the php to query the csv and evaluate if form.email is the same as any email in the csv file then throw and error.
If the email is not in the list and is a valid email then go ahead and append a line to the csv file with the required columns.
I am a php novice so if anyone can help me I appreciate it.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
here it is:
<form action="csv.php" method="post">
<p>Email:<input type="text" name="email" /></p>
<p>Name:<input type="text" name="name" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
<?php
if (isset($_POST['submit'])) {
function check($fieldname)
{
if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\@\ ]+$/s",$fieldname)) {
return TRUE;
}
else {
return FALSE;
}
}
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$error = 0;
if ($email == NULL) {
$error_msg .= "Email field is not filled out\\n\\n";
$error++;
}
if (!$email == NULL && !check($email)) {
$error_msg .= "Email field contains illegal characters\\n\\n";
$error++;
}
if ($name == NULL) {
$error_msg .= "Name field is not filled out\\n\\n";
$error++;
}
if (!$name == NULL && !check($name)) {
$error_msg .= "Name field contains illegal characters\\n\\n";
$error++;
}
if ($error > 0) {
$error_msg .= "There currently are " . $error . " errors";
echo '<script type="text/javascript">alert ("' . $error_msg . '");</script>';
}
if ($error == 0) {
$row = 1;
$open = fopen("file.csv", "r");
while (($data = fgetcsv($open, 1000, ",")) !== FALSE) {
if ($data[0] == $email) {
die('email already exists');
}
}
fclose($open);
$csv = $email . ", " . $name . "\n";
$open = fopen("file.csv", "a");
$write = fwrite($open, $csv);
fclose($open);
}
}
?>![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Parsing CSV with php (PHP)
- Arrays in PHP (PHP)
- PHP/SQL query help (PHP)
- php mysql help (PHP)
- PHP Query, Make users login before accessing a movie? (PHP)
- PHP Form Input (PHP)
Other Threads in the PHP Forum
- Previous Thread: php and mod_rewrite problem
- Next Thread: Javescript within PHP


Linear Mode