For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > August 2004 > problem for inserting forms text values









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author problem for inserting forms text values
kindermaxiz@yahoo.com

2004-08-27, 3:56 am

hey all:
I do a loop that creates text forms on the fly kinda like this:

for (i,i<=$x,i++)(
echo "<input type=text name=$forname> <br>"
$values .= "$forname,"

)

echo "<input form type=submit name="submit">"

then

if ($submit)
//to get rid of the last comma:
$myvalues= str_replace($values,-1)
//i use a function to get the $namesofcolumns but im in a netcafe
right now so...
mysql_query(insert into blabla ($namesofcolumns) values ($myvalues);

the problem is that the insert works but only null values get
inserted, how can I do that?

thanx in advance
kingofkolt

2004-08-27, 3:56 am

<kindermaxiz@yahoo.com> wrote in message
news:39615087.0408261928.346ace59@posting.google.com...
> hey all:
> I do a loop that creates text forms on the fly kinda like this:
>
> for (i,i<=$x,i++)(
> echo "<input type=text name=$forname> <br>"
> $values .= "$forname,"
>
> )
>
> echo "<input form type=submit name="submit">"
>
> then
>
> if ($submit)
> //to get rid of the last comma:
> $myvalues= str_replace($values,-1)
> //i use a function to get the $namesofcolumns but im in a netcafe
> right now so...
> mysql_query(insert into blabla ($namesofcolumns) values ($myvalues);
>
> the problem is that the insert works but only null values get
> inserted, how can I do that?
>
> thanx in advance


I didn't see enough of your code to know for sure that this is the case, but
I'm guessing you're working on the assumption that register_globals in
php.ini is set to On. The best policy to go by is to use $_POST['somevar']
instead of $somevar, as that will be more reliable. For example, your line
"if ($submit)" should be "if ($_POST['submit'])". Or actually, "if
(isset($_POST['submit']))" for good measure...

- JP


kindermaxiz@yahoo.com

2004-08-28, 3:55 am

ok this is my code, when I try to insert the values I get 1,2,3,4 etc
instead of what is entered in the form, can u tell me where is my
mistake please and how to solve the whole thing pease?

gracias


if ($material_to_be_added==$j)
{
$resultprod = $sqlquery ("describe $tabname");
echo "<form method=\"post\" action=$php_self>";
while($row = $sqlfetcharray($resultprod)) {
$col_name = $row['Field'];
$null_value = $row['Null'];
$translated_colname = 'translation_'.$col_name ;
$dispayed_colname = ${$translated_colname};

if ($col_name=='id' || $null_value=='YES')
echo "";
else {echo "<br>$dispayed_colname:<BR><INPUT TYPE=\"TEXT\"
NAME=\"$k\" SIZE=\"40\">";
$col_to_insert .= "$col_name,";
$cols_to_insert = substr_replace($col_to_insert,'',-1);
$val_to_insert .= "$k,";
$vals_to_insert = substr_replace($val_to_insert,'',-1);
$k = $k +1;
}
}
echo "<p><input type=\"submit\" name=\"submit\" value=\"$submit\">
</form><p> $cols_to_insert <p> $vals_to_insert";
if ($submit) {
$result=$sqlquery("INSERT INTO $tabname($cols_to_insert)".
"VALUES ($vals_to_insert)");
}
}


"kingofkolt" <jessepNOSPAM@comcast.net> wrote in message news:<ppyXc.322092$%_6.188275@attbi_s01>...
> <kindermaxiz@yahoo.com> wrote in message
> news:39615087.0408261928.346ace59@posting.google.com...
>
> I didn't see enough of your code to know for sure that this is the case, but
> I'm guessing you're working on the assumption that register_globals in
> php.ini is set to On. The best policy to go by is to use $_POST['somevar']
> instead of $somevar, as that will be more reliable. For example, your line
> "if ($submit)" should be "if ($_POST['submit'])". Or actually, "if
> (isset($_POST['submit']))" for good measure...
>
> - JP

Ken Robinson

2004-08-28, 3:55 am


kindermaxiz@yahoo.com wrote (in part):
> hey all:
> I do a loop that creates text forms on the fly kinda like this:
>
> for (i,i<=$x,i++)(
> echo "<input type=text name=$forname> <br>"
> $values .= "$forname,"
>
> )
>
> echo "<input form type=submit name="submit">"
>
> then
>


Well...

Your code is screwed up...

<?
for ($i;$i<$x;$++)
echo '<input type=text name=forname[] value="'. $forname .
'">'."<br>\n";
echo '<input type=submit name="submit">'."<br>\n";
?>

Then

<?
if (isset($_POST['submit'])){
$query = "insert into table values (". implode(',',$_POST['forname'])
.. ")";
?>

My code my not be perfect, but it's closer than yours.

Ken

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com