kicken Posted October 8, 2012 Share Posted October 8, 2012 However, the comma before WHERE will cause that error. That is your immediate error problem. Remove the extra comma. But I dont know how to turn 'test' into the actually id number of the member. Don't you already have the ID number in $_POST['form_id'], which you've saved to the variable $id? Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1383833 Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2012 Share Posted October 8, 2012 Read the posts in this thread. The information you need is there, but you continue to plead ignorance in hopes someone will rewrite your code for you. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1383841 Share on other sites More sharing options...
justlukeyou Posted October 9, 2012 Author Share Posted October 9, 2012 Many thanks Kicken, which comma is it please. I know its a dumb question but whatever I try just creates an error. Pikachu2000 I genuinely wish I understood what people saying because I would have resolved this issue days ago. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1383887 Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2012 Share Posted October 9, 2012 The answer has been given to you repeatedly. Read the posts again. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1383939 Share on other sites More sharing options...
justlukeyou Posted October 10, 2012 Author Share Posted October 10, 2012 When I use the vardump as below: var_dump($_SESSION) ; If get this code: array(1) { ["userID"]=> string(3) "test" } I take it this is competely wrong. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384271 Share on other sites More sharing options...
justlukeyou Posted October 10, 2012 Author Share Posted October 10, 2012 (edited) Ah hell this is killing me When Im logged get this: array(3) { ["userLoggedIn"]=> int(1) ["userEmail"]=> string(23) "someone@yahoo.com" ["userID"]=> string(3) "test" } Pikachu, the following two use of comma appear to have the same results. Im lost as to how I should end it as I get the same results. country = '".$_POST['country']."', WHERE country = '".$_POST['country']."'; WHERE Edited October 10, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384323 Share on other sites More sharing options...
kicken Posted October 10, 2012 Share Posted October 10, 2012 Pikachu, the following two use of comma appear to have the same results. Im lost as to how I should end it as I get the same results. country = '".$_POST['country']."', WHERE country = '".$_POST['country']."'; WHERE That is because they are both wrong. You don't end a list with a comma. It only goes between items: a, b, c, d, <- not correct a, b, c, d <- correct Hence why you were told to: ... Remove the extra comma. Not replace it with a semi-colon. Where you got that idea from I have no idea. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384332 Share on other sites More sharing options...
justlukeyou Posted October 11, 2012 Author Share Posted October 11, 2012 a, b, c, d, <- not correct a, b, c, d <- correct Many thanks, that makes it so much easier to understand. Is there anyway I can echo just the ID so I can test if it is reading the ID. I have tried a vardump which echoes the following "array(3) { ["userLoggedIn"]=> int(1) ["userEmail"]=> string(23) "somewhere@yahoo.com" ["userID"]=> string(2) "id" }" Although Im not not sure what it should show. I take its not the above? var_dump($_SESSION); $_SESSION['userID'] = 'id'; $_POST['form_id']; function mysql_real_escape_array($t) { return array_map("mysql_real_escape_string",$t); } function trim_array($ar) { return array_map("trim",$ar); } if(isset($_POST['form_id'])) { $_POST = mysql_real_escape_array($_POST); $_POST = trim_array($_POST); $error = ""; if(!isset($_POST['category']) || empty($_POST['category'])) { $error = "Please select a category."; } if(!isset($_POST['website']) || empty($_POST['website'])) { $error.= " Please enter a Website Domain."; } if(!isset($_POST['company']) || empty($_POST['company'])) { $error.= " Please enter a Company Name."; } if(!isset($_POST['building']) || empty($_POST['building'])) { $error.= " Please enter a Building Name or Number."; } if(!isset($_POST['streetname']) || empty($_POST['streetname'])) { $error.= " Please enter a Street Name."; } if(!isset($_POST['town']) || empty($_POST['town'])) { $error.= " Please enter your Town."; } if(!isset($_POST['state']) || empty($_POST['state'])) { $error.= " Please enter a State."; } if(!isset($_POST['postcode']) || empty($_POST['postcode'])) { $error.= " Please enter a Zip Code/Post Code."; } if(!isset($_POST['country']) || empty($_POST['country'])) { $error.= " Please select your country."; } if(!isset($_POST['aboutcompany']) || empty($_POST['aboutcompany'])) { $error.= " Please enter details about your company."; } if($error == "") { $sql = " UPDATE users SET category = '".$_POST['category']."', linkcategory = '".str_replace(' ', '-',strtolower($_POST['category']))."', firstname = '".$_POST['firstname']."', surname = '".$_POST['surname']."', email = '".$_POST['email']."', website = '".$_POST['website']."', company = '".$_POST['company']."', building = '".$_POST['building']."', streetname = '".$_POST['streetname']."', town = '".$_POST['town']."', state = '".$_POST['state']."', postcode = '".$_POST['postcode']."', aboutcompany = '".$_POST['aboutcompany']."', country = '".$_POST['country']."' WHERE id = " . $_SESSION['userID']; $result = mysql_query($sql) or die("An error occurred ".mysql_error()); } } Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384611 Share on other sites More sharing options...
Jessica Posted October 11, 2012 Share Posted October 11, 2012 How do you seriously not see what's wrong with that code? Do you really not know the difference between a word and a number? Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384612 Share on other sites More sharing options...
justlukeyou Posted October 11, 2012 Author Share Posted October 11, 2012 Which word? Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384623 Share on other sites More sharing options...
justlukeyou Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) Righty so when I replace 'id' with 70 which is an ID number in the database it updates just ID number 70, finally getting somewhere! So how do I replace '70' with the actual id number of the member who is logged in? Edited October 11, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384626 Share on other sites More sharing options...
Barand Posted October 11, 2012 Share Posted October 11, 2012 $id = (int) $_POST['form_id']; Then add your where clause. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384628 Share on other sites More sharing options...
justlukeyou Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) $id = (int) $_POST['form_id']; Then add your where clause. Which now creates an error! I just dont get what you mean. I have this which reads 70 and updates profile 70. But when I change it to id it doesn't. $_SESSION['userID'] = '70'; WHERE id = " . $_SESSION['userID']; What does this go with. But I have no idea what this means: $id = (int) $_POST['form_id']; Then add your where clause. Edited October 11, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384633 Share on other sites More sharing options...
Jessica Posted October 11, 2012 Share Posted October 11, 2012 Then it's time to find a new hobby. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384635 Share on other sites More sharing options...
justlukeyou Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) I genuinely dont think your explaining things very well with this issue. The reason I say that is that all the progress I have made to point I can now update a single id is from another forum. All the responses thus far on this forum have meant nothing and helped very little. I've had some tremendous help and guidance with other topics but posts like $id = (int) $_POST['form_id']; Then add your where clause. mean nothing. Edited October 11, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384638 Share on other sites More sharing options...
Jessica Posted October 11, 2012 Share Posted October 11, 2012 The first line tells you to assign the value of $_POST['id'] to $id, while casting it to an integer. Since it's an ID, it should be a number. The second line tells you to put a WHERE clause on your query, which you did. WHERE THE HELL ARE YOU STUCK??? You have a half dozen versions of this code that just show you putting random bits of code in, if you don't understand what ANY OF IT DOES you will continue to come back and be confused. If another forum is happy to do it for you, GO BACK THERE. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384639 Share on other sites More sharing options...
Pikachu2000 Posted October 11, 2012 Share Posted October 11, 2012 It really is time to just hire someone. You have no aptitude for programming whatsoever. Sorry to be blunt, but it's the truth. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384643 Share on other sites More sharing options...
Jessica Posted October 11, 2012 Share Posted October 11, 2012 Also, you need to learn HOW TO LEARN. Learning to bake is very similar to learning to program. Would you read a recipe and see "tbs" and throw your hands in the air and say you don't get it? What would you do when you are instructed to temper chocolate? Or sift flour? This is the SAME process. These are mostly English words that you simply don't understand and rather than throwing flour into the oven and picking a random temperature, then complaining that your cupcakes taste bad, you need to learn what the terms are and how the processes work. Then you can learn that when your cupcakes rise and fall, it means your baking soda ia too old, and when they never rose at all, you probably forgot the baking soda entirely. You don't just throw random things together without knowing WHY. The computer is no more magic than my mixer, you have to do things in the right order, and be specific. The good thing is that with a computer, you're not likely to poison anyone if you mess up, so you can try things until you get it right. If you want to update a specific user, you need to know what user to update. It's up to you to decide how that information gets from one place to another, there are several ways. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384644 Share on other sites More sharing options...
justlukeyou Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) But you have to admit, responses like these: "How do you seriously not see what's wrong with that code? Do you really not know the difference between a word and a number?" or "2. What is $int?" Are no way useful. They just dont help answer the topic. its almost as if your revelling in the fact you know alot more about PHP than I do and want to ensure you let me know. Can I please ask one very simple question...Does this code allocate the id number to $id? $id = (int) $_POST['form_id']; If so why isn't the following the correct WHERE clause to use? WHERE id=$id"; Edited October 11, 2012 by justlukeyou Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384648 Share on other sites More sharing options...
Barand Posted October 11, 2012 Share Posted October 11, 2012 It is the correct WHERE clause to use (at last!) but every time you have used you haven't assigned a value to $id and you have had that preceding comma that we kept telling you was causing an error. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384654 Share on other sites More sharing options...
KevinM1 Posted October 11, 2012 Share Posted October 11, 2012 In past posts, I gave you a link to what I felt was the most "In plain English" resource I have found - Larry Ullman's book. Have you bought it yet? Because that's as gentle an introduction there is. Get it, if you don't have it already. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384655 Share on other sites More sharing options...
justlukeyou Posted October 12, 2012 Author Share Posted October 12, 2012 It is the correct WHERE clause to use (at last!) but every time you have used you haven't assigned a value to $id and you have had that preceding comma that we kept telling you was causing an error. Apologies mate, I really didn't know that the comma was just the issue. I was following the code for the original profile creation and that has comma on the end and works. I have thought it had to have a comma or something on the end. I shall try it ASAP and give it a go. Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384725 Share on other sites More sharing options...
Andy123 Posted October 12, 2012 Share Posted October 12, 2012 This is not entirely correct, I'm afraid. While it is true that PDO support multiple database systems, it does not translate the SQL sentences. It is not a Database Abstraction Layer (DBA), but an Data Access Abstraction layer (DAA). So unless you're using nothing but the most simplest of SQL queries, you'll still have to translate the queries whenever you change the underlying database engine. Yes, I am aware of that. I realize that I wrote "all there is to do", which sounds misleading. What I actually with that is that all you have to switch to using a different database vendor is to change the connection string. That is, to simply connect to the database. As such, you won't have to change any code other than some SQL strings. So yeah, you will most likely face SQL syntax errors, but you will connect to the database just fine. Sorry that I was not clear enough. Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384856 Share on other sites More sharing options...
justlukeyou Posted October 12, 2012 Author Share Posted October 12, 2012 Hi, I think I have it how people suggested however it is not doing anything. It is not updating the database for any profilers or returning any error messages. Is it worth just echoing the id number? $id = (int) $_POST['form_id']; function mysql_real_escape_array($t) { return array_map("mysql_real_escape_string",$t); } function trim_array($ar) { return array_map("trim",$ar); } if(isset($_POST['form_id'])) { $_POST = mysql_real_escape_array($_POST); $_POST = trim_array($_POST); $error = ""; if(!isset($_POST['category']) || empty($_POST['category'])) { $error = "Please select a category."; } if(!isset($_POST['website']) || empty($_POST['website'])) { $error.= " Please enter a Website Domain."; } if(!isset($_POST['company']) || empty($_POST['company'])) { $error.= " Please enter a Company Name."; } if(!isset($_POST['building']) || empty($_POST['building'])) { $error.= " Please enter a Building Name or Number."; } if(!isset($_POST['streetname']) || empty($_POST['streetname'])) { $error.= " Please enter a Street Name."; } if(!isset($_POST['town']) || empty($_POST['town'])) { $error.= " Please enter your Town."; } if(!isset($_POST['state']) || empty($_POST['state'])) { $error.= " Please enter a State."; } if(!isset($_POST['postcode']) || empty($_POST['postcode'])) { $error.= " Please enter a Zip Code/Post Code."; } if(!isset($_POST['country']) || empty($_POST['country'])) { $error.= " Please select your country."; } if(!isset($_POST['aboutcompany']) || empty($_POST['aboutcompany'])) { $error.= " Please enter details about your company."; } if($error == "") { $sql = " UPDATE users SET category = '".$_POST['category']."', linkcategory = '".str_replace(' ', '-',strtolower($_POST['category']))."', firstname = '".$_POST['firstname']."', surname = '".$_POST['surname']."', email = '".$_POST['email']."', website = '".$_POST['website']."', company = '".$_POST['company']."', building = '".$_POST['building']."', streetname = '".$_POST['streetname']."', town = '".$_POST['town']."', state = '".$_POST['state']."', postcode = '".$_POST['postcode']."', aboutcompany = '".$_POST['aboutcompany']."', country = '".$_POST['country']."' WHERE id=$id"; Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384862 Share on other sites More sharing options...
justlukeyou Posted October 12, 2012 Author Share Posted October 12, 2012 When I try to echo something nothing appears however when I try the vardump I do get an email address echoed. echo $row['email']; Quote Link to comment https://forums.phpfreaks.com/topic/269163-update-only-against-unique-id-number/page/2/#findComment-1384865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.