PDA

View Full Version : passing variable through a form field


Paul Ferrie
09-01-2004, 06:35 PM
Hi guys, I am trying to pass a variable in a form to the next page when the submit button is pressed.


<form enctype="multipart/form-data" method="post" action='addImage2.php?newsId=$newsId'>
<div align="left">
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
<table border="0" width="95%">
<tr>
<td width="9%"><font color='#cccccc' size = 2 >Picture file upload:</font><br>
<input name="userfile" type="file" id="userfile" size="50"> </td>
</tr>
<tr>
<td width="9%">
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</div>
</form>


For some reason addImage2.php is not recieving the variable.
The variable is there and is populated but not being passed:(
Anyone

Cheers

freddycodes
09-02-2004, 06:39 AM
Yeah it doesn't quite work this like. HTML cannot parse php, and since you are using post, you should be using a hidden input.



<form enctype="multipart/form-data" method="post" action='addImage2.php'>
<div align="left">
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
<table border="0" width="95%">
<tr>
<td width="9%"><font color='#cccccc' size = 2 >Picture file upload:</font><br>
<input name="userfile" type="file" id="userfile" size="50"> </td>
</tr>
<tr>
<td width="9%">
<input type="hidden" name="newsId" value="<?php print $newsId; ?>">
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</div>
</form>

Paul Ferrie
09-02-2004, 02:08 PM
Cheers m8,
PHP 'N' FLASH ARE MY STRONGER POINTS. NOT SO MUCH WITH PHP 'N' HTML

#cheers

Paul Ferrie
09-02-2004, 03:05 PM
Yup that worked
cheers.

Run into another problem now :(
the image is being uploaded but the database is not being set with the new image url.

Here's the script to upload the file:

<?

// Include config file
include('connection.php');
// If userfile holds the image location then upload the image
// if(!empty($_FILES['userfile']['tmp_name'])) {
$name = strtolower(eregi_replace('#| |\?|!', '',$_FILES['userfile']['name']));
$destination = '../img/'.$name;
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $destination)) {
$pict='../img/'.$name;
$query = "UPDATE newsArchive SET pict = $pict WHERE newsId = $newsId";
}
// If query failed...
if (!$query) {
// Inform of an error and quit
fail("Couldn't set image");
}
print "New picture has been has been added to row. Please complete the rest of the fields.newsId=$newsId";
// Header("Location: main.php?success=New picture has been has been added to row. Please complete the rest of the fields.&newsId=$newsId");

// }
?>



Cheers for any help

Paul

freddycodes
09-02-2004, 05:02 PM
Yeah you have to run the query, setting a string variable with the sql statement does nothing more than that.


<?
$query = mysql_query("UPDATE newsArchive SET pict = $pict WHERE newsId = $newsId");
?>

Paul Ferrie
09-05-2004, 08:45 AM
i forgot to add my link function to the top of the php page
:(
$link=dbconnect();

Thanks for your help

freddycodes
09-05-2004, 05:28 PM
-']i forgot to add my link function to the top of the php page
:(
$link=dbconnect();

Thanks for your help


That still wouldn't have fixed your code, since you never ran the query. But thanks for trying to appease my petty egotistical needs. ;)