Jump to content

Recommended Posts

The basic format for an UPDATE query is

 

UPDATE table_name SET field_name=new value

 

In order for it to function $id will HAVE to be set to a field name. What are you trying to do? What is $id set to? Maybe your query is supposed to be:

$query4 = "UPDATE users SET id='$id' WHERE name='$n1'";

the $id is a variable that changes depending on who access the page, so it can't be a specific field name.  It needs to be a variable.

 

So you create a new column in a table for every new user that signs up?

There are about 20 columns, all with different names.  When the user hits the php page it will parse a specific column name which is the variable $id.  So I need it to insert a 1 into that column if it's used.  But because there could be any of 20 different ones I have to use a variable.  So I need the field name to be a variable.

Apprently I am not making myself very clear.  Lets try this again..

 

Someone hits the page and parses a 12 to the $id variable.  Which in my database there is a column named 12..  I need it to insert a 1 into that field.

 

But not everyone will parse a 12, some may parse another number which will have columns already setup for in the database.

Someone hits the page and parses a 12 to the $id variable.  Which in my database there is a column named 12.. 

IIRC, you can't have a column name that begins with a numeric value in mySQL, or most other databases

How does 12 get passed to the page? Via the url like

 

filename.php?id=12

 

In which case to get the id from the url you'll use $_GET['id'] like so

 

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = (int) $_GET['id'];

    $query4 = "UPDATE users SET $id='1' WHERE name='$n1'";

    // rest of code
}

If you fields named a1 .. to .. a12 and you're using the example code I made above

 

Then you'd do:

if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id = 'a'.$_GET['id'];

    $query4 = "UPDATE users SET $id='1' WHERE name='$n1'";

    // rest of code
}

 

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.