Reputation: 53
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>';
Upvotes: 0
Views: 164
Reputation: 17014
$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"] .']" >
Upvotes: 2