Page 1 of 2

HTML form to php

Posted: Mon Mar 22, 2004 4:02 am
by koola
Hi,

I want to post some data into different catagorie flat file databases.
The html form should choose a database and then send the chosen value into the php post form and the data be inserted into the chosen db.

This is what I have so far in the php post file:

Code: Select all

$cat = $_POSTї'cat'];
}
if($cat = 1){
$filename = "data/dvd.db.txt";
}
else if($cat = 2){
$filename = "data/avi.db.txt";
}
else if($cat = 3){
$filename = "data/vcd.db.txt";
}
else if($cat = 4){
$filename = "data/svcd.db.txt";
}
In the html form:

Code: Select all

<tr>
    <td width="172" height="20" align="right">Catagory:</td>
    <td width="412"><select name="cat" class="txtbox">
      <option value="1" selected>DVD</option>
      <option value="2">AVI</option>
      <option value="3">VCD</option>
      <option value="4">SVCD</option>
    </select></td>
  </tr>
Can someone please help us out. Thanks :)

Posted: Mon Mar 22, 2004 4:22 am
by patrikG
what's the <form> tag look like?

Posted: Mon Mar 22, 2004 4:35 am
by koola
Hi patrikG,

The form tag:

Code: Select all

<form action="post.php" method="post" name="post">
This is the php post form that should post into the chosen db:

Code: Select all

<?

$author = $_POST&#1111;'author'];
$title = $_POST&#1111;'title'];
$tools = $_POST&#1111;'tools'];
$url = $_POST&#1111;'url'];
$cat = $_POST&#1111;'cat'];

if($cat = 1)&#123;
$filename = "data/dvd.db.txt";
&#125;
else if($cat = 2)&#123;
$filename = "data/avi.db.txt";
&#125;
else if($cat = 3)&#123;
$filename = "data/vcd.db.txt";
&#125;
else if($cat = 4)&#123;
$filename = "data/svcd.db.txt";
&#125;
$author = htmlspecialchars(trim(stripslashes($author)));
$title = htmlspecialchars(trim(stripslashes($title)));
$url = htmlspecialchars(trim(stripslashes($url)));
$date = date('d M Y');

$guideurl = "<a href='$url' target='_blank'>View</a>";

// Build db string
$news = $title."|".$guideurl."|".$tools."|".$date."|".$author."\n" ;

$data = fopen($filename, "a");
fwrite($data, $news);
fclose($data);

header("location: $HTTP_REFERER ");

?>
Thanks for the reply :)

Posted: Mon Mar 22, 2004 4:37 am
by patrikG
And what is the problem?

Posted: Mon Mar 22, 2004 4:39 am
by koola
The problem is that it doesn't post into the selected db.
I don't know why it doesn't, could it be my code?

Posted: Mon Mar 22, 2004 4:44 am
by patrikG
Put

Code: Select all

echo "<h4>CAT</h4><pre>";print_r($_POST["cat"]);echo"</pre>";
at the top of your post.php page and post the results here.

Posted: Mon Mar 22, 2004 4:51 am
by koola
Posting with DVD gives:

Code: Select all

CAT
1
Posting with AVI:

Code: Select all

CAT
2
Posting with VCD:

Code: Select all

CAT
3
Posting with SVCD:

Code: Select all

CAT
4
It looks like the chosen value is being passed, but the code is not selecting the correct db :( No idea why?

Posted: Mon Mar 22, 2004 4:55 am
by patrikG
Isn't it? You're writing the SQL string to a file - have you looked at the contents of that file?

Posted: Mon Mar 22, 2004 5:04 am
by koola
Nope :(

I'm putting the data into a text file db, but not the one I selected.
I've looked in all of the files, but all the data is being put into 'dvd.db.txt' and not the chosen one.

Any ideas as I am real stuck with this one?

Posted: Mon Mar 22, 2004 5:11 am
by patrikG
Try

Code: Select all

$data = fopen($filename, "a+");

Posted: Mon Mar 22, 2004 5:20 am
by koola
I carn't belive it! :evil:

It still doesn't insert the data into the correct db.

Posted: Mon Mar 22, 2004 5:21 am
by patrikG
Check the directory permissions, start chmodding them to 0777 and see if that helps.

Posted: Mon Mar 22, 2004 5:28 am
by koola
Yep, they are all chmodded at 777 but it is still not selecting the correct db?

Posted: Mon Mar 22, 2004 5:33 am
by patrikG
echo $title before or after you write to the file.

Posted: Mon Mar 22, 2004 5:40 am
by koola
Ok, I echoed them all, this what was displayed:

Author: koola
Title: test
Tools: test
URL: Http://test.com
Cat: 1

PHP code:

Code: Select all

<?php
echo "Author: $author<br>";
echo "Title: $title<br>";
echo "Tools: $tools<br>";
echo "URL: $url<br>";
echo "Cat: $cat<br>";
?>