0

Hello I am yousing form to insert new values into query.
Error which i got is:Array to string conversion.
What should I change to not get this error?

Thank you

if( isset($_POST["new_log"]) ){

//mysql_real_escape_string - ochrana proti mysql injection

$name       = $_POST["name"];
$surname    = $_POST["surname"];
$password   = $_POST["password"];
$email      = $_POST["email"];
$salary     = $_POST["salary"];
$msaving    = $_POST["msaving"];
$mfixpayment = $_POST["mfixpayment"];
$lastupdate = $_POST["lastupdate"];
$bio        = $_POST["bio"];
$money      = $_POST["money"];

$new_log=" INSERT INTO login SET `name`='$name', `surname`='$surname', `password`='$password', `email`='$email', `salary`='$salary', `msaving`='$msaving', `mfixpayment`='$mfixpayment', `lastupdate`='$lastupdate', `bio`='$bio', `money`='$money' ";

mysql_query( $new_log ) or die( mysql_error() );

}

here I am inserting new values by form

    echo ' <form method="post"> ';  
    echo ' meno:                <input type="text" name="name['. $row_log["id"] .']" >  <br />';
    echo ' priezvisko:          <input type="text" name="surname['. $row_log["id"] .']">  <br />';
    echo ' heslo:               <input type="text" name="password['. $row_log["id"] .']">  <br />';
    echo ' e-mail:              <input type="text" name="email['. $row_log["id"] .']">  <br />';
    echo ' vyplata:             <input type="number" name="salary['. $row_log["id"] .']">  <br />';
    echo ' chcem mesačne ušetriť <input type="number" name="msaving['. $row_log["id"] .']">  <br />';
    echo ' platím každý mesiac: <input type="number" name="mfixpayment['. $row_log["id"] .']">  <br />';
    echo ' posledná mena:       <input type="date" name="lastupdate['. $row_log["id"] .']">  <br />';
    echo ' niečo o sebe:        <input type="text" name="bio['. $row_log["id"] .']">  <br />';
    echo ' mám na účte:         <input type="number" name="money['. $row_log["id"] .']">  <br />';
    echo "<br />";

    echo '<input type="submit" name="new_log" value="Pridať nového užívateľa" >';
    echo '</form>';
1
  • 4
    All of your $_POST values are arrays. That's what name="name['. $row_log["id"] .']" does. Commented Aug 11, 2014 at 18:02

1 Answer 1

2
$name       = $_POST["name"];

should be

$name       = $_POST["name"][$id];

Alternatively, output this:

<input type="text" name="name" >

instead of

<input type="text" name="name['. $row_log["id"] .']" >
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.