PDA

View Full Version : Problem with Dreamweaver Trying to get A Dynamic Data...



Rockonmetal
07-08-2007, 08:56 PM
Answer is on page 3... posted by myself...

Rockonmetal
07-08-2007, 08:56 PM
Give me a minute, Bravenet doesn't like me... i'll put it on freewebs...

thetestingsite
07-08-2007, 09:08 PM
The connection name would be the name you give for your MySQL database connection. Your database server (beings that you installed WAMP5) would be "localhost" (without the quotes). The username and password by default is "root" (again, no quotes) with no password. The database will be the database that you have set up using either the MySQL command line tools or using PHPMyAdmin (which I believe comes preinstalled with WAMP5).

Hope this helps.

//EDIT (after reading what's below the last image in your post): Not sure how you would do it in Dreamweaver, but if you were to make your own php script to write to files, you may want to look through these pages for any understanding on how to do so:

http://www.php.net/fopen
http://www.php.net/fwrite
http://www.php.net/file_get_contents
http://www.php.net/fclose
(and so on...)

Rockonmetal
07-08-2007, 09:08 PM
Ok the images are up... anyone willing to help me out here, let me know...

Thanks to all

ok i'll try that...

What should go in connection name?
Edit:
I just installed WAMP5 Onto my computer and I haven't found how to name my server or change the username and password...

Ok I think I might just have a way to bypass the who binding thing...

I'll put up the code i have

Rockonmetal
07-08-2007, 09:19 PM
<?php
$filename = 'data.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

Theres the code... it wrote it into the document data.txt
Ok, now how do I get that to write the entire form into the document?

thetestingsite
07-08-2007, 09:23 PM
You would need to put the code you posted into a php document, and to write the contents of the form to the file, you will need to request the content like so:



<?php
$filename = 'data.txt';

$formfield = $_POST['field1'];

/* The above can be $_POST, $_GET, or $_REQUEST depending on the way you
are submitting the form. field1 (inside the $_POST array) is the name of the field
in which you are requesting the data from. the variable $formfield is just a variable. */

$somecontent = "This is a test. $formfield \r\n";



// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>


Hope this helps.

Rockonmetal
07-08-2007, 09:30 PM
So Field1 Is set as the Form name or the inputs?

thetestingsite
07-08-2007, 09:35 PM
It would be the field in the form that you want the data from. Example:

The form:


<form action="test.php" method="POST">
<input type="text" name="testField">
<input type="submit" value="Go">
</form>


The PHP script:


<?php

$var = $_POST['testField'];

echo $var; //echos whatever was typed into the text field named testField
?>


Hope this helps.

//EDIT: Also, the fields need to be spelled the exact same in both the form and the php script for it to work properly.

Rockonmetal
07-08-2007, 09:43 PM
Sweet Thanks alot! one question though. Can I do this?

$var = $_POST['testField' , 'testField2'];?? Or do I have to put in entirely different code for that.

thetestingsite
07-08-2007, 09:48 PM
You would have to call the field in individual statements like so:



<?php

$name = $_POST['name'];
$email = $_POST['email'];



or simply call the field like so if you are just going to use it once in the script:



<?php

echo $_POST['name'] . " <br> " . $_POST['email'];

//will display something like Name <br> Email in the source code.
?>


Hope this helps.

Rockonmetal
07-08-2007, 09:58 PM
Ok I think this is the last thing... I tried the $email thing and it looks like its gonna work. heres the problem though.


// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}


I changed that to this

// Write $somecontent to our opened file.
if (fwrite($handle, $name, $email, $VideoTitle, $Description) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

Is that correct it doesnt appear so, because when I tried it it didn't roll.

thetestingsite
07-08-2007, 10:02 PM
You have to place the variables in the variable $somecontent (or any other variable that you want as long as it gets passed to the fwrite function). Have a look at the following:



<?php
$filename = 'data.txt';

$name = $_POST['name'];
$email = $_POST['email'];
$VideoTitle = $_POST['VideoTitle'];
$Description = $_POST['Description'];

$somecontent = <<<HERE
------------------------
$name
$email
$VideoTitle
$Description
------------------------

HERE;

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.

if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>


Hope this helps.

Rockonmetal
07-08-2007, 10:07 PM
It does help a little but i get this instead:
Success, wrote ( '' , '' , '' , '' ,) to file (data.txt)

here is the somecontent code i put in:

$somecontent = " '$name' , '$email' , '$VideoTitle' , '$Description' ,";

Edit:
If it helps i also tried with out the apostrophees ' those things...

thetestingsite
07-08-2007, 10:21 PM
Are your form field names "name", "email", "VideoTitle", and "Description"? Also, make sure you are passing the form via POST method.

Rockonmetal
07-08-2007, 10:22 PM
<?php
$filename = 'data.txt';

$name = $_POST['name'];
$email = $_POST['email'];
$VideoTitle = $_POST['VideoTitle'];
$Description = $_POST['Description'];

$somecontent = " '$name' , '$email' , '$VideoTitle' , '$Description' ,"; //THIS PART!
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.

if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>
I will also confirm that my form is using post and all the names are what they are

Rockonmetal
07-08-2007, 10:44 PM
What should I put in for the php code?

thetestingsite
07-08-2007, 10:48 PM
The php script you posted above is fine, just make sure that the form fields have the same names as those that you are calling in this part of the php script:



$name = $_POST['name'];
$email = $_POST['email'];
$VideoTitle = $_POST['VideoTitle'];
$Description = $_POST['Description'];

Rockonmetal
07-08-2007, 11:02 PM
Ok it still isn't working. here is the code i have for both the form and the status page.

<html>
<head>
<script src="SpryAssets/SpryEffects.js" type="text/javascript"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
Original: ArjoGod, Shauna Merritt -->
<!-- Modified By: Ronnie T. Moore, Editor -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
extArray = new Array(".mov", ".mpg", ".mpeg", ".avi", ".swf", ".wmv");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
}
// En
function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
//-->
</script>
<style type="text/css">
html, body, table{
font-family: Tahoma;
font-size: 12px;
color: FFFFFF;
overflow: auto;
scrollbar-face-color: #4e4e4e;
scrollbar-base-color:#444444;
scrollbar-arrow-color: #FFFFFF;
scrollbar-track-color:#444444;
scrollbar-shadow-color:#5e5e5e;
scrollbar-highlight-color:#5e5e5e;
scrollbar-3dlight-color:#444444;
scrollbar-darkshadow-Color:#444444;
}
a:link{
color: FFFFFF;
font-family: Trebuchet Ms;
text-decoration: none;
font-weight: bold;
}
a:hover{
font-family: Trebuchet Ms;
color: 666666;
text-decoration: none;
font-weight: bold;
}

.form{
font-family: Trebuchet Ms;
border-width: 2px;
border-style: solid;
border-color: 4e4e4e;
width: 468px;
height: 400px;
color: FFFFFF;
overflow: none;
scrollbar-face-color: #4e4e4e;
scrollbar-base-color:#444444;
scrollbar-arrow-color: #FFFFFF;
scrollbar-track-color:#444444;
scrollbar-shadow-color:#5e5e5e;
scrollbar-highlight-color:#5e5e5e;
scrollbar-3dlight-color:#444444;
scrollbar-darkshadow-Color:#444444;
}
.input{
width: 180px;
background-color: #5e5e5e;
border-width: 1px;
border-color: #770000;
border-style: solid;
color: #C3C3C3;
font-family: Trebuchet Ms;
font-size: 10px;
}
.smallinput{
width: 90px;
background-color: #5e5e5e;
border-width: 1px;
border-color: #770000;
border-style: solid;
color: #C3C3C3;
font-family: Trebuchet Ms;
font-size: 10px;
}
.form textarea{
width: 275px;
height: 150px;
overflow: auto;
}
.button{
background: url(button.png);
height: 20px;
width: 100px;
border-width: 1px;
border-style: solid;
border-color: #555555;
color: FFFFFF;
font-family: Trebuchet Ms;
font-weight: bold;
}
/*.threepxfix class below:
Targets IE6- ONLY. Adds 3 pixel indent for multi-line form contents.
to account for 3 pixel bug: http://www.positioniseverything.net/explorer/threepxtest.html
*/



* html .threepxfix{
margin-left: 3px;
}

#modernbricksmenu{
padding: 0;
width: 100%;
background: transparent;
voice-family: "\"}\"";
voice-family: inherit;
}

#modernbricksmenu ul{
font: bold 11px Trebuchet Ms;
margin:0;
margin-left: 55px; /*margin between first menu item and left browser edge*/
padding: 0;
list-style: none;
}

#modernbricksmenu li{
display: inline;
margin: 0 2px 0 0;
padding: 0;
text-transform:uppercase;
}

#modernbricksmenu a{
float: left;
display: block;
color: white;
margin: 0 1px 0 0; /*Margin between each menu item*/
padding: 5px 10px;
text-decoration: none;
letter-spacing: 1px;
background-color: #444444 ;
border-bottom: 1px solid #444444;
}

#modernbricksmenu a:hover{
background-color: #770000; /*Menu hover bgcolor*/
border-bottom: 1px solid #770000;
}

#modernbricksmenu #current a{ /*currently selected tab*/
background-color: #D25A0B; /*Brown color theme*/
border-color: #D25A0B; /*Brown color theme*/
}

#modernbricksmenuline{
clear: both;
padding: 0;
width: 100%;
height: 5px;
line-height: 5px;
background: #770000; /*Brown color theme*/
}


</style>



</head>
<body bgcolor="444444" >
<center>

<table width="468" align="center">
<tr>
<td><img src="banner.png" border="0"></td></tr>
<tr>
<td colspan="2">
<div id="modernbricksmenu">
<ul>
<li>
<a href="Index.html">Index</a></li>
<li>
<a href="Videos.html">Videos</a></li>
<li>
<a href="Submit.html">Submit Video</a></li>
<li>
<a href="forum.htm">PureADD Forum</a></li>
</ul>
</div>

<div id="modernbricksmenuline">&nbsp;</div></td>
</tr>
<tr>
<td width="468" valign="top"><table width="400" border="1" align="center" bordercolor="#4e4e4e">
<tr><form action="status.php" method="post" enctype="text/plain" >
<th width="127" align="right" valign="middle" scope="col"><label>Your Name:</label></th>
<th width="257" align="left" valign="top" scope="col">

<input name="name" type="text" class="input" id="name" maxlength="30">
</th>
</tr>
<tr>
<th align="right" valign="middle" scope="col">Your Email Address:</th>
<th align="left" scope="col"><label>
<input name="email" type="text" class="input" id="email" maxlength="100">
</label></th>
</tr>
<tr>
<th align="right" valign="middle" scope="col">Your Video's Title:</th>
<th align="left" scope="col"><input name="VideoTitle" type="text" class="input" id="VideoTitle" maxlength="20"></th>
</tr>
<tr>
<th align="right" valign="top" scope="col">Video Description:</th>
<th align="left" scope="col"><label>
<textarea name="textarea" cols="45" rows="5" class="input" name="Description" id="Description"></textarea>
</label></th>
</tr>
<tr>
<th align="right" valign="top" scope="col">Our Rules:</th>
<th align="left" valign="top" scope="col"><p>You must read these rules that we have put up to stop spammers and other mean people who like to put up bad videos

which are filled with bad stuff.<br>
<br>
</p></th>
</tr>
<tr>
<th align="center" valign="top" scope="col" colspan="2">
<input name="Submit" type="submit" class="button" id="Submit" value="Submit">
<Br>
</th>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2">
<center><sup>.:: PureADD Videos 2007&copy :: Designed by PureADD ::.</sup></center>
<div id="modernbricksmenuline">&nbsp;</div></td>
</table>

</body>
</html>
thats the submition page submition.php
here is the status page status.php

<?php
$filename = 'data.txt';

$name = $_POST['name'];
$email = $_POST['email'];
$VideoTitle = $_POST['VideoTitle'];
$Description = $_POST['Description'];

$somecontent = " '$name' , '$email' , '$VideoTitle' , '$Description' ,"; //THIS PART!
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.

if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

I really hope thats not right

alexjewell
07-08-2007, 11:37 PM
Those single quotes are bothering me...



$somecontent = " '".$name."' , '".$email."' , '".$VideoTitle."' , '".$Description."' ,"; //THIS PART!

Rockonmetal
07-09-2007, 01:31 AM
ok so I entered it and I still don't have any difference other than " , " , " ,

Rockonmetal
07-09-2007, 01:32 AM
<?php
$filename = 'data.txt';

$name = $_POST['name'];
$email = $_POST['email'];
$VideoTitle = $_POST['VideoTitle'];
$Description = $_POST['Description'];

$somecontent = " '".$name."' , '".$email."' , '".$VideoTitle."' , '".$Description."' ,";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.

if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

Thats what I have now

Rockonmetal
07-09-2007, 04:19 PM
I still haven't gotten this, if someone could just tell me what to put... then I would be fine.

Rockonmetal
07-14-2007, 10:29 PM
OK i got it to work... its really quite neat!

ok so on the HTML Page *or the form page* u put this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

Name
<form method="POST" action="data.php" name="">
Your Name:<input type="text" name="text" value="text" />
Your Name:<input type="text" name="text2" value="text" />
Your Name:<input type="text" name="text3" value="text" />
Your Name:<input type="text" name="text4" value="text" />

<input type="submit" />
</form>

</body>
</html>

Edit it to your standards
Then put this into the Data.php page:

<?php
$var = $_POST["text"];
$var2 = $_POST["text2"];
$var3 = $_POST["text3"];
$var4 = $_POST["text4"];
echo "Please Fill Out The Form Below"
?>
<?php
$filename = 'data.txt';
$somecontent = "
<br />Your Name: $var
<br />Your EmailAddress: $var2
<br />Your Password: $var3
<br />Your Password: $var4
<br />End of Form";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file";
exit;
}

echo "Success, your content to the database)";

fclose($handle);

} else {
echo "The file is not writable";
}
?>

Thats what worked for me! Thanks