PHP & MySQL database storing the name Array problem.
Posted
by comma
on Stack Overflow
See other posts from Stack Overflow
or by comma
Published on 2010-04-24T06:32:42Z
Indexed on
2010/04/24
6:33 UTC
Read the original article
Hit count: 166
I'm new to PHP & MySQL and I keep getting the word Array stored in my MySQL tables fields $skill
, $experience
, $years
I was wondering how can I fix this problem?
And I know I need to add mysqli_real_escape_string
which I left out to make code more easier to read Hopefully.
Here is the PHP & MySQL code.
if (isset($_POST['info_submitted'])) {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT learned_skills.*, users_skills.*
FROM learned_skills
INNER JOIN users_skills ON learned_skills.id = users_skills.skill_id
WHERE user_id='$user_id'");
if (!$dbc) {
print mysqli_error($mysqli);
return;
}
$user_id = '5';
$skill = $_POST['skill'];
$experience = $_POST['experience'];
$years = $_POST['years'];
if (isset($_POST['skill'][0]) && trim($_POST['skill'][0])!=='') {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT learned_skills.*, users_skills.* FROM learned_skills INNER JOIN users_skills ON users_skills.skill_id = learned_skills.id WHERE users_skills.user_id='$user_id'");
if (mysqli_num_rows($dbc) == 0) {
for ($s = 0; $s < count($skill); $s++){
for ($x = 0; $x < count($experience); $x++){
for ($g = 0; $g < count($years); $g++){
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$query1 = mysqli_query($mysqli,"INSERT INTO learned_skills (skill, experience, years)
VALUES ('" . $s . "', '" . $x . "', '" . $g . "')");
$id = mysqli_insert_id($mysqli);
if ($query1 == TRUE) {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$query2 = mysqli_query($mysqli,"INSERT INTO users_skills (skill_id, user_id)
VALUES ('$id', '$user_id')");
}
}
}
}
}
}
}
Here is the XHTML code.
<li><label for="skill">Skill: </label><input type="text" name="skill[0]" id="skill[0]" />
<label for="experience">Experience: </label>
<?php
echo '<select id="experience[0]" name="experience[0]">' . "\n";
foreach($experience_options as $option) {
if ($option == $experience) {
echo '<option value="' . $option . '" selected="selected">' . $option . '</option>' . "\n";
} else {
echo '<option value="'. $option . '">' . $option . '</option>'."\n";
}
}
echo '</select>';
?>
<label for="years">Years: </label>
<?php
echo '<select id="years[0]" name="years[0]">' . "\n";
foreach($grade_options as $option) {
if ($option == $years) {
echo '<option value="' . $option . '" selected="selected">' . $option . '</option>' . "\n";
} else {
echo '<option value="'. $option . '">' . $option . '</option>'."\n";
}
}
echo '</select>';
?>
</li>
© Stack Overflow or respective owner