php - SQL Insert won't insert on all fields -
i have php generating html form , i'm trying write script update information in database. reason works on of fields , not others.
code won't work:
php-form users can change details within
echo"<form name='details'>"; echo"<p>surname: <input type='text'id='surname' value='".$row['surname']."'/></p>; <p>telephone: <input type='text'id='phone' value='".$row['telephone']."'/></p>; <p>postcode: <input type='text' id='postcode' value='".$row['postcode']."'/></p>; <p>house/flat number: <input type='text' id='number' value='".$row['number']."'/></p>"; ajax - sends changes server via querystring
var sname = document.getelementbyid('surname').value; var tel = document.getelementbyid('phone').value; var num = document.getelementbyid('number').value; var pcode = document.getelementbyid('postcode').value; var querystring = "?username=" + username +"&email="+email...."; ajaxrequest.open("get", "url" + querystring, true); ajaxrequest.send(null); php - execute update command
//connect server ... //get variables $sname = $_get['sname']; $pcode = $_get['pcode']; $tel = $_get['tel']; $num=$_get['num']; //process update $update ="update user set surname='$sname',telephone='$tel',number='$num', postcode='$pcode' username='$username'"; //if query, display success if(mysqli_query($update)) { echo"success"; } else { echo"error"; } //else display error the query executes fine, values aren't displaying within database. other variables (username, password etc) update fine. database fields type varchar(80).
edit: have query being executed. still results in surname, postcode, number , telephone field not being updated.
ignoring moment other issues code , approach (sql injection issues, vs. post issue, etc.), , dealing update not changing things expected, there couple of things check.
try outputing update query in logs , make sure looks expecting. values you're meaning push across wire not making query or that.
verify running query hand in standalone sql client (mysql, squirrel, etc...) updates record. it's entirely possible valid update query may not match records. (say username value you're looking not match 1 that's in database.
not knowing infrastructure, i'd suggest sanity checks: pointing @ right database? have update wrapped in transaction that's rolling back? etc ...
a few other tips:
i suggest looking @ pdo, in particular how prepared statements work. kind of query you're building above run off data or worse. while not panacea, prepared statements solid first step.
take @ jquery's ajax functions. in particular post method. provides simple interface making ajax calls without having construct special url strings. plus, switching post avoid data showing in webserver logs files.
Comments
Post a Comment