...

View Full Version : Error, Insert Query



pha357
05-04-2006, 03:39 AM
Greetings,

I sucessfully installed this event listing script. However, When I tried to post an event ad click submut the following error message appears:

Error, insert query failed


I figure something in the code is in error which I have pasted below:


<?php
include 'config.php';

// AUTHENTICATION
if (isset($_POST['pw']))
{
$pw = $_POST['pw'];
$_SESSION['pw'] = $pw;
}
elseif (isset($_GET['pw']))
{
$pw = $_GET['pw'];
$_SESSION['pw'] = $pw;
}
elseif (isset($_SESSION['pw']))
{
$pw = $_SESSION['pw'];
}

if ($pw == $adminpass)
{
include 'library/opendb.php';
include 'library/timeFunctions.php';
include 'library/displayFunctions.php';

// get variables from form post for which record to change, and what to do with it
$action = $_GET['action'];
$id = $_GET['id'];


// THE DELETE OPTION
if($action == 'delete')
{
// set up delete query
$query = "DELETE FROM events WHERE id =" . $id;
// do the query
mysql_query($query) or die('Error, query failed');

echo "event deleted successfully!<br><br><a href='admin.php'>add a new event</a>";
}

// THE ADD NEW OPTION
elseif (isset($_POST['add']) || isset($_POST['edit']))
{
// get date from form post
$date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
// get time from form post
$rawTime = $_POST['time'];
// convert time to MySQL format
if($rawTime > 11 )
{
$rawTime = '0';
}
$time = ($rawTime + $_POST['ampm']) . ':' . $_POST['minute'] . ':00';
// get showTime
$showTime = $_POST['showTime'];
// showTime to 1 or 0
if ($showTime == "on")
{
$showTime = 1;
}
else
{
$showtime = 0;
}
// get venue
$venue = $_POST['venue'];
// get description
$description = $_POST['description'];
// set up insert query
if (isset($_POST['add'])) {
$query = "INSERT INTO events (date, time, showTime, venue, description) VALUES ('$date', '$time', '$showTime', '$venue', '$description')";
}
elseif (isset($_POST['edit'])) {
// set up update query
$query = "UPDATE events SET date = '$date', time = '$time', showTime = '$showTime', venue = '$venue', description = '$description' WHERE id ='$id'";
}
// do the query
mysql_query($query) or die('Error, insert query failed');

echo "event updated successfully!<br><br><a href='admin.php'>add a new event</a>";
}




// ADD/EDIT FORM
else
{
// load stored values for editing event
if($action == 'edit')
{
$query = "SELECT * FROM events WHERE id='$id'";
$result = mysql_query($query);
$date = mysql_result($result,0,"date");
$time = mysql_result($result,0,"time");
$venue = mysql_result($result,0,"venue");
$description = mysql_result($result,0,"description");
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$year = substr($date, 0, 4);
$hour = realHour($time);
$minute = substr($time, 3, 2);
$ampm = realAMPM($time);
$showTime = mysql_result($result,0,"showTime");
}


?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">

<tr>
<td width="100">Date</td>
<td>

<select name="month" id="month">
<option value="01" <?php if ($month == "01") {echo "selected";} ?>>Jan
<option value="02" <?php if ($month == "02") {echo "selected";} ?>>Feb
<option value="03" <?php if ($month == "03") {echo "selected";} ?>>Mar
<option value="04" <?php if ($month == "04") {echo "selected";} ?>>Apr
<option value="05" <?php if ($month == "05") {echo "selected";} ?>>May
<option value="06" <?php if ($month == "06") {echo "selected";} ?>>Jun
<option value="07" <?php if ($month == "07") {echo "selected";} ?>>Jul
<option value="08" <?php if ($month == "08") {echo "selected";} ?>>Aug
<option value="09" <?php if ($month == "09") {echo "selected";} ?>>Sep
<option value="10" <?php if ($month == "10") {echo "selected";} ?>>Oct
<option value="11" <?php if ($month == "11") {echo "selected";} ?>>Nov
<option value="12" <?php if ($month == "12") {echo "selected";} ?>>Dec
</select>

<select name="day" id="day">
<option value="01" <?php if ($day == "01") {echo "selected";} ?>>1
<option value="02" <?php if ($day == "02") {echo "selected";} ?>>2
<option value="03" <?php if ($day == "03") {echo "selected";} ?>>3
<option value="04" <?php if ($day == "04") {echo "selected";} ?>>4
<option value="05" <?php if ($day == "05") {echo "selected";} ?>>5
<option value="06" <?php if ($day == "06") {echo "selected";} ?>>6
<option value="07" <?php if ($day == "07") {echo "selected";} ?>>7
<option value="08" <?php if ($day == "08") {echo "selected";} ?>>8
<option value="09" <?php if ($day == "09") {echo "selected";} ?>>9
<option <?php if ($day == "10") {echo "selected";} ?>>10
<option <?php if ($day == "11") {echo "selected";} ?>>11
<option <?php if ($day == "12") {echo "selected";} ?>>12
<option <?php if ($day == "13") {echo "selected";} ?>>13
<option <?php if ($day == "14") {echo "selected";} ?>>14
<option <?php if ($day == "15") {echo "selected";} ?>>15
<option <?php if ($day == "16") {echo "selected";} ?>>16
<option <?php if ($day == "17") {echo "selected";} ?>>17
<option <?php if ($day == "18") {echo "selected";} ?>>18
<option <?php if ($day == "19") {echo "selected";} ?>>19
<option <?php if ($day == "20") {echo "selected";} ?>>20
<option <?php if ($day == "21") {echo "selected";} ?>>21
<option <?php if ($day == "22") {echo "selected";} ?>>22
<option <?php if ($day == "23") {echo "selected";} ?>>23
<option <?php if ($day == "24") {echo "selected";} ?>>24
<option <?php if ($day == "25") {echo "selected";} ?>>25
<option <?php if ($day == "26") {echo "selected";} ?>>26
<option <?php if ($day == "27") {echo "selected";} ?>>27
<option <?php if ($day == "28") {echo "selected";} ?>>28
<option <?php if ($day == "29") {echo "selected";} ?>>29
<option <?php if ($day == "30") {echo "selected";} ?>>30
<option <?php if ($day == "31") {echo "selected";} ?>>31
</select>
,
<select name="year" id="year">
<option <?php if ($year == (date('Y') - 3)) {echo "selected";} echo ">" . (date('Y') - 3); ?>
<option <?php if ($year == (date('Y') - 2)) {echo "selected";} echo ">" . (date('Y') - 2); ?>
<option <?php if ($year == (date('Y') - 1)) {echo "selected";} echo ">" . (date('Y') - 1); ?>
<option <?php if (($year == date('Y')) OR (!isset($year))) {echo "selected";} echo ">" . date('Y'); ?>
<option <?php if ($year == (date('Y') + 1)) {echo "selected";} echo ">" . (date('Y') + 1); ?>
<option <?php if ($year == (date('Y') + 2)) {echo "selected";} echo ">" . (date('Y') + 2); ?>
<option <?php if ($year == (date('Y') + 3)) {echo "selected";} echo ">" . (date('Y') + 3); ?>
<option <?php if ($year == (date('Y') + 4)) {echo "selected";} echo ">" . (date('Y') + 4); ?>
</select>

</td>
</tr>
<tr>
<td width="100">Time</td>
<td>
<input name="time" type="text" id="time" size="2" maxlength="2" <?php if (isset($hour)) {echo "value=" . $hour;} ?>> :
<input name="minute" type="text" id="minute" size="2" maxlength="2" <?php if (isset($minute)) {echo "value=" . $minute;} else {echo "value='00'";} ?>>
<select name="ampm" id="ampm">
<option value="12" <?php if ($ampm == "PM") {echo "selected";} ?>>PM
<option value="0" <?php if ($ampm == "AM") {echo "selected";} ?>>AM
</select>
(show Time? <input name="showTime" type="checkbox" id="showTime" <?php if ($showTime) {echo "checked";} elseif (!isset($showTime)) {echo "checked";} ?>>)
</td>
</tr>
<tr>
<td width="100">Venue</td>
<td>
<textarea name="venue" id="venue" rows="5" cols="80"><?php if (isset($venue)) {echo $venue;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">Description</td>
<td>
<textarea name="description" id="description" rows="5" cols="80"><?php if (isset($description)) {echo $description;} ?></textarea>
</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>
<?php

if ($action == 'edit')
{
echo "<input name='edit' type='submit' id='edit' value='update event'>";
}
else
{
echo "<input name='add' type='submit' id='add' value='add event'>";
}
?>
</td>
</tr>
</table>
</form>
<?php
}
?>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
UPCOMING EVENTS
</td>
</tr>
<?php

$query = "SELECT * FROM events ORDER BY date, time";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
if ($row['date'] >= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}


?>
</table>
<BR>
<BR>
<table border="0" cellspacing="3">
<tr>
<td colspan="9" align="center" class="highlight">
PAST EVENTS
</td>
</tr>
<?php


$query = "SELECT * FROM events ORDER BY date DESC, time DESC";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{
if ($row['date'] <= date('Y-m-d'))
{
displayEvents($row);
displayActions($row);
}
}


include 'library/closedb.php';
}

// AUTHENTICATION FAILED
else
{
echo "Wrong password";
}
?>
</table>
<br />
<br />
<span class="small">VSEL v1.01 &copy;2006 <a href="http://ekittell.com" target="_blank">Eric Kittell</a>
</span>
</body>
</html>:)

ralph l mayo
05-04-2006, 06:45 AM
You can change the or die() messages to be more helpful, make then or die(mysql_error()) for debugging.

Also,


<select name="day" id="day">
<option value="01" <?php if ($day == "01") {echo "selected";} ?>>1
<option value="02" <?php if ($day == "02") {echo "selected";} ?>>2
<option value="03" <?php if ($day == "03") {echo "selected";} ?>>3
<option value="04" <?php if ($day == "04") {echo "selected";} ?>>4
<option value="05" <?php if ($day == "05") {echo "selected";} ?>>5
<option value="06" <?php if ($day == "06") {echo "selected";} ?>>6
<option value="07" <?php if ($day == "07") {echo "selected";} ?>>7
<option value="08" <?php if ($day == "08") {echo "selected";} ?>>8
<option value="09" <?php if ($day == "09") {echo "selected";} ?>>9
<option <?php if ($day == "10") {echo "selected";} ?>>10
<option <?php if ($day == "11") {echo "selected";} ?>>11
<option <?php if ($day == "12") {echo "selected";} ?>>12
<option <?php if ($day == "13") {echo "selected";} ?>>13
<option <?php if ($day == "14") {echo "selected";} ?>>14
<option <?php if ($day == "15") {echo "selected";} ?>>15
<option <?php if ($day == "16") {echo "selected";} ?>>16
<option <?php if ($day == "17") {echo "selected";} ?>>17
<option <?php if ($day == "18") {echo "selected";} ?>>18
<option <?php if ($day == "19") {echo "selected";} ?>>19
<option <?php if ($day == "20") {echo "selected";} ?>>20
<option <?php if ($day == "21") {echo "selected";} ?>>21
<option <?php if ($day == "22") {echo "selected";} ?>>22
<option <?php if ($day == "23") {echo "selected";} ?>>23
<option <?php if ($day == "24") {echo "selected";} ?>>24
<option <?php if ($day == "25") {echo "selected";} ?>>25
<option <?php if ($day == "26") {echo "selected";} ?>>26
<option <?php if ($day == "27") {echo "selected";} ?>>27
<option <?php if ($day == "28") {echo "selected";} ?>>28
<option <?php if ($day == "29") {echo "selected";} ?>>29
<option <?php if ($day == "30") {echo "selected";} ?>>30
<option <?php if ($day == "31") {echo "selected";} ?>>31
</select>


...lmao

mio
05-04-2006, 03:23 PM
I won't lmao but fortunately there is no 9k days in a month...
use this "trick" for your "option select"


echo "<select name=whateveruwant id=whateveruwant>";
for($i=1; $i<=31; $i++){
if($i==$month)
echo "<option value=$i selected=selected>$i</option>";
else
echo "<option value=$i>$i</option>";

}
echo "</select>"


then about the query error:
check this line


$query = "INSERT INTO events (date, time, showTime, venue, description) VALUES ('$date', '$time', '$showTime', '$venue', '$description')";
}

replace by


$query = "INSERT INTO events (date, time, showTime, venue, description) VALUES ('" . $date. "', '" . $time . "', '" . $showTime ." ', '" . $venue . "', '" . $description . "')";
}


:thumbsup:

pha357
05-08-2006, 04:50 AM
I changed the or die() messages to or die(mysql_error()) for debugging

and I got the following message back:

Table 'mysql.events' doesn't exist

harsh789
05-08-2006, 12:30 PM
you need to create table events. It seems you created table, but the database is different. Either create a table in mysql database or create different database and then create table events.

I recommend to create different database and create events table in it. And change the database name in your config file accordingly.

pha357
05-08-2006, 09:49 PM
The hosting service I'm using is Yahoo which isn't very user friendly in terms of databases and such. I wished the client would have had me handle the host set up instead of just grabbbing the first thing they found.

I ran the script installation and seemingly , based on its response, was installed successfully....but I don't think it was to be honest.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum