Page 1 of 1

Output problem

Posted: Wed Jan 28, 2004 6:38 pm
by John Cartwright

Code: Select all

<?php
 <?php 

include("mysql.php"); 
include("header.php"); 

echo "<div align="center">"
	."<form action="{$_SERVER['PHP_SELF']}"\n"
	."<p>Type your Date here: eg. 2004-01-31 (y-m-d)<br/>\n" 
	."<input type="text" name="date" cols="40"><br>\n"
	."<p>Is this Upcoming or Past eg. Upcoming OR Past<br/>\n" 
	."<input type="text" name="uppast" cols="40"><br>\n"	
	."<p>Please enter the filename of the flyer eg. flyer24.jpg<br/>\n" 
	."<input type="text" name="pic" cols="40"><br>\n"
	."<p>Type your Description here here:<br/>\n" 
	."<textarea name="desc" rows="10" cols="40" wrap></textarea><br/>\n" 
	."<input type="submit" name="submitevents" value="SUBMIT" /></p>\n" 
	."</form>\n"
	."</div>";
echo "<div align="center"><strong>NOTE - </strong>To go to the next line type in < br > (without the spaces between < ) </div><br><br>";

//adding to the database
if ($submitevents == "SUBMIT") { 
  $sql = "INSERT INTO events SET date='$date', desc='$desc'";
if (@mysql_query($sql)) { 
    echo("<div align="center">Your Event has been added.</div>"); 
  } else { 
    echo ("<div align="center">Error adding submitted Event: " . mysql_error() . "</div>"); 
  } 
}
//deleting from the database
if (isset($deleteevents)) { 
      $sql = "DELETE FROM events WHERE id=$deleteevent"; 
      if (@mysql_query($sql)) { 
        	echo("<div align="center">The event has been deleted.</div>"); 
      }else{ 
        echo("<p>Error deleting event: " . mysql_error() . "</p>"); 
  } 
} 
//preparing data from database
$result = @mysql_query("SELECT * FROM events ORDER BY `date` ");

while ($row = mysql_fetch_array($result)) { 
   
	$newdate = explode("-",$row["date"]); 
	$month = $newdate[1]; // eg. February 
    $day = $newdate[2]; // eg. 04 
    $year = $newdate[0]; // eg. 2004 
    $id =  $row["id"];
	$desc = $row["desc"];

echo "<table width="668" border="0" cellpadding="0" cellspacing="0">\n"
    ."<tr>\n"
    ."<td width="22%" height="20">Date</td>\n"
    ."<td width="26%">Description</td>\n"
    ."<td width="32%">Location</td>\n"
    ."<td width="20%">Flyer</td>\n"
    ."</tr>\n"
	."<tr>\n"
    ."<td width="22%" height="20">".$month.$year."</td>\n"
    ."<td width="26%">".$desc."</td>\n"
    ."<td width="32%">".$location."</td>\n"
    ."<td width="20%">".$pic."</td>\n"
    ."</tr>\n"
    ."</table>\n"
	."<br><br>\n";
 } 
?>
?>
I'm getting the error:
Error adding submitted Event: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='fdsfd'' at line 1
This is what's causing the problem ( I believe )

Code: Select all

<?php  $sql = "INSERT INTO events SET date='$date', desc='$desc'";
?>
But the thing is I have the same code on other pages without causing any problems :S

Posted: Wed Jan 28, 2004 6:45 pm
by Weirdan
desc is reserved word. You need to quote it with backticks (`) if you're going to use it as field name.

Code: Select all

INSERT INTO events SET date='$date', `desc`='$desc'

Posted: Wed Jan 28, 2004 6:45 pm
by dull1554
replace "INSERT INTO events SET date='$date', desc='$desc'" with

Code: Select all

"INSERT INTO users (date, desc) VALUES('$date', '$desc')"
that should do it

Posted: Wed Jan 28, 2004 6:57 pm
by John Cartwright
wow I'm really stupid... I starred at that code for about 30 min going wtf is wrong with it :S......................

Much appreciated guys :D

Posted: Wed Jan 28, 2004 6:59 pm
by dull1554
glad it works.....no prob.....

Posted: Wed Jan 28, 2004 7:01 pm
by John Cartwright
dull1554 wrote:replace "INSERT INTO events SET date='$date', desc='$desc'" with

Code: Select all

"INSERT INTO users (date, desc) VALUES('$date', '$desc')"
that should do it
That didn't work...but the first one did .. TY again