Jump to content

Update Only Against Unique Id Number


justlukeyou

Recommended Posts

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?

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

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 by justlukeyou
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

 

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());

   }
}

Link to comment
Share on other sites

$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 by justlukeyou
Link to comment
Share on other sites

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 by justlukeyou
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by justlukeyou
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.