0

I have the following code which is meant to cycle through names submitted on a form:

$row_count = count($_POST['name']);
if ($row_count > 0) {

  mysql_select_db($database, $connection);
  $name = array();
  $workshop = array();

  for($i = 0; $i < $row_count; $i++) {
    // variable sanitation...
    $name[i] = mysql_real_escape_string(ucwords($_POST['name'][$i]));
    $workshop[i] = mysql_real_escape_string($_POST['workshop'][$i]);
    }
  $names = "('".implode("','",$name)."')";
.....etc

For some reason $names is only returning the last name submitted on the form, rather than all of the names. Could someone help me get this working correctly?

Thanks,

Nick

0

1 Answer 1

6

problem is here

$name[i] = 
$workshop[i] = 

solution:

$name[$i] = 
$workshop[$i] = 

now your code is working in this way:

$name["i"] = 
$workshop["i"] = 

so you have only one element in $name, $workshop arrays. (last from loop)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.