28, May 2012

Parameter Passing, Generating Code, and Storing the user input from the new code - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Parameter Passing, Generating Code, and Storing the user input from the new code
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: Parameter Passing, Generating Code, and Storing the user input from the new code  (Read 911 times)
Google dot what?
*
Posts: 2
16 credits
Members referred : 0


« on: Mar 02, 2007, 03:56:56 pm »

Hello, I am trying to create a user interface to connect to a MySql database. The problem is when the user input their data the values aren't stored or passed. Also is there a better way to generate html code from the user input. Please run the code so you can see what I am talking about.

Thanks in advance

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This file ask the user for the database name, table name and how many fields, then it calls itself back and it creates the fields and allow the user to put in the input. Now I think the problem is here when the user put the data in, its not storing it and then when they click "submit me1!" button it doesn't pass it to the 2n.php file.

Code:
<?php
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
   
$dn $_POST[dname];
   
$tn $_POST[tname];
   
$fa$_POST[famount];
   
$i 1;   
while (
$i $fa+)
{

echo "Field $i: <input type=\"text\" name=\"$content\">"
echo "DataType: <input type=\"text\" name=\"$dtype\"><br>";
$arrayc[$i-1] = $content;
$arrayd[$i-1] = $dtype;
$i++;
}

?>

<form action="2n.php" method="post">
<input type="submit" name="submit" value="submit me1!" />
   </form>
<?php

}else{
?>

<html>
<body>
<form action="1n.php" method="post">
Database Name: <input type="text" name="dname" />
New Table Name: <input type="text" name="tname" />
How many field(s): <input type="value" name="famount" />
<input type="hidden" name="action" value="submitted" />
   <input type="submit" name="submit" value="submit me!" />
   </form>
</body>
</html>
<?php
}
?>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


This echos the variables from the above file to see if they were passed.

Code:
<?php
$dname1
=$_POST[$dn];
$tname1=$_POST[$tn];
$famount1=$_POST[$fa];
$carray=$_POST[$arrayc];
$darray=$_POST[$arrayd];

//to see if the info was pass from file to file
echo $dname1;
echo 
$tname1;
echo 
$famount1;
for(
$i=0$i<$famount1$i++)
{
echo 
$carray[$i];
echo 
$darray[$i];
}
/*
//open up connection
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
  //create database
  if (mysql_query("CREATE DATABASE $dname1",$con))
  {
  echo "Database name $dname1 created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
  
  //create table and fields
  mysql_select_db($dname1, $con);
$sql = "CREATE TABLE $tname1
(
a int

)";
mysql_query($sql,$con);
mysql_close($con);
*/
?>

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Mar 02, 2007, 04:14:14 pm »

In order to pass the variables to the second script you should use <input>

eg.

echo '<input type="hidden" name="dname" value="' .  $dname '" />
?>

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Mar 02, 2007, 04:35:03 pm »

I'm not 100% sure but I think its also not OK to post array's from form to form, you need to serialize them first or you convert them them into the post array...(to be sure check the php manual about "serialize/unserialize")


Google dot what?
*
Posts: 2
16 credits
Members referred : 0


Re: Parameter Passing, Generating Code, and Storing the user input from the new
« Reply #3 on: Mar 02, 2007, 07:48:10 pm »

Thanks everyone for your help. Forgive for my ignorance, but I am a novice at this PHP game.

Nikolas, I tried using your code, but didn't know where to place it. where ever I did place it, it didn't work.


I also tried these hidden fields(maroon color), but it just returned me to my original script without the input fields:
Code:
}else{
?>

<html>
<body>

<form action="1n.php" method="post">

Database Name: <input type="text" name="dname" />
[color=Maroon]<input type="hidden" name="dname" value="' .  $dname . '" />[/color]
New Table Name: <input type="text" name="tname" />
[color=Maroon]<input type="hidden" name="tname" value="' .  $tname . '" />[/color]
How many field(s): <input type="value" name="famount" />
[color=Maroon]<input type="hidden" name="famount" value="' .  $famount . '" />[/color]

<input type="hidden" name="action" value="submitted" />
   <input type="submit" name="submit" value="submit me!" />
   </form>
</body>
</html>


<?php


Please tell me where to place the code


________________________________________________________________________________________________________________________________________________________________
Olaf, serializing (I don't even know what that means) that's a little bit too advance for me right now, I am a beginner, that will be my last resort. I do appreciate the help and if you can provide a quick example of how to "serialize an array" that would be helpful (and also explain what it is).
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Mar 02, 2007, 10:03:34 pm »

Code:
I am a beginner,...

you should start reading the book Wink, you're asking for examples? all functions inside the PHP manual have some

Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6138
Tags : paramater passing generate code dynamic storing user input Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Parameter Passing, Generating Code, and Storing the user input from the new code
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 06:43:39 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.