I have some problems
Notice: Array to string conversion in x\contact_ajouter_verif.php on line 17
This is my form :
<form action="contact_ajouter_verif.php" method="post" name="ajoutContact" enctype="multipart/form-data" >
<fieldset>
<label>Nom :</label> <input size="30%" type="text" placeholder="" name="nom" />
<label>Numéro :</label> <input size="30%" type="number" placeholder="" name="num" />
<label>Image au format png :</label><input type="file" name="img" />
</fieldset>
<input name="submit" type="submit" value="Ajouter"/>
</form>
And this is my pdo receiver page:
<?php
include('../inc/connexion.inc.php');
include('session.php');
$nom = $_POST['nom'];
$num = $_POST['num'];
$img = $_FILES['img'];
$pseudo = $user_check. "_contact";
$rqt1= "INSERT INTO $pseudo(CTC_NOM, CTC_NUMERO, CTC_IMG) VALUES(:nom, :num, :img)";
$result1 =$cnxpdo->prepare($rqt1);
$result1->execute(array(
'nom' => "$nom",
'num' => "$num",
'img' => "$img" //line 17
));
?>
I really don't understand what I'm doing wrong, please if someone have the solution :)
Finally found for those in the same case than me (unlikely but we never know...) :
<?php
include('../inc/connexion.inc.php');
include('session.php');
$nom = $_POST['nom'];
$num = $_POST['num'];
$img =addslashes(file_get_contents ($_FILES['img']['tmp_name']));
$pseudo = $user_check. "_contact";
$rqt1= "INSERT INTO $pseudo(CTC_NOM, CTC_NUMERO, CTC_IMG) VALUES(:nom, :num, :img)";
$result1 =$cnxpdo->prepare($rqt1);
$result1->execute(array(
'nom' => "$nom",
'num' => "$num",
'img' => "$img"
));
?>
Thanx for your help.
Related
I have some problems
Notice: Array to string conversion in x\contact_ajouter_verif.php on line 17
This is my form :
<form action="contact_ajouter_verif.php" method="post" name="ajoutContact" enctype="multipart/form-data" >
<fieldset>
<label>Nom :</label> <input size="30%" type="text" placeholder="" name="nom" />
<label>Numéro :</label> <input size="30%" type="number" placeholder="" name="num" />
<label>Image au format png :</label><input type="file" name="img" />
</fieldset>
<input name="submit" type="submit" value="Ajouter"/>
</form>
And this is my pdo receiver page:
<?php
include('../inc/connexion.inc.php');
include('session.php');
$nom = $_POST['nom'];
$num = $_POST['num'];
$img = $_FILES['img'];
$pseudo = $user_check. "_contact";
$rqt1= "INSERT INTO $pseudo(CTC_NOM, CTC_NUMERO, CTC_IMG) VALUES(:nom, :num, :img)";
$result1 =$cnxpdo->prepare($rqt1);
$result1->execute(array(
'nom' => "$nom",
'num' => "$num",
'img' => "$img" //line 17
));
?>
I really don't understand what I'm doing wrong, please if someone have the solution :)
Finally found for those in the same case than me (unlikely but we never know...) :
<?php
include('../inc/connexion.inc.php');
include('session.php');
$nom = $_POST['nom'];
$num = $_POST['num'];
$img =addslashes(file_get_contents ($_FILES['img']['tmp_name']));
$pseudo = $user_check. "_contact";
$rqt1= "INSERT INTO $pseudo(CTC_NOM, CTC_NUMERO, CTC_IMG) VALUES(:nom, :num, :img)";
$result1 =$cnxpdo->prepare($rqt1);
$result1->execute(array(
'nom' => "$nom",
'num' => "$num",
'img' => "$img"
));
?>
Thanx for your help.
I was trying to push with a single form using the $_POST method multiple times the same form (with different values) until the array index is 4 (or a number I decide).
So with this html form i want to press submit, push the values into array, then refresh page, reinsert different values and so on until the condition is true.
<?php
if (!isset($count)) {
$person = array(
array(
'name' => '',
'surname' => '',
'phoneNumber' => ''
)
);
}
var_dump($person);
if (!isset($_POST['submit'])) {
echo "<form action=\"index.php\" method=\"post\">
<label for=\"name\">Name</label>
<input type=\"text\" name=\"name\" required>
<br>
<label for=\"surname\">Surname</label>
<input type=\"text\" name=\"surname\" required>
<br>
<label for=\"phoneNumber\">Phone Number</label>
<input type=\"text\" name=\"phoneNumber\" required>
<br>
<input type=\"submit\" value=\"Submit\" name=\"submit\">
</form>";
$count = 0;
} else {
$name = $_POST['name'];
$surname = $_POST['surname'];
$phoneNumber = $_POST['phoneNumber'];
if (count($person) <= 2) {
array_push($person, $name, $surname, $phoneNumber);
//echo "<meta http-equiv=\"refresh\" content=\"0\">";
//echo "Sto inserendo persone";
//echo count($persone);
echo count($person);
//var_dump($persone);
//print_r($persone);
} else {
var_dump($person);
};
}
?>
I was thinking about using $_SESSION but I don't have an idea about how to use it.
I don't want to use AJAX or jQuery or Javascript only pure PHP.
The example below shows always the form and your actual persons array. If you submit the form, your data will add to the array until it counts more than three entries. I think that is what you are looking for:
<?php
session_start();
if (!isset($_SESSION['persons'])) {
$_SESSION['persons'] = [];
}
if(isset($_POST['submit'])) {
if (count($_SESSION['persons']) <= 2) {
$_SESSION['persons'][] = array(
'name' => $_POST['name'],
'surname' => $_POST['surname'],
'phoneNumber' => $_POST['phoneNumber']
);
}
}
?>
<pre><?php var_dump($_SESSION['persons']); ?></pre>
<form action="index.php" method="post">
<label for="name">Name</label>
<input type="text" name="name" required><br>
<label for="surname">Surname</label>
<input type="text" name="surname" required><br>
<label for="phoneNumber">Phone Number</label>
<input type="text" name="phoneNumber" required><br>
<input type="submit" value="Submit" name="submit">
</form>
With the following line of code you can clear you array if you need to:
$_SESSION['persons'] = [];
I'm having trouble with posting values typed into textarea. everything else works well, any idea how to make it work?
HTML:
<form id="formData2" action="artistuploader.php" method="post"
enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000"></input>
<br/>
<input id="inputField" type="text" name="actname" placeholder="Act Name" >
<br>
<input id="inputField" type="text" name="fullname" placeholder="Full Name" >
<br>
<input id="inputField" type="text" name="genre" placeholder="Genre" >
<br>
<textarea id="inputField" name="biography" form="formData2" placeholder="Biography"<?php echo $biography; ?>></textarea>
<br>
<input id="inputField" type="file" name="artistImage" placeholder="Artwork" >
<br>
<input id="inputField" type="text" name="imagepath" placeholder="Image path URL" >
<br>
<input id="submitButton" type="submit" name="uploadArtist" value="Register Artist">
</form>
PHP
<?php
$msg = "";
//if Upload button is pressed
if (isset($_POST['uploadArtist'])){
$target = "uploads/artistPics".basename($_FILES['artistImage']['name']);
//connecting to our database
$db = mysqli_connect("127.0.0.1", "user", "pass", "tablename");
$tmp_name = $_FILES['artistImage']['tmp_name'];
$name = $_FILES['artistImage']['name'];
//getting the submitted form data
$ActName = $_POST['actname'];
$FullName = $_POST['fullname'];
$Genre = $_POST['genre'];
$ArtistPhoto = $_FILES['artistImage']['name'];
$imageURLpath = $_POST['imagepath'];
$Biography = $_POST['biography'];//having problem with this line here
//saving submitted data into database table songsDB
$sql = "INSERT INTO artistsdb (ActName,FullName,Genre,ArtistPhoto,Biography,imageURLpath) VALUES ('$ActName','$FullName','$Genre','$ArtistPhoto','$Biography','$imageURLpath')";
mysqli_query($db, $sql); //stores the submitted data into table
//now moving the uploaded image to uploads folder
if(move_uploaded_file($_FILES['artistImage']['tmp_name'], $target)){
$msg = "Uploaded Successful";
}else{
$msg = "There was a problem uploading Data";
}
}
//header("refresh:1; url=index.php"); ?>
Replace your textarea with
<textarea id="inputField" name="biography" form="formData2" placeholder="Biography"><?php echo $biography; ?></textarea>
I am creating a form to insert images into a slider, with a maximum of 10 slides. When inserting the images i need the option of being able to choose maybe just 2,3 or 4 slides for example. But when i try to inset less than the 10 image, it does not insert into the database.
Here is what i have thus far;
try {
//$max_size = 2097152; This is to do, not part of question
$allowed = array('jpg', 'jpeg', 'png');
$img_1 = $_FILES['slider_1']['name'];
$extn = strtolower(end(explode('.', $img_1)));
$temp = $_FILES['slider_1']['tmp_name'];
if(in_array($extn, $allowed) === true) {
$slider_1 = 'data/' . md5(time().uniqid()) . '.' . $extn;
move_uploaded_file($temp, $slider_1);
}
//This works upto this point
$insert = DB::getInstance()->insert('slider', array(
'main' => $main,
'slider_1' => $slider_1,
'slider_2' => $slider_2,
'slider_3' => $slider_3,
'slider_4' => $slider_4,
'slider_5' => $slider_5,
'slider_6' => $slider_6,
'slider_7' => $slider_7,
'slider_8' => $slider_8,
'slider_9' => $slider_9,
'slider_10' => $slider_10
));
Session::flash('success', '<p class="success">Inserted successfully</p>');
Redirect::to('test.php');
} catch(Exception $e) {
die($e->getMessage());
}
Here is my insert function
public function insert($table, $fields = array()) {
$keys = array_keys($fields);
$values = null;
$x = 1;
foreach($fields as $value) {
$values .= "?";
if($x < count($fields)) {
$values .= ', ';
}
$x++;
}
$sql = "INSERT INTO {$table} (`" . implode('`, `', $keys) . "`) VALUES ({$values})";
if(!$this->query($sql, $fields)->error()) {
return true;
}
return false;
}
And here is my form
<form id="contact-form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" autocomplete="off">
<label for="main"><span class="required">*</span> Main Image:</label>
<input type="file" name="main">
<label for="img_set_1"><span class="required">*</span> Image Set 1:</label>
<input type="file" name="slider_1">
<label for="img_set_2"><span class="required">*</span> Image Set 2:</label>
<input type="file" name="slider_2">
<label for="img_set_3"><span class="required">*</span> Image Set 3:</label>
<input type="file" name="slider_3">
<label for="img_set_4"><span class="required">*</span> Image Set 4:</label>
<input type="file" name="slider_4">
<label for="img_set_5"><span class="required">*</span> Image Set 5:</label>
<input type="file" name="slider_5">
<label for="img_set_6"><span class="required">*</span> Image Set 6:</label>
<input type="file" name="slider_6">
<label for="img_set_7"><span class="required">*</span> Image Set 7:</label>
<input type="file" name="slider_7">
<label for="img_set_8"><span class="required">*</span> Image Set 8:</label>
<input type="file" name="slider_8">
<label for="img_set_9"><span class="required">*</span> Image Set 9:</label>
<input type="file" name="slider_9">
<label for="img_set_10"><span class="required">*</span> Image Set 10:</label>
<input type="file" name="slider_10">
<button type="submit">SUBMIT</button>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</form>
Thanks in advance
I want to create insert database a web service from :
http://www.discorganized.com/php/a-complete-nusoap-and-flex-example-part-1-the-nusoap-server/
Here's my script :
<?php
require_once 'lib/nusoap.php';
$client= new nusoap_client("http://127.0.0.1/test2/index.php", false);
$in_contact=array ('first_name'=>$_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'phone_number' => $_POST['phone_number'],);
$result = $client->call('insertContact', $in_contact);
if ($result){
echo "OK";
} else {
echo "Error";
}
?>
despite increasing ID, why the other columns remain empty ?
please help me, thank you.
The <form> code..
< form action="Contact.class.php" method="GET" > Nama Depan:<br> <input type="text" name="first_name"/><br> Nama Belakang:<br> <input type="text" name="last_name"/><br> Email:<br> <input type="text" name="email"/><br> Telepon:<br> <input type="text" name="phone_number"/><br><br> <input type="submit" value="Submit"/><br> < /form >
As you can see the method is GET , Change that to POST
Like this...
<form action="Contact.class.php" method="POST" >
The fixed <form> code.. You had a lot of indentations gone wrong..
<form action="Contact.class.php" method="POST" >
Nama Depan:<br> <input type="text" name="first_name"/><br>
Nama Belakang:<br> <input type="text" name="last_name"/><br>
Email:<br> <input type="text" name="email"/><br>
Telepon:<br> <input type="text" name="phone_number"/><br><br>
<input type="submit" value="Submit"/><br> </form>
<?php
require_once 'lib/nusoap.php';
$client= new nusoap_client("http://127.0.0.1/test2/index.php", false);
$in_contact=array ('first_name'=>$_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'phone_number' => $_POST['phone_number'],);
$result = $client->call('insertContact', array($in_contact));
if ($result){
echo "OK";
} else {
echo "Error";
}
?>