Monday 15 February 2010

php - Random Queries Failing with MySql -



php - Random Queries Failing with MySql -

i hope question not broad not specific piece of code. @ random times , on random queries have failures in code. of time seems on insert calls. update , delete still work fine, insert fail across entire page several hours @ time before mysteriously working again. page beingness used , tested myself currently.

one of sample queries. php

session_start(); $poster = $_session['login_user']; $conn = new pdo("mysql:host=localhost;dbname=spectrum",'root', '1234abcd'); $u = $_post['user']; $p = md5($_post['pass']); $e = $_post['email']; $fn = $_post['first_name']; $ln = $_post['last_name']; $t = $_post['type']; $sql = "insert users(id, user, pass, email, type, first_name, last_name, poster) values ('', :user, :pass, :email, :type, :first, :last, :poster)"; $q = $conn->prepare($sql); $q->bindparam(":user", $u); $q->bindparam(":email", $e); $q->bindparam(":pass", $p); $q->bindparam(":type", $t); $q->bindparam(":first", $fn); $q->bindparam(":last", $ln); $q->bindparam(":poster", $poster); $q->execute(); echo json_encode('user has been added.');

this done through ajax call. jquery

var request; if (request) { request.abort(); } var $form = f; var $inputs = $form.find("input, select, button, textarea"); var serializeddata = $form.serialize(); $inputs.prop("disabled", true); request = $.ajax({ url: site + "/backend/formup.inc.php", type: "post", datatype: 'json', data: serializeddata }); request.done(function (data){ if(data.location){ window.location.replace(data.location); } else{ alert(data); location.reload(false); } }); request.fail(function (jqxhr, textstatus, errorthrown){ alert( "the next error occured: "+ textstatus, errorthrown ); }); request.always(function (data) { if(!data.tvar){ $inputs.prop("disabled", false); } });

here html.

<form class="hidden" method="post"> <input type="text" name="user" placeholder="username" required/> <input type="email" name="email" placeholder="email" required/> <input type="password" name="pass" placeholder="password" required/> <input type="text" name="first_name" placeholder="first name" required/> <input type="text" name="last_name" placeholder="last name" required/> <input type="radio" name="type" value="0">owner <input type="radio" name="type" value="1">employee <input type="radio" name="type" value="2">artist <input type="radio" name="type" value="3">venue <input type="radio" name="type" value="4">fan<br /> <input type="hidden" name="fname" value="add_user" /> <input type="submit" class="button" value="add" /> </form>

also apologize if formatting may off questions. first time posting , getting used site.

php jquery mysql

No comments:

Post a Comment