Jump to content

Update mysql not workking


anne3marie

Recommended Posts

I am very new to php. I am using the code below to process a html form to update customers preference called item1. I want to update only the loggin in customer which  is where my problem is. If i write "WHERE userid=4" or no where statement at all it updates correctly. When I include the where statement, it echos "updated" but the database doesn't change. I cannot figure out the correct where statement! Please Help!

 

 

<?php

include 'db.php';

 

$item_1 = $_POST['item1'];

 

$query = "UPDATE users SET item_1 = '$item_1' WHERE userid='$userid'";

 

 

 

if(mysql_query($query)){

echo "updated";}

else{

echo "fail";}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/263402-update-mysql-not-workking/
Share on other sites

I thought I tried that but it seems adding session_start() did the trick. Thanks for helping me. I knew it was a simple fix! Now do you know how I would add a conditional statement that leaves the database entry alone? I don't know what goes at the end of this statement or if it is possible. something like If '$item1'== 'do not update' {} not sure

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.