Hey guys.. going crazy over this :'(

This is my form

echo "<form action='addwebsitekeywordsscript.php' method='post'>";
echo "<input type='hidden' value='" . $currentwebsite . "' name='id' /><br />";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[]' class='kywrd1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>חיפושים:</div> <input type='text' name='keywordSearch[]' class='kywrdsrc1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>שפה:</div> <select class='kywrdlang'>  <option value='he'>עברית</option>  <option value='en'>אנגלית</option></select></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[]' class='kywrd1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>חיפושים:</div> <input type='text' name='keywordSearch[]' class='kywrdsrc1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>שפה:</div> <select class='kywrdlang'>  <option value='he' >עברית</option>  <option value='en'>אנגלית</option></select></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[]' class='kywrd1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>חיפושים:</div> <input type='text' name='keywordSearch[]' class='kywrdsrc1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>שפה:</div> <select class='kywrdlang'>  <option value='he'>עברית</option>  <option value='en'>אנגלית</option></select></div>";
echo "<br style='clear: both' />";
echo "<input type='submit' class='sendbutton' value='הגש טופס' />";
echo "</form>";

This is the Mysql Insert code

mysql_select_db("seorgani_maincldb", $con);
mysql_query("SET NAMES 'UTF-8'");
$sql="INSERT INTO KeywordList (id, keyword, keywordSearch, keywordlanguage)
VALUES
('$_POST[id]','$_POST[keyword]','$_POST[keywordSearch]','$_POST[keywordlanguage]')";

if (!mysql_query($sql,$con))
  {
  die('שגיאה: ' . mysql_error());
  }

I need to enter multiple VALUES meaning take the first set of value into the the 1 raw
then the second raw and so on..

I know it wont work this way but have looked for a way to do that
across the web and couldn't find it or i don't know what i am looking for

Any help would be greatly appreciated :idea:

You have to provide indexes to the array variables in your form, and on the receiving side you have to walk through the arrays which those indexes constitute.
For example:

echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[1]' class='kywrd1' /></div>";

...

for ($i = 0; $i < MAXINDEX; $i++) {
$sql=sprintf("INSERT INTO KeywordList (id, keyword, keywordSearch, keywordlanguage) 
VALUES ('%s','%s','%s','%s')", 
  $_POST[id][$i],
  $_POST[keyword][$i],
  $_POST[keywordSeararch][$i],
  $_POST[keywordlanguage][$i]
  )
)";
  mysql($sql);
}

Thanks a lot man!! gona try it now

What if some field is left empty.. any way to integrate into this
script a value check ?

ALSO (again.. thanks for your help)

How do i treat a select feautre in the PHP
meaning how do i use the ID??

What if some field is left empty.. any way to integrate into this
script a value check ?

Google for "PHP input validation" as well as for "SQL injection". You will have to check against malicious input. An empty field is just an empty string in the associated $_POST variable.

How do i treat a select feautre in the PHP
meaning how do i use the ID??

The "name" attribute of the select tag is the name of the $_POST variable; the selected option is its value. If the option tag has an explicit "value" attribute, this will be the value of the post variable.

First i want to thank you again for your help
i know it takes time so 10x a lot

i tried this code and it doeset output any error
But doeset insert any values into the database..

FORM:

echo "<form action='addwebsitekeywordsscript.php' method='post'>";
echo "<input type='hidden' value='" . $currentwebsite . "' name='id' /><br />";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[1]' name='keyword[1]' class='kywrd1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>חיפושים:</div> <input type='text' name='keywordSearch[1]' class='kywrdsrc1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>שפה:</div> <select class='kywrdlang'>  <option value='he' name='keywordlanguage[1]'>עברית</option>  <option value='en' name='keywordlanguage[1]'>אנגלית</option></select></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[2]' class='kywrd1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>חיפושים:</div> <input type='text' name='keywordSearch[2]' class='kywrdsrc1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>שפה:</div> <select class='kywrdlang'>  <option value='he' name='keywordlanguage[1]'>עברית</option>  <option value='en' name='keywordlanguage[1]'>אנגלית</option></select></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>מילת מפתח:</div> <input type='text' name='keyword[3]' class='kywrd1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>חיפושים:</div> <input type='text' name='keywordSearch[3]' class='kywrdsrc1' /></div>";
echo "<div class='kywrdformcontnr'><div class='kywrdform'>שפה:</div> <select class='kywrdlang'>  <option value='he' name='keywordlanguage[1]'>עברית</option>  <option value='en' name='keywordlanguage[1]'>אנגלית</option></select></div>";
echo "<br style='clear: both' />";
echo "<input type='submit' class='sendbutton' value='הגש טופס' />";
echo "</form>";

SCRIPT:

mysql_select_db("seorgani_maincldb", $con);
mysql_query("SET NAMES 'UTF-8'");

for ($i = 0; $i < MAXINDEX; $i++) {
$sql=sprintf("INSERT INTO KeywordList (keyword, keywordSearch, keywordlanguage) 
VALUES ('%s','%s','%s')", 
  $_POST[keyword][$i],
  $_POST[keywordSeararch][$i],
  $_POST[keywordlanguage][$i]
);
if (!mysql_query($sql,$con))
  {
  die('שגיאה: ' . mysql_error());
  }

}

See Anything wrong ?

If you use foreign code, first try to understand what it is doing.
Define MAXINDEX in both your scripts. Put it in an include file so that all your scripts use the same value.
Create your input fields in a loop, running from 0 to MAXINDEX - 1. This would avoid the error of using keywordlanguage[1] more than once, too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.