Current location: Hot Scripts Forums » Programming Languages » PHP » php script running a mysql UPDATE query


php script running a mysql UPDATE query

Reply
  #1 (permalink)  
Old 05-29-04, 08:43 AM
chronic_ chronic_ is offline
Newbie Coder
 
Join Date: May 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
php script running a mysql UPDATE query

Here is my script, it is for a blocks system i have created for a CMS i'am writing, however, i'm really struggling with update/edit pages, i want a page where you can update a block in the database, i will add admin protection later, anyway, my problem is, i can't get the form to update the database, i have tried using variables instead of $name for form input e.g.
$fname = $_POST['name']
$fcontent = $_POST['content']

but this still makes no difference, the page just refreshes, but no update is made to the database. I have tried using other fields from the database like " WHERE name = 'name here' " but that didn't work either, so i don't think its anything to do with auto-increment. It just won't work, can you help me because i really need to work out how to do an update page.

<HTML>
<?php
if($submit){

include("config.php"); //include config file

$db = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("cannot connect to database"); //create database connection variable, called 'db'

mysql_select_db($dbname,$db); //select the database, specify database name, then connect

$sql = "UPDATE blocks WHERE position = '3' SET name = '$name', content = '$content'";
mysql_query($sql);
echo "Information updated...";
} else {
?>
<form method="post" action="<? echo $PHP_SELF ?>">
Name:<input type="Text" name="name"><br>
Content:<input type="Text" name="content"><br>
Position:<input type="Text" name="position"><br>
<input type="Submit" name="submit" value="Update information"></form>
<?
}
?>
</HTML>
Reply With Quote
  #2 (permalink)  
Old 05-29-04, 08:49 AM
e-Tech-Solution e-Tech-Solution is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The MySQL documentation is available at http://dev.mysql.com/doc/mysql/en/UPDATE.html

Try putting the where clause after your set clause. If that doesn't work, add something like "echo mysql_error();" right after you run the query
Reply With Quote
  #3 (permalink)  
Old 05-29-04, 09:45 AM
chronic_ chronic_ is offline
Newbie Coder
 
Join Date: May 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Somebody please help, i've tried everything !

Somebody please help, i've tried everything !
Reply With Quote
  #4 (permalink)  
Old 05-29-04, 11:06 AM
chronic_ chronic_ is offline
Newbie Coder
 
Join Date: May 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
New script... [Still having problems !!!]

I tried writing a new script, i've posted it here, but im still having problems, can someone please find a problem with either of the scripts and help me please !?

Both scripts execute fine, but no physical changes to the database actually happen. Can anybody help me ?

<?php
include("config.php"); //include config file

if ($submit){
mysql_connect ($dbhost, $dbuser, $dbpass) or die ("cannot connect to database"); //create database connection variable, called 'db'
$sql = "UPDATE blocks SET "
." name=\"".$_POST['name']."\""
.",content=\"".$_POST['content']."\""
." WHERE position = '".$_POST['position']."'";
mysql_query ($sql);
}else{
?>
<form name="update" method="post" action="<?php echo $PHP_SELF ?>">
name:<input type="text" name="name">
content:<input type="text" name="content">
position:<input type="text" name="position">
<input type="submit" name="submit" value="click">
<?
}
?>
Reply With Quote
  #5 (permalink)  
Old 05-29-04, 12:22 PM
e-Tech-Solution e-Tech-Solution is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Put:

echo(mysql_error());

After your mysql_query() and tell us the result.

Quote:
Originally Posted by chronic_
I tried writing a new script, i've posted it here, but im still having problems, can someone please find a problem with either of the scripts and help me please !?

Both scripts execute fine, but no physical changes to the database actually happen. Can anybody help me ?

<?php
include("config.php"); //include config file

if ($submit){
mysql_connect ($dbhost, $dbuser, $dbpass) or die ("cannot connect to database"); //create database connection variable, called 'db'
$sql = "UPDATE blocks SET "
." name=\"".$_POST['name']."\""
.",content=\"".$_POST['content']."\""
." WHERE position = '".$_POST['position']."'";
mysql_query ($sql);
}else{
?>
<form name="update" method="post" action="<?php echo $PHP_SELF ?>">
name:<input type="text" name="name">
content:<input type="text" name="content">
position:<input type="text" name="position">
<input type="submit" name="submit" value="click">
<?
}
?>
__________________
e-Tech-Solution.com: Shared Windows 2003 Hosting and Cross-platform Web Development
Reply With Quote
  #6 (permalink)  
Old 05-29-04, 06:46 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Point the form here:
http://www.acecoolco.com/tool_request_tester.php

then, copy all the items under:

Showing all POST variables:
Posted variable name Posted variable Contents

Showing all GET variables:
Variable in url Get Variable Contents

###
you might need to do

if ($_POST['Submit']) {
or
if ($_POST['submit']) {
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
cant add more than 1 mysql table with php script chrisb62 PHP 1 04-27-04 04:00 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 03:31 AM


All times are GMT -5. The time now is 10:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.