View Full Version : admin panel help - editing data
llorax
04-03-2007, 09:02 PM
I'm still new to this whole PHP thing and Ive essentially created a form where if you type in the date listed in the database, it will display the events information and give you the option to edit.
Below is the code that I have constructed for the page that displays the information based on examples and tutorials.
I get an error message on the 18th line which talks about "$current_???_html .= "$current_???_html" I just put the ?? there because I figured this code is needed but Im not sure what it means or what it is suppose to be coded as. Can anyone explain this and help me get my code working. Thanks in advance!
<?php
include 'session.inc.php';
include 'config.inc.php';
include 'db.inc.php';
$link = db_connect();
if ($_POST != '')
$id = $_POST['hid'];
else
$id = $_GET['id'];
$query = "SELECT ('$date','$venue','$location','$information') FROM showdates;
$result = db_query($query, $link);
if (mysql_num_rows($result)) {
$current_horses_html = "<table cellpadding=1 cellspacing=2 width=99% border=0><tr align='center' bgcolor='#cccccc'><td><B>Date</B></td><td><B>Venue</B></td><td><B>Location</B></td><td><B>Information/B></td><td colspan='2'><B>Action</B></td></tr>";
while (list($id, $date, $venue, $location, $information) = mysql_fetch_array($result)) {
$current_showdates_html .= "<tr bgcolor=#FFFFFF align=center><td>$date</td><td>$venue</td><td>$location</td><td>$information</td><td><a href='edit.php?id=$id'>Edit</a></td></tr>";
}
$current_???_html .= "<tr><td></td><td></td></tr></table>";
} else {
$current_???_html = '<p>Show does not exist. Please try again.</p>';
}
if (isset($_GET['err_msg'])) {
$err_msg = $_GET['err_msg'];
if (!empty($err_msg)) {
echo "<p><b>Error</b>:<br>$err_msg</p>";
}
}
?>
<html>
<head>
<title></title>
<link href=../admin/rustedshows.css rel=stylesheet type="text/css">
</head>
<body>
<center><img src="images/banner.jpg" border=0></center>
<br>
<table border=0 width=55% bgcolor="#BEC9D4" cellpadding=0 cellspacing=0 align=center style="border:1px solid #000;">
<tr>
<td style="padding:12px;"><h3>Update Show Details</h3></UL>
<form action="../admin/edit.php" method="post" name="Update Show Details" id="Update Show Details">
<?=$current_???_html?>
</form>
<p><br>
<a href="../admin/?logout">Logout</a> | <a href="update.php">Update Another Show</a> | <a href="admin.php">Back to Main Page</a></td>
</tr>
</table>
<center>
Design © Llora McGrath 2007</center>
</body>
</html>
thetestingsite
04-03-2007, 11:36 PM
Well, I see a couple of things that is wrong with the code (and anyone of these could cause the error message.
<?php
include 'session.inc.php';
include 'config.inc.php';
include 'db.inc.php';
$link = db_connect();
if ($_POST != '')
$id = $_POST['hid'];
else
$id = $_GET['id'];
$query = "SELECT ('date','venue','location','information') FROM showdates";
$result = db_query($query, $link);
if (mysql_num_rows($result)) {
$current_horses_html = "<table cellpadding=1 cellspacing=2 width=99 border=0><tr align='center' bgcolor='#cccccc'><td><B>Date</B></td><td><B>Venue</B></td><td><B>Location</B></td><td><B>Information/B></td><td colspan='2'><B>Action</B></td></tr>";
while (list($id, $date, $venue, $location, $information) = mysql_fetch_array($result)) {
$current_horses_html .= "<tr bgcolor=#FFFFFF align=center><td>$date</td><td>$venue</td><td>$location</td><td>$information</td><td><a href='edit.php?id=$id'>Edit</a></td></tr>";
}
$current_horses_html .= "<tr><td></td><td></td></tr></table>";
} else {
$current_horses_html = '<p>Show does not exist. Please try again.</p>';
}
if (isset($_GET['err_msg'])) {
$err_msg = $_GET['err_msg'];
if (!empty($err_msg)) {
echo "<p><b>Error</b>:<br>$err_msg</p>";
}
}
?>
<html>
<head>
<title></title>
<link href=../admin/rustedshows.css rel=stylesheet type="text/css">
</head>
<body>
<center><img src="images/banner.jpg" border=0></center>
<br>
<table border=0 width=55% bgcolor="#BEC9D4" cellpadding=0 cellspacing=0 align=center style="border:1px solid #000;">
<tr>
<td style="padding:12px;"><h3>Update Show Details</h3></UL>
<form action="../admin/edit.php" method="post" name="Update Show Details" id="Update Show Details">
<?=$current_horses_html?>
</form>
<p><br>
<a href="../admin/?logout">Logout</a> | <a href="update.php">Update Another Show</a> | <a href="admin.php">Back to Main Page</a></td>
</tr>
</table>
<center>
Design © Llora McGrath 2007</center>
</body>
</html>
Anyways, that is your code that has been editted, and it should work (according to the syntax).
Hope this helps.
llorax
04-04-2007, 02:16 AM
but why should it say horses? What is that referring to?
thetestingsite
04-04-2007, 02:19 AM
This variable:
$current_horses_html
could be whatever you want it to be (as long as you keep it the same throughout your script). In other words, you could name it anything and it will still work (as long as you replace all occurrences of the old variable in the script).
Hope this helps.
llorax
04-04-2007, 02:51 AM
now im getting this error:
Could not send query: Operand should contain 1 column(s)
thetestingsite
04-04-2007, 02:57 AM
Sorry, completely overlooked this part:
$query = "SELECT ('$date','$venue','$location','$information') FROM showdates";
Remove the parts in red (I also editted the code I editted for you originally).
Hope this helps
llorax
04-04-2007, 08:16 PM
I believe I edited everything you suggested and I'm still getting the same error message.
<?php
include 'session.inc.php';
include 'config.inc.php';
include 'db.inc.php';
$link = db_connect();
if ($_POST != '')
$id = $_POST['hid'];
else
$id = $_GET['id'];
$query = "SELECT ('date','venue','location','information') FROM showdates";
$result = db_query($query, $link);
if (mysql_num_rows($result)) {
$current_shows_html = "<table cellpadding=1 cellspacing=2 width=99 border=0><tr align='center' bgcolor='#cccccc'><td><B>Date</B></td><td><B>Venue</B></td><td><B>Location</B></td><td><B>Information/B></td><td colspan='2'><B>Action</B></td></tr>";
while (list($id, $date, $venue, $location, $information) = mysql_fetch_array($result)) {
$current_shows_html .= "<tr bgcolor=#FFFFFF align=center><td>$date</td><td>$venue</td><td>$location</td><td>$information</td><td><a href='edit.php?id=$id'>Edit</a></td></tr>";
}
$current_shows_html .= "<tr><td></td><td></td></tr></table>";
} else {
$current_shows_html = '<p>Show does not exist. Please try again.</p>';
}
if (isset($_GET['err_msg'])) {
$err_msg = $_GET['err_msg'];
if (!empty($err_msg)) {
echo "<p><b>Error</b>:<br>$err_msg</p>";
}
}
?>
<html>
<head>
<title></title>
<link href=../admin/rustedshows.css rel=stylesheet type="text/css">
</head>
<body>
<center><img src="images/textbanner.gif" border=0></center>
<br>
<table border=0 width=55% bgcolor="#BEC9D4" cellpadding=0 cellspacing=0 align=center style="border:1px solid #000;">
<tr>
<td style="padding:12px;"><h3>Update Show Details</h3></UL>
<form action="../admin/edit.php" method="post" name="Update Show Details" id="Update Show Details">
<?=$current_shows_html?>
</form>
<p><br>
<a href="../admin/?logout">Logout</a> | <a href="update.php">Update Another Show</a> | <a href="admin.php">Back to Main Page</a></td>
</tr>
</table>
<center>
Design © Llora McGrath 2007</center>
</body>
</html>
thetestingsite
04-04-2007, 08:33 PM
Question, do you have a function in any of these files:
session.inc.php,
config.inc.php,
db.inc.php
that has a function named "db_query()"?
If not, then you may want to try changing this line:
$result = db_query($query, $link);
to this:
$result = mysql_query($query, $link);
Hope this helps.
llorax
04-04-2007, 08:38 PM
my db inc file does include that function:
<?php
function db_connect() {
global $cfg;
$link = mysql_connect($cfg['db_server'], $cfg['db_user'], $cfg['db_pass']) or die("Could not connect: " . mysql_error());
mysql_select_db($cfg['db_name']) or die("Could not select database: " . mysql_error());
return $link;
}
function db_query($query, $link) {
$result = mysql_query($query, $link) or die("Could not send query: " . mysql_error());
return $result;
}
function db_close($result, $link) {
/* Free resultset */
if (isset($result)) {
mysql_free_result($result);
}
/* Closing connection */
mysql_close($link);
}
?>
thetestingsite
04-04-2007, 08:45 PM
Ok, I'm going to try this once again.
<?php
include 'session.inc.php';
include 'config.inc.php';
include 'db.inc.php';
$link = db_connect();
if ($_POST != '')
$id = $_POST['hid'];
else
$id = $_GET['id'];
$query = "SELECT (`date`,`venue`,`location`,`information`) FROM showdates";
$result = db_query($query, $link);
if (mysql_num_rows($result)) {
$current_shows_html = "<table cellpadding=1 cellspacing=2 width=99 border=0><tr align='center' bgcolor='#cccccc'><td><B>Date</B></td><td><B>Venue</B></td><td><B>Location</B></td><td><B>Information/B></td><td colspan='2'><B>Action</B></td></tr>";
while (list($id, $date, $venue, $location, $information) = mysql_fetch_array($result)) {
$current_shows_html .= "<tr bgcolor=#FFFFFF align=center><td>$date</td><td>$venue</td><td>$location</td><td>$information</td><td><a href='edit.php?id=$id'>Edit</a></td></tr>";
}
$current_shows_html .= "<tr><td></td><td></td></tr></table>";
} else {
$current_shows_html = '<p>Show does not exist. Please try again.</p>';
}
if (isset($_GET['err_msg'])) {
$err_msg = $_GET['err_msg'];
if (!empty($err_msg)) {
echo "<p><b>Error</b>:<br>$err_msg</p>";
}
}
?>
<html>
<head>
<title></title>
<link href=../admin/rustedshows.css rel=stylesheet type="text/css">
</head>
<body>
<center><img src="images/banner.jpg" border=0></center>
<br>
<table border=0 width=55% bgcolor="#BEC9D4" cellpadding=0 cellspacing=0 align=center style="border:1px solid #000;">
<tr>
<td style="padding:12px;"><h3>Update Show Details</h3></UL>
<form action="../admin/edit.php" method="post" name="Update Show Details" id="Update Show Details">
<?=$current_shows_html?>
</form>
<p><br>
<a href="../admin/?logout">Logout</a> | <a href="update.php">Update Another Show</a> | <a href="admin.php">Back to Main Page</a></td>
</tr>
</table>
<center>
Design © Llora McGrath 2007</center>
</body>
</html>
Notice the parts in red in the query. This should do it. Hope this helps.
llorax
05-14-2007, 03:37 PM
I have tried the code with and without the single quotes and there is the same column error either way. Is there another possible problem??
thetestingsite
05-20-2007, 01:44 AM
Sorry for the belated response, but try changing this:
$query = "SELECT (`date`,`venue`,`location`,`information`) FROM showdates";
to this:
$query = "SELECT * FROM showdates";
in the code to see if that fixes the problem.
Hope this helps; and again, sorry for the late reply.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.