PDA

View Full Version : Insert data to a table



Syous
June 28th, 2007, 01:54 PM
For some reason this script isn't working. Anyone see anything wrong? config.php is just fine, the form just doesn't send information to my database at all...I don't even get an error message when submitting it.


<?
include("config.php");

$id = $_POST['id'];
$date = $_POST['date'];
$time = $_POST['time'];
$event = $_POST['event'];
$details = $_POST['details'];
$expiration = $_POST['expiration'];
?>

<form action="submit.php?loc=sent" method="post">
Date: <input type="text" name="date" size="8"><br><br>
Day and Time: <input type="text" name="time" size="8"><br><br>
Event: <input type="text" name="event" size="8"><br><br>
Details: <input type="text" name="details" size="8"><br><br>
Expiration: <input type="text" name="expiration" size="8"><br><br>
<input type="submit" value="Submit">
</form>

<?
if( $id and $date and $time and $event and $details )
{
include ("config.php");

$rs = @mysql_select_db( "newwine_admin" )
or die ( mysql_error() ) ;

$query1 = "DELETE from SCHEDULE where EXPIRATION<'$DATE'";
mysql_query($query1) or die(mysql_error());

$sql ="insert into schedule (ID, DATE, TIME, EVENT, DETAILS, EXPIRATION)
values ( $id, \"$date\", \"$time\", \"$event\", \"details\", \"$expiration\" ) ";

$rs = mysql_query( $sql );

if($rs) { echo( "Event Added: $date $time $event $details $expiration" )
or die( mysql_error() ) ; }
}
?>

simplistik
June 28th, 2007, 02:14 PM
if( $id and $date and $time and $event and $details )



if( $id && $date && $time && $event && $details )




$sql ="insert into schedule (ID, DATE, TIME, EVENT, DETAILS, EXPIRATION)
values ( $id, \"$date\", \"$time\", \"$event\", \"details\", \"$expiration\" ) ";



$sql ="insert into schedule (ID, DATE, TIME, EVENT, DETAILS, EXPIRATION)
values ( $id, '$date', '$time', '$event', '$details', '$expiration' ) ";

also make sure that:


ID, DATE, TIME, EVENT, DETAILS, EXPIRATION
are the actual names of the columns in your table, table names are case-sensitive...

Syous
June 28th, 2007, 02:24 PM
Included your changes, the field names in the table are spelled and capitalized correctly. Yet still the information does not show up in the database.

simplistik
June 28th, 2007, 02:46 PM
Well if i had paid more attention to what you were doing I wouldn't have made those changes to that if statement what you should have it looks like...


<input type="submit" name="submit" value="Submit" />




include ("config.php");

$id = $_POST['id'];
$date = $_POST['date'];
$time = $_POST['time'];
$event = $_POST['event'];
$details = $_POST['details'];
$expiration = $_POST['expiration'];
$submit = $_POST['submit'];

//...

if( $submit )
{

$rs = @mysql_select_db( "newwine_admin" )
or die ( mysql_error() ) ;

$query1 = "DELETE from SCHEDULE where EXPIRATION<'$DATE'";
mysql_query($query1) or die(mysql_error());

$sql ="insert into schedule (ID, DATE, TIME, EVENT, DETAILS, EXPIRATION)
values ( '$id', '$date', '$time', '$event', '$details', '$expiration' ) ";

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

also you have SCHEDULE and schedule... only one can be right...

Syous
June 28th, 2007, 02:55 PM
K made the changes, now I get this.

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 ' "7/04/2007", "monday 7:00pm", "Prayer", "details", "07/05/2007" )' at line 2

Syous
June 28th, 2007, 03:14 PM
Problem fixed. ID is set to autoincrement and needed to be taken out of values in the $sql query as well at the $_POST at the top.

simplistik
June 28th, 2007, 03:40 PM
Problem fixed. ID is set to autoincrement and needed to be taken out of values in the $sql query as well at the $_POST at the top.

Well... you don't need to remove it outta the post... just outta the sql query :) you can always use that for something else like... returning data or somethin or other :) :thumb2: