jquery - Inserting inputted data and session ID into database -
i seem having lot of problem question if help me out i'd appreciate it.
i'm learning programming @ moment (early stages maintain in mind) , i'm making mini application myself teach me different things. have html file creates form user can add together in deal name , deal description databases
the text entered 2 textbox's in form captured , create json object via javascript function
the javascript function read on php file created take json object , write given values database so:
<?php $var1 = $_request['action']; // dont need action tutorial, in complex code need way determine ajax action nature $jsonobject = json_decode($_request['outputjson']); // decode json object readable php object $name = $jsonobject->{'name'}; // name object $desc = $jsonobject->{'desc'}; // desc object mysql_connect("localhost","root",""); // conect mysql, first parameter location, sec mysql username , 3rd 1 mysql password @mysql_select_db("findadeal") or die( "unable select database"); // connect database called test $query = "insert deal (dname, description, restaurantid) values ('$name' ,'$desc' '$username') $username=(select restaurantid restaurant username = '$username')"; $result=mysql_query($query); $num = mysql_numrows($result); if($num != 0) { echo "true"; } else { echo "false"; } ?> this problem lying. html file can add together deal part of larger project im creating. user have logged in , session has been created - know works mini php statement have inserted top of html files echos "it works" meaning user logged in , details still in array:
<?php if( !isset( $_session ) ){ session_start(); echo "whats happening"; } if( isset( $_session['username'] ) ){ /* user logged in */ echo "it works!"; } ?> what cant , need help this:
when deal info beingness inserted database, fields beingness inserted in include:
dealid autoimplemented dont need that dname deal name of user inserted info form description 1 time again user inserted info form restaurantid id of logged in userwhat can't figure out find out how restaurantid session variable , include in mysql statement.
the sql statement in php file below wrong i'm aware trying piece myself see if create sort of logic problem.
in plain english language im trying username beingness stored in session variable , create sql statement go:
insert deals table name, description , restaurantid restaurantid restaurant tabel , can gotten finding username session variable same username within restaurant table.from i'd able commit deal beingness inserted have gotten restaurant id other table!
i hope makes sense, i've been @ ages , had no avail! if shown me i'd able move onto lots of other areas such amending , deleting etc it's need getting session piece figured out first. massive in advance help!!!
without using real code, trying understand you:
$db = new pdo("mysql:host=".dbhost.";dbname=".dbname, dbuser, dbpass); $sql = 'select restaurantid restaurant username=:username'; $statement = $db->prepare($sql); $statement->bindparam(':username', $_session['username'], pdo::param_str); $statement->execute(); $result = $statement->fetch(pdo::fetch_assoc); if(!empty($result)) { // here restaurant id, can utilize insert statement... $rid = $result['restaurantid']; } jquery mysql session php
No comments:
Post a Comment