Jump to content

[SOLVED] Update Not Working For Some Reason. Probably Really Simple Issue.


basement

Recommended Posts

the database connects properly so it isn't that.

 

$connect = @mysql_connect('localhost',"******_" . $_SESSION['user'],$_SESSION['password']);

if($connect == true){

@mysql_select_db($database, $connect);

if(isset($_POST['Edit'])){

$description1=$_POST["description1"];

echo($description1);

$query1 = "UPDATE Description SET description = $description1 WHERE id = 1";      <------------

 

if(mysql_query($query1))                                                                              <------------

echo("<h1>Company description has been updated.</h1>");

else

echo("<p>Failed to update company description</p><br />");

 

 

----------------------------------------------------------------------------------------

 

i'm sure the issue is one of the two lines that the arrows are pointing at. that page always says that it failed to update the company description and every time i reload it the changes haven't been saved. so the mysql_query isn't doing what i'm thinking it should. but i've probably made a mistake somewhere.

 

and this line

 

$result = @mysql_query("SELECT description FROM Description WHERE id=1")

 

pulls description from the table correctly and consistently.

Link to comment
Share on other sites

Further information. I added the or die(mysql_error()) line and it produced this

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '******* is a publicly traded (***: ****) Canadian exploration-stage mining comp' at line 1

 

 

interesting the error is missing the first word of the textarea box. not sure why that is but it could be the issue. I really hope someone can help me with this. I'm trying to add data via another form and that one isn't working either. Using version 5.0.45

Link to comment
Share on other sites

Guess you should  use quotes around your column values ;-)

 

UPDATE Description SET description = '$description1' WHERE id = 1

 

Best again if you apply mysql_real_escape() to $description1 before submitting it to the database.

Some little unrequested tips:

- never use @ in front of db instructions

- ALWAYS use "or die(mysql_error())" after EVERY db instruction

- always escape data as above before giving it to the db if it comes from user

Link to comment
Share on other sites

if(isset($_POST['Edit'])){

$description1=mysql_real_escape_string($_POST["description1"]);

 

$query1 = "UPDATE Description SET description = '$description1' WHERE id = 1";

 

$result = mysql_query($query1) or die(mysql_error());

if($result)

echo("<h1>Company description has been updated.</h1>");

else

echo("<p>Failed to update company description.</p><br />");

 

 

working now. thank you very very much. wish you were on at 12am EST last night though!

 

*rush rush rush*

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.