Sending content from my frontend to my PHP/MySQL-backend -


when send content frontend reaches if (!empty)-statement table in phpmyadmin/mysql-database not recieve information , not add it.

i have 2 tables. 1 varchar (text) named "photo" , id called "id" a_i.

with current code send (well attempt send) text "photo" nothing id a_i? maybe need add addiotional code , might issue here , reason database not seem add content send?

<?php    $value = json_decode(file_get_contents('php://input'));   $mysql_pekare= new mysqli ("", "","", "");     if(!empty($value)) {        echo "you reached if-statement";       $stmt = $mysql_pekare->prepare("insert photoalbum(`photo`) values(?)");        $stmt->bind_param("s", $value['photo']);        $stmt->execute();        $stmt->close();        $mysql_pekare->close();    }  ?> 

in frontend when send content recieve in log:

{"photo":"test"} 

and recieve in log, echo call did if reaches if function does:

"you reached if-statement" 

by default, json_decode() returns object, value in $value->photo.

so insert code should -

if(!empty($value)) {    echo "you reached if-statement";   $stmt = $mysql_pekare->prepare("insert photoalbum(`photo`) values(?)");    $stmt->bind_param("s", $value->photo);    $stmt->execute();    $stmt->close();    $mysql_pekare->close(); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -