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";
}
?>
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 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'm building a sort of blog system, but I'm having trouble with editing an existing 'post' in the system. It is collecting the data from the database, and it displays it. But when I click the update button, I get this error. I've looked for it, checked my code couple of times, but I just couldn't find anything. This is the error.
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
And this is my code.
<?php //include config
require_once('../../includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php'); }
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bewerk</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<link rel="stylesheet" href="../style/normalize.css">
<link rel="stylesheet" href="../style/main.css">
<link rel="stylesheet" href="../style/login.css">
</head>
<body>
<?php
//check for any errors
if(isset($error)){
foreach($error as $error){
echo $error.'<br />';
}
}
try {
$stmt = $db->prepare('SELECT patient_id, voornaam, achternaam, leeftijd, lengte, gewicht, foto_url FROM patienten WHERE patient_id = :patient_id') ;
$stmt->execute(array(':patient_id' => $_GET['id']));
$row = $stmt->fetch();
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
<?php
//if form has been submitted process it
if(isset($_POST['submit'])){
$_POST = array_map( 'stripslashes', $_POST );
//collect form data
extract($_POST);
if(!isset($error)){
try {
//insert into database
$stmt = $db->prepare('UPDATE patiënten SET patient_id, voornaam = :voornaam, achternaam = :achternaam, leeftijd = :leeftijd, lengte = :lengte, gewicht = :gewicht, foto_url = :foto_url WHERE patient_id = :patient_id') ;
$stmt->execute(array(
':patient_id' => $patient_id,
':voornaam' => $voornaam,
':achternaam' => $achternaam,
':leeftijd' => $leeftijd,
':lengte' => $lengte,
':gewicht' => $gewicht,
':foto_url' => $foto_url
));
//redirect to index page
header('Location: index.php?action=updated');
exit;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>
<div class="row">
<div class="col-md-2 col-md-offset-5">
<img src="../style/images/logo.png">
</div>
</div>
<div class="keuze_link row">
<p><b><?php echo $row['voornaam'];?> <?php echo $row['achternaam'];?></b> bewerken</p>
</div>
<div class="container">
<form class="toevoegen" action="" method="post">
<input type="text" name="voornaam" value="<?php echo $row['voornaam'];?>">
<br>
<input type="text" name="achternaam" value="<?php echo $row['achternaam'];?>">
<br>
<input type="text" name="leeftijd" value="<?php echo $row['leeftijd'];?>">
<br>
<input type="text" name="lengte" value="<?php echo $row['lengte'];? >">
<br>
<input type="text" name="gewicht" value="<?php echo $row['gewicht'];?>">
<br>
<input type="text" name="foto_url" value="<?php echo $row['foto_url'];?>">
<br>
<input class="button" type="submit" name="submit" value="Updaten!">
</form>
</div>
</body>
</html>
If you guys wanna know more, or see more code, I'd like to hear it. Thanks in advance.
EDIT. for update.
//insert into database
$stmt = $db->prepare('UPDATE patienten SET patient_id = :patient_id, voornaam = :voornaam, achternaam = :achternaam, leeftijd = :leeftijd, lengte = :lengte, gewicht = :gewicht, foto_url = :foto_url WHERE patient_id = :patient_id') ;
$stmt->execute(array(
'patient_id' => $patient_id,
':voornaam' => $voornaam,
':achternaam' => $achternaam,
':leeftijd' => $leeftijd,
':lengte' => $lengte,
':gewicht' => $gewicht,
':foto_url' => $foto_url
));
Latest form for update
<form class="toevoegen" action="" method="post">
<input type="hidden" name="voornaam" value="<?php echo $row['patient_id'];?>">
<input type="text" name="voornaam" value="<?php echo $row['voornaam'];?>">
<br>
<input type="text" name="achternaam" value="<?php echo $row['achternaam'];?>">
<br>
<input type="text" name="leeftijd" value="<?php echo $row['leeftijd'];?>">
<br>
<input type="text" name="lengte" value="<?php echo $row['lengte'];?>">
<br>
<input type="text" name="gewicht" value="<?php echo $row['gewicht'];?>">
<br>
<input type="text" name="foto_url" value="<?php echo $row['foto_url'];?>">
<br>
<input class="button" type="submit" name="submit" value="Updaten!">
</form>
:patient_id is missing from the $stmt->execute() function. Please add it and try again.
In your update query you forgot about :patient_id to bind
And yes, remove $ before column names.
I'm trying to create a PHP script to connect an HTML form to a MySQL database, and everything is working except there is one input that cannot be null, and no matter what I do, the system doesn't seem to recognize when I enter text into the field, and I have no idea what I'm doing wrong.
Here's my PHP code:
if (empty($_POST['book_name']))
{$errors[ ] = 'You forgot to enter the book name.';
}
else {
$booktitle = trim($_POST['book_name']);
}
if (empty($_POST['author']))
{$errors[ ] = 'You forgot to enter the author.';
}
else {
$author = trim($_POST['author']);
}
if (empty($_POST['cover']))
{$errors[ ] = 'You forgot to enter the book cover image.';
}
else {
$cover = trim($_POST['cover']);
}
if (empty($_POST['publisher']))
{$errors[ ] = 'You forgot to enter the publisher.';
}
else {
$publisher = trim($_POST['publisher']);
}
if (empty($_POST['language_id']))
{$errors[ ] = 'You forgot to enter the book language.';
}
else {
$languageid = trim($_POST['language_id']);
}
if (empty($_POST['length_pages']))
{$errors[ ] = 'You forgot to enter the book length in pages.';
}
else {
$lengthpages = trim($_POST['length_pages']);
}
if (empty($_POST['fiction']))
{$errors[ ] = 'You forgot to enter if the book is fiction or not.';
}
else {
$fiction = trim($_POST['fiction']);
}
if (empty($_POST['pub_year']))
{$errors[ ] = 'You forgot to enter the year the book was published.';}
else {
$pubyear = trim($_POST['pub_year']);
}
if (empty($errors)) {
require ('mysqli_connect.php');
}
$q = "INSERT INTO books(book_name, author, publisher, language_id, length_pages, cover, fiction, pub_year) VALUES
('$booktitle', '$author', '$publisher', '$languageid', '$lengthpages', '$cover', '$fiction', '$pubyear')";
$r = #mysqli_query($dbc, $q);
if ($r) {
echo 'Thank you! This book information has been entered into the database.';
}
else {
echo 'System error.';
echo mysqli_error($dbc) . ' Query: ' . $q;
foreach ($errors as $msg) {
echo " - $msg<br>\n";
}
}
?>
and here's my HTML code:
<form action="register.php" method="post">
<p>Book name: <input type="text" name="book_name" size="20" maxlength="100" value="<?php if (isset($_POST['book_name'])) echo $_POST['book_name']; ?>" /></p>
<p>Author: <input type="text" name="author" size="20" maxlength="100" value="<?php if (isset($_POST['author'])) echo $_POST['author']; ?>" /></p>
<p>Publisher: <input type="text" name="publisher" size="20" maxlength="100" value="<?php if (isset($_POST['publisher'])) echo $_POST['publisher']; ?>" /></p>
<p>Language:</p>
<p>English <input type="radio" name="language_id" value="1" /></p>
<p>Spanish <input type="radio" name="language_id" value="2" /></p>
<p>French <input type="radio" name="language_id" value="3" /></p>
<p>Italian <input type="radio" name="language_id" value="4" /></p>
<p>Mandarin <input type="radio" name="language_id" value="5" /></p>
<p>Number of pages: <input type="text" name="length_pages" size="20" maxlength="100" value="<?php if (isset($_POST['length_pages'])) echo $_POST['length_pages']; ?>" /></p>
<p>Cover image file name: <input type="text" name="cover" size="20" maxlength="100" value="<?php if (isset($_POST['cover'])) echo $_POST['cover']; ?>" /></p>
<p>Is this book fiction?:</p>
<p>Yes <input type="radio" name="fiction" value="yes" /></p>
<p>No <input type="radio" name="fiction" value="no" /></p>
<p>Year Published: <input type="text" name="pub_year" size="20" maxlength="100" value="<?php if (isset($_POST['pub_year'])) echo $_POST['pub_year']; ?>" /></p>
<input type="submit" name="submit" value="submit" /></form>
And for whatever reason, every time I try to test it out, I get this error message:
"System error. Query: INSERT INTO books(book_name, author, publisher, language_id, length_pages, cover, fiction, pub_year) VALUES ('', 'Not Hayley Munguia', 'Random House', '2', '134', 'howtobenormal.jpg', 'no', '1938') - You forgot to enter the book name."
even though I'm definitely inputting something into the book name field.
I really have no idea what I'm doing wrong, all help is appreciated! Thank you!
First check taking the sentences the mysql and put directly in the phpmyadmin and see the errors. Second I can see is likely the var book_name is empty