Jump to content

Proper Format


dpiearcy

Recommended Posts

I'm still learning mysqli (obviously).

 

Can someone give me the proper format for the following?

 

 

$query = mysqli_query($myConnection, "INSERT INTO table WHERE id='$pid' LIMIT 1(how, date)

VALUES('$var', now()) ") or die (mysqli_error($myConnection));

 

Just wanting to update here and not write a new row hence why I need to match the id.

Link to comment
Share on other sites

You need an UPDATE, not an INSERT

 

UPDATE tablename
SET how = '$var', date=NOW()
WHERE id=$pid LIMIT 1

 

If the is unique you don't need the LIMIT 1.

 

WHAT button do I push to insert code like you did? I've tried a few of them and haven't figured that out on here yet either :-) I want to do things correctly after all. I know this was off topic but thought I'd ask.

 

I'm going to try that and see if it works. Thanks for the reply.

Link to comment
Share on other sites

Thanks for that Christian F.

 

Ok... not even going to bother changing table names and var names this time. This still does not work. I'm no longer getting an error but from php myadmin I see nothing has changed in the database.

 

Here is what I used as per Barand.

 

$query = mysqli_query($myConnection, "UPDATE prayer SET how = '$praise', date=NOW() WHERE id=$pid") or die (mysqli_error($myConnection));

 

Tried single quotes around the var pid to no effect as well just to check.

Link to comment
Share on other sites

I should say (not sure if it matters) but the row ''how" has nothing in it until this point. The other rows are filled out except for how and then I want the current date. From the former insert I have the date of original insert. I want the date now so I can have both so I have two different rows for that.

 

Short and simple, this is a prayer request board for a church I'm helping. Have their request board working but I want them to hit a button when prayer is answered. That's the how part coming from a form that says how it all happened. Then I show on a different board answered prayer with the original request, the how, the original posted date and then the answered date.

 

I know none of that matters just saying neither of those rows will have anything in them. (well....date will have the default 00-00-0000 I guess).

Link to comment
Share on other sites

I THINK I have found at least the source of part of the problem. For SOME reason my sessions suddenly stopped working. I had my parse.php just echo my variables and I was getting the ID from a session stored. It was working earlier and now has stopped. So I'm not sending the ID to the database to change hence no change.

 

Back to figuring out why that suddenly stopped working since I haven't edited that at all.

Link to comment
Share on other sites

It's more likely that you introduced a literal character or the BOM (Byte Order Mark) at the start of your file and that's what is causing your session variables to no longer work, and in the case where they started working again, that character/BOM got removed or didn't transfer when you copied file(s) to a server.

 

Do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying all the errors it detects? You are likely getting php errors that would point to why your session variables are not working.

 

Also, echoing a $_SESSION variable on the page where it is set, doesn't mean that variable is part of a session if the session_start() statement on that page has failed. In this case, the $_SESSION variables are only local to the page they are set on.

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.