Jump to content

Recommended Posts

This one actually made me laugh.

I have a form with a text area (id="comments") that post to Update.php

 

Update.php

	
mysql_select_db('chamber');

$text = $_POST['comments'];

mysql_query("UPDATE announcements SET text = $text WHERE id='1'"); 
/*	mysql_query("UPDATE announcements SET text = 'This does update' WHERE id='1'"); */

mysql_close($my_connection);

echo "Hello World";

 

The weird thing is that "Hello World" pops up, so I kind of assumed that it's executing, but the database doesn't update.  I can get it to update if I just type in text, but I'm not passing anything from the form.  Without any errors it makes things difficult to work on.

 

Any thoughts or a working example to study would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/161396-no-update-and-no-errors/
Share on other sites

Maq

 

Thank you for the reply.

I didn't know that about the reserve word...never even crossed my mind.  So I went back and renamed a few things.  Still didn't work, but here is what I have discovered.  When I run the Update.php by itself and manually put in some text, it updates fine.  But when I launch Update.php from my form page, it doesn't update.  The echo "Hello World" pops up and the page looks the same, but no update.  I was using the echo to gage whether or not things were working, but I guess I was off on this too.

 

Here's the form:

<!-- Start  -->

<body bgcolor="#d6cab6">
<div id="Global">
  
  <div id="Workarea">
  
  <div id="formHolder">
  <form name="form1" method="post" action="Update.php">
    <table width="100%" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td>
          <textarea name="comments" id="comments" cols="26" rows="5"></textarea>
        
          <input type="submit" name="submit" id="submit" value="Submit" />
    	</td>
      </tr>
  </form>
  </div>
  </div>
  </div>
</body>
</html>

 

Here's the new Update.php

<?php

$my_connection = mysql_connect('localhost', 'root', 'root');

if (!$my_connection){
	die('Could not connect: ' .mysql_error());
}


mysql_select_db('chamber');

/*	$i = $_POST['comments'];

mysql_query("UPDATE announcements SET comment_field = $i WHERE id='0'"); */
mysql_query("UPDATE announcements SET comment_field = 'This does update for me' WHERE id='0'"); 

mysql_close($my_connection);


echo "Hello World";

?>

 

I don't understand.  Even if I'm putting in text manually, why wouldn't it update simply because it was launched from a previous page?

no. it should work.

 

try this:

   mysql_query("UPDATE announcements SET comment_field = '".$i."' WHERE id='0'"); 
//mysql_query("UPDATE announcements SET comment_field = 'This does update for me' WHERE id='0'"); 

 

you might need to use single quotes (i already inserted them)

Yes sorry, you need single quotes around values that aren't INTs.

 

Either use what alco has or put: (if id is an interger, which is should be, then you don't need single quotes there)

 

comment_field = '$i' WHERE id='0'"); 

 

If that doesn't, work you could use or die to see what the error is (take this off as soon as it goes live):

 

   mysql_query("UPDATE announcements SET comment_field = '$i' WHERE id='0'") or die(mysql_query()); 

 

 

Thanks for the replies.  I appreciate the input.

 

I'm a bit baffled on this one.  I've been wondering about this echo working while nothing else does.  Truth is, it wasn't working.  When I changed 'Hello World' to 'Hello World 2' there weren't any changes.  Mystified, I renamed both files and tried again.  This time, I ran the form first and came up with the error that the new_update.php wasn't found.  ???  They're in a folder by themselves, how could they not see each other. Once I ran the new_update.php by itself, then the form would see it, but only the new_update.php that was run by itself. Consequently none of the changes I was making to the new_update.php was being seen.  I've never had a file issue like this.  Why would the form see it only after it has been run by itself?!  A file is a file, shouldn't it be there all the time?!

 

I've enclosed the complete code for both files:

new_input.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<!-- Start  -->

<body bgcolor="#d6cab6">

  <form name="form1" method="post" action="new_update.php">
    <table width="100%" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td><textarea name="comments" id="comments" cols="26" rows="5"></textarea>
          <input type="submit" name="submit" id="submit" value="Submit" />
    	</td>
      </tr>
  </form>

</body>
</html>

 

new_update.php:

<?php

$my_connection = mysql_connect('localhost', 'root', 'root');

if (!$my_connection){
	die('Could not connect: ' .mysql_error());
}


mysql_select_db('chamber');

/*	$i = $_POST['comments'];

mysql_query("UPDATE announcements SET comment_field = '".$i."' WHERE id='0'") or die(mysql_query());*/
mysql_query("UPDATE announcements SET comment_field = 'fifth attempt to verify' WHERE id='0'") or die(mysql_query()); 

mysql_close($my_connection);


echo "Hello World 3";

?>

 

I don't get it ??? ???

The PHP Powers don't like me.

this shouldn't do anything, but maybe try and clear your cache (if you're on a local machine, restart your apache server). also, idk if this will change anything but instead of using the back button on your browser, enter the actual address in the URL box

 

I was thinking along the same lines.  I've tried that and restarting the machine multiple times.  I tried running it outside of Dreamweaver -- straight out of the folder with Firefox (didn't work but is that bypassing the server?).  I didn't have any problems earlier this morning when I was learning how to read from a database.  I used the same kind of setup with the two different files. 

 

I might try uploading the files to my Godaddy account and seeing if things work better from there.  I've tried to make the files as short and as simple as I can, but I just feel like I'm missing something.  I dunno.  I'll give it another shot tomorrow. 

 

Thanks for all of the inputs.

this shouldn't do anything, but maybe try and clear your cache (if you're on a local machine, restart your apache server). also, idk if this will change anything but instead of using the back button on your browser, enter the actual address in the URL box

 

I was thinking along the same lines.  I've tried that and restarting the machine multiple times.  I tried running it outside of Dreamweaver -- straight out of the folder with Firefox (didn't work but is that bypassing the server?).  I didn't have any problems earlier this morning when I was learning how to read from a database.  I used the same kind of setup with the two different files. 

 

I might try uploading the files to my Godaddy account and seeing if things work better from there.  I've tried to make the files as short and as simple as I can, but I just feel like I'm missing something.  I dunno.  I'll give it another shot tomorrow. 

 

Thanks for all of the inputs.

 

try entering

 

$var1 = 'hello world';
$var2 = 'hello world 2';

var_dump($var1, $var2);

 

See what you get from the above (by just going to the address of the file and not doing the form action)

try entering

 

$var1 = 'hello world';
$var2 = 'hello world 2';

var_dump($var1, $var2);

 

See what you get from the above (by just going to the address of the file and not doing the form action)

 

I apologize for taking so long to get back.  I tried the code and got this: string(11) "hello world" string(13) "hello world 2" Hello World 2

 

Here's the code:

<?php

$my_connection = mysql_connect('localhost', 'root', 'root');

if (!$my_connection){
	die('Could not connect: ' .mysql_error());
}
$var1 = 'hello world';
$var2 = 'hello world 2';

var_dump($var1, $var2);	

mysql_select_db('chamber');

/*	$i = $_POST['comments'];

mysql_query("UPDATE announcements SET comment_field = '".$i."' WHERE id='0'") or die(mysql_query());*/
mysql_query("UPDATE announcements SET comment_field = 'fourth attempt to verify' WHERE id='0'") or die(mysql_query()); 

mysql_close($my_connection);

echo "Hello World 2";

?>

 

This was without using the form.

???

so basically you're saying when you update it now and don't use the form... it shows the new updates?

 

Exactly

 

For some reason, the form doesn't trigger the new_update.php code.  More to the point, it doesn't even see it until I have run the new_update.php once by itself.  At that point, it will display new_update.php ... but it won't display any of the changes I might make until I run the new_update.php again (by itself).

 

It would be nice if this was something incredibly simple. 

 

Thanks for the feedback.

Maybe this will do a little better job explaining.

 

Step 1) From a freshly fired up computer I run the form

Result) Nothing

 

Step 2) I run the new_update.php

Result) The new_update.php page displays and the database is updated.

 

Step 3) I run the form again.

Result) The new_update.php is displayed but the database is not updated.

 

Step 4) I modify new_update.php but do not run it.

 

Step 5) I run the form again.

Result) The original new_update.php page (Step 2) is displayed and the database is not updated.

 

Step 6) Run the new_update.php

Result) The new_update.php page is displayed and the database updated.

 

Step 7) I run the form again

Result) The new_update.php from Step 6 is displayed, but the database is not updated.

 

and so on and so on...

 

It seems to me that the form is calling up the previously displayed new_updated.php page instead of actually running it.  But I could be smoking crack too.  :P

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.