Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php update a record in mysql

Status
Not open for further replies.

babez

Programmer
Jan 3, 2007
4
0
0
GB
Hi i have this script as follows, and i cant understand why it doesnt work. all my connections are correct and it does put values in the database...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns=" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> update record fields in the events table </title>
</head>
<body>
<center>
<?
include 'database_conn.php';

$neventCode = $_POST['neventCode']; // need this to identify the particular record
$ntitle = $_POST['ntitle'];
$nartistname = $_POST['nartistname']; // new value for artistname
$ndescription = $_POST['ndescription'];
$ntype = $_POST['ntype'];
$nstartdate = $_POST ['nstartdate'];
$nenddate = $_POST['nenddate'];
$ntime = $_POST['ntime'];
$nvenuename = $_POST['nvenuename']; // new value for venuename
$nvenueaddress = $_POST['nvenueaddress'];
$ntelephone = $_POST['ntelephone'];
$nurl = $_POST['nurl'];

//print on the screen that the record is currently being updated
echo "<h1>Updating record ... </h1>";

//command to update the events table

$sql = "UPDATE events SET title = $ntitle, artistname = $nartistname, description = $ndescription, type = $ntype, startdate = $nstartdate, enddate = $nenddate, time = $ntime, venuename = $nvenuename, venueaddress = $nvenueaddress, telephone = $ntelephone, url = $nurl, WHERE eventCode = $neventCode";

mysql_query($sql) or die (mysql_error());

echo "<h2>Record updated</h2>";

mysql_close($conn);
?>
<form name="Back to Admin" method="post" action="Administration.html">
<input type="submit" name="submit" value="Back to Admin">
</form>
</center>
</body>
</html>

and the values before and after are as follows (in the database)

mysql> select *from events;
+-----------+--------------------+-------------------------+------------------------------------+-------+------------+------------+------+-------------------+---------------------------------------------------------+-------------+---------------------------------+
| eventCode | title | artistname | description | type | startdate | enddate | time | venuename | venueaddress | telephone | url |
+-----------+--------------------+-------------------------+------------------------------------+-------+------------+------------+------+-------------------+---------------------------------------------------------+-------------+---------------------------------+
| 1 | ONE NIGHT OF QUEEN | Gary Mullen & The Works | Live in concert one night of queen | music | 2006-12-09 | 2006-12-09 | 1900 | Metro Radio Arena | Metro Radio Arena Newcastle Newcastle upon Tyne NE4 7NA | 0870 7000 9 | |
+-----------+--------------------+-------------------------+------------------------------------+-------+------------+------------+------+-------------------+---------------------------------------------------------+-------------+---------------------------------+
1 row in set (0.00 sec)

mysql> select *from events;
+-----------+---------------------------+-------------------------------+-------------------------------+----------------------+------------+------------+------+----------------------+-------------------------------+-------------+-------------------------------+
| eventCode | title | artistname | description | type | startdate | enddate | time | venuename | venueaddress | telephone | url |
+-----------+---------------------------+-------------------------------+-------------------------------+----------------------+------------+------------+------+----------------------+-------------------------------+-------------+-------------------------------+
| 1 | ?><?php echo ?>
< | ?><?php echo ?>
<?php | ?><?php echo ?>
<?php | ?><?php echo ?>
| 0000-00-00 | 0000-00-00 | ?><? | ?><?php echo ?>
| ?><?php echo ?>
<?php | ?><?php ech | ?><?php echo ?>
<?php |
+-----------+---------------------------+-------------------------------+-------------------------------+----------------------+------------+------------+------+----------------------+-------------------------------+-------------+-------------------------------+
1 row in set (0.00 sec)

Do you see any problems??
thanks
tammy
 
Do you get any errors?
Can we see the code for the database_conn.php included file?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
you need to put quotes around the string values in the sql query.
 
No i dont get any errors in fact when i run it from the website it does nothing to the db now and it comes with a blank screen in the browser with done posted.

i have added quotes to the strings as follows :
" $sql = ("UPDATE events SET title = "$ntitle", artistname = "$nartistname", description = "$ndescription", type = "$ntype", startdate = "$nstartdate", enddate = "$nenddate", time = "$ntime", venuename = "$nvenuename", venueaddress = "$nvenueaddress", telephone = "$ntelephone", url = "$nurl", WHERE eventCode = "$neventCode"";)"

There is no need for the 'database_conn.php' to be posted as the connection is there
any other ideas?
thanks for your replies.
 
that is not going to work. change the double quotes around the values to single quotes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top