PDA

View Full Version : Downloadable file... Variables not working


NeoMoon
04-20-2008, 04:20 PM
NOTE: Wasn't sure if this was supposed to go in HTML or PHP.

Okay, I'm sure I did something wrong with this (The onClick part):

<html>
<head>
<title>Project Zaro - Object Creation</title>
<?php include("stylesheets.php"); ?>
</head>
<body>
<!-- START DIV DECLARING -->
<?php include("divs.php"); ?>
<!-- END DIV DECLARING -->
<div id="content-c">
<font color="CCCCCC">
<!-- Content -->
<center>
<form action="testFile.sql" method="get">
<p>Object Name: <input type="text" maxlength="100" name="name"></p>

<p>Entry ID: <input type="text" maxlength="6" name="entry"></p>

<p>Type: <select name="type">
<option value="regular">Regular</option>
<option value="chair">Chair</option>
</select></p>

<p>Display ID: <input type="text" maxlength="6" name="display"></p>

<p>Spell ID: <input type="text" maxlength="6" name="spell"></p>

<p>Sound ID: <input type="text" maxlength="6" name="sound"></p>

<p><input type="submit"
onClick="<?php
$myFile='testFile.sql';
$fh = fopen($myFile, 'w');

$name = $_GET['name'];
$entry = $_GET['entry'];
$type = $_GET['type'];
$display = $_GET['display'];
$spell = $_GET['spell'];
$sound = $_GET['sound'];

fwrite($fh, 'INSERT INTO gameobject_names (entry, Type, DisplayID, Name, spellfocus, sound1) VALUES (' . $entry . ', ' . $type . ', ' . display . ', \'' . name . '\', ' . spell . ', ' . sound . ');');
?>"
value="Make that Object!">

</center>
<!-- End Content -->
</font>
</div>
</body>
</html>


What it's supposed to do is write to testFile.sql and then prompt the user to download it.

But instead, this is what I get in the testFile.sql:
INSERT INTO gameobject_names (entry, Type, DisplayID, Name, spellfocus, sound1) VALUES (, , display, 'name', spell, sound);

All help appreciated! Thanks!

http://neo-moon.com/object.php

Iszak
04-20-2008, 04:26 PM
Edit: because you're redirecting to the page before you write to the file maybe? because not only 'entry' isn't there but also anything you add from your link isn't in the file so maybe use the form action to the same page and then use PHP to redirect the user to a the file but before that save the information in it.

NeoMoon
04-20-2008, 04:31 PM
Maybe cause someone didn't enter the 'entry' so maybe do checks to make sure they did.Well I am not worried about if all the forms are filled out right now...

The only problem I really want fixed right now is why it won't create the file with the correct variables.

The file has the same information in it each time it is downloaded.