473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem updating database via form (PHP/HTML)

I am trying to code a page that allows the user to edit the content that is drawn from the database. The fields show the correct data from the database, and you can type in the fields, but the database does not update when the "submit" button is clicked. It jumps to the events list page, as it should, but the information has not been changed.

My code is as follows:

Top of page
[php]
<? if (array_key_exists('_submit_check', $_POST)) {
mysql_query("UPDATE events SET eventTitle = '$eventTitle', eventInfo = '$eventInfo', eventImage = '$eventImage' WHERE eventID = '$id'");
header("Location: eventsList.php");
}
?>[/php]

Within the template
[php]<?php
mysql_select_db($database_Site, $Site);
$query = "SELECT * FROM events WHERE eventID = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$id = mysql_result($result,$i,"eventID");
$eventTitle = mysql_result($result,$i,"eventTitle");
$eventInfo = mysql_result($result,$i,"eventInfo");
$eventImage = mysql_result($result,$i,"eventImage");
?>
<form action="<? echo $PHP_SELF; ?>" method="POST">
<input type="hidden" name="_submit_check" value="1"/>
<input type="hidden" name="eventID" value="<? echo $id; ?>">
<tr>
<td valign="top"><b><font size="2" face="Arial, Helvetica, sans-serif">Title</font></b></td>
<td><input size="50" maxlength="250" type="text" name="eventTitle" value="<? echo $eventTitle; ?>">
</td>
</tr>
<tr>
<td valign="top"><b><font size="2" face="Arial, Helvetica, sans-serif">Information</font></b></td>
<td><textarea name="eventInfo" cols="40" rows="10"><? echo $eventInfo; ?></textarea>
</td>
</tr>
<tr>
<td valign="top" align="left"><font face="Arial, Helvetica, sans-serif" size="2"><b>Image</b></font></td>
<td><input size="50" maxlength="250" type="text" name="eventImage" value="<? echo $eventImage; ?>">
</td>
</tr>
<tr align="center" valign="top">
<td colspan=2><input type="Submit" name="submit" value="Update">
</td>
</tr>
</form>[/php]

Any help would be appreciated.
Jan 9 '08 #1
1 1503
mwasif
802 Expert 512MB
Hi lilbadger25,

Welcome to TSDN!!!

[php]
<? if (array_key_exists('_submit_check', $_POST)) {
mysql_query("UPDATE events SET eventTitle = '$eventTitle', eventInfo = '$eventInfo', eventImage = '$eventImage' WHERE eventID = '$id'");
header("Location: eventsList.php");
}
?>[/php]
What is the value of $id and where you are assigning the value to it? To know the issue, use the following code
[PHP]<?
if (array_key_exists('_submit_check', $_POST)) {
$query = "UPDATE events SET eventTitle = '$eventTitle', eventInfo = '$eventInfo', eventImage = '$eventImage' WHERE eventID = '$id'";
mysql_query($query);
echo $query;
exit;
header("Location: eventsList.php");
}
?>[/PHP]
This will print the query. Please confirm if the printed query is correct or not.

Post back what did you get from the above code?
Jan 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
0
by: Bob Kaku | last post by:
I'm trying to create a text editing and updating capability to help someone who wants to maintain content on a web page without having to know any HTML or use a web authoring tool and FTP'ng the...
3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
4
by: Federico Bari | last post by:
Good morning all from italy, i have probably a compatibility problem with a html/javascript page. The aim of the code of the file test.htm you find here following (copy the 3 files in the...
6
by: '~=_Slawek_=~' | last post by:
I have problem with SQL update. Sometimes it can take 2-10 seconds. I need to make this update every time page is opened - ASYNCHRONOUSLY. I have read forums, php.net etc about running php code...
31
by: Lag | last post by:
Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY CODE IN update.php----(user, pass, and database are typed in directly, I...
2
by: underground | last post by:
Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form <? include("include/session.php");...
2
by: rpjd | last post by:
I am trying to submit entries in a form to a database. I am using " within my submission form and $_POST I am getting the connection to the database but I my script is not executing,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.