Note that there are some explanatory texts on larger screens.

plurals
  1. POEditing tables in SQL database with PHP
    primarykey
    data
    text
    <p>Ok it's been about 5 hours since I've worked on this bit &amp; I just can't get it to work. I've looked everywhere but my codes just seem to be...unique. Anyway I'm trying to change entries in a particular table in my SQL database. The name of the table is userdb. I've got 5 text boxes, name, username, password, email, and ID. Where ID would be the primary key needed for the query to look for the entry I'm looking for and the remaining 4 text boxes are filled with new entries that I'd like to have.</p> <p>Here's the contents of my main PHP file called admin.php, this one's in the head tag:</p> <pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { $(".test4").click(function() { var id = $("#txUserid").val(); $.post("updateUser.php", { id: id }, function(data) { alert(data); }); }); }); </code></pre> <p></p> <p>this one in the body:</p> <pre><code> &lt;font color="white"&gt;Name&lt;/font&gt;&lt;input class="test1" type="text" id="txNm" value="" onkeyup="nospaces(this)"&gt; &lt;font color="white"&gt;Username&lt;/font&gt;&lt;input class="test1" type="text" id="txUsn" value="" onkeyup="nospaces(this)"&gt; &lt;font color="white"&gt;Password&lt;/font&gt;&lt;input class="test1" type="password" id="txPwd" value="" onkeyup="nospaces(this)"&gt; &lt;font color="white"&gt;E-Mail&lt;/font&gt;&lt;input class="test1" type="text" id="txEml" value="" onkeyup="nospaces(this)"&gt; &lt;font color="white"&gt;Updater - ID, only affected by the Delete &amp; Update button.&lt;/font&gt;&lt;input class="test1" type="text" id="txUserid" value="" onkeyup="nospaces(this)"&gt; &lt;input class="test4" name="Submit" type="submit" value="" id="submit"/&gt; </code></pre> <p>This one's my updateUser function which is stored in 'mshop2.script.js':</p> <pre><code>function updateUser(){ var name = $('#txNm').val(); var username = $('#txUsn').val(); var password = $('#txPwd').val(); var email = $('#txEml').val(); var id = $('#txUserid').val(); var finalData = { nm: name, usn: username, pwd: password, eml: email, uid: userid }; $.post('updateUser.php', finalData, function(resp){ if(resp == 'success'){ alert('User successfully modified.'); getUserList(); } }); } </code></pre> <p>this one's my updateUser.php file:</p> <pre><code>&lt;?php include 'config.php'; $nm = mysql_real_escape_string($_POST["nm"]); $usn = mysql_real_escape_string($_POST["usn"]); $pwd = mysql_real_escape_string($_POST["pwd"]); $eml = mysql_real_escape_string($_POST["eml"]); $id = mysql_real_escape_string($_POST["id"]); $sql = "SELECT ID FROM userdb WHERE ID='$id'"; $result = mysql_query($sql); if(mysql_num_rows($result) &gt;0) { //found $q = "UPDATE userdb SET `name` = '$nm', `username` = '$usn', `password` = '$pwd', `email` = '$eml' WHERE ID ='$uid'"; } else { //not found die('Error: The ID does not exist.' . mysql_error()); echo mysql_error(); } $result = mysql_query($q); if(empty($_POST['nm'])) { die('You need to enter a value for the Name field'); } if(empty($_POST['usn'])) { die('You need to enter a value for the Name field'); } if(empty($_POST['pwd'])) { die('You need to enter a value for the Name field'); } if(empty($_POST['eml'])) { die('You need to enter a value for the Name field'); } if(empty($_POST['uid'])) { die('You need to enter a value for the Name field'); } if(empty($_POST['id'])) { die('You need to enter a value for the Name field'); } if(!mysql_query($q, $con)){ die('Error: ' . mysql_error()); echo mysql_error(); }else{ echo 'success'; } mysql_close($con); ?&gt; </code></pre> <p>I can't figure out what's been causing it not to work, the intended entry I'd like to entry, say, if I entered '50' in the ID textbox. The ID will stay the same but the rest of the fields are empty. What did I do wrong this time?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload