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ї'author'];
$title = $_POSTї'title'];
$tools = $_POSTї'tools'];
$url = $_POSTї'url'];
$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";
}
$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:
Posting with AVI:
Posting with VCD:
Posting with SVCD:
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
Posted: Mon Mar 22, 2004 5:20 am
by koola
I carn't belive it!
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>";
?>