Just copy your page and remove the sensitive data. Might be a problem on that page if you cannot connect…
It really cant be cus im using that connect file for another script thats working, anyways here it is.
<?php
define('DB_USER', '*******');
define('DB_PASSWORD', '*******');
define('DB_HOST', 'localhost');
define('DB_NAME', '********');
$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) OR die('Could not select the database:' . mysql_error());
?>
Whats the table “calendar” like? ie. What is the insert SQL so we can see the table layout.
the fields it has are:
id, date, subject, content, image
Im not inserting anything for id, its auto increment, should i be inserting something for it?
Insert a blank field like this:
$query = “INSERT INTO calendar VALUES (’’, ‘$date1 . $date2 . $date3’ , ‘$subject’ , ‘$content’ , ‘$image’)”;
If you have the same number of columns listed you don’t need to designate the columns. They just need to match order. But for auto incrementing columns you just use single quotes to designate auto increment…
k, thanks man, ill check and see if that works.
still not working, im getting the system error contact nathan message on the else statement.
here is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>calendar update</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#000000" leftmargin="0" topmargin="0">
<table width="780" height="297" border="0" cellpadding="0" cellspacing="0" bgcolor="#00A0DE">
<tr>
<td height="102"><div align="center"><span class="style1">
<?php
require_once 'mysql_connect.php';
if ( isset($_POST['Submit']) ){
$subject = trim($_POST['subject']);
$content = trim($_POST['content']);
$date1 = $_POST['date1'];
$image = trim($_POST['image']);
if($subject == ""){
echo 'You forgot the subject';
@mysql_close();
exit();
}
if($content == ""){
echo 'You forgot the content';
@mysql_close();
exit();
}
$sql = "INSERT INTO calendar (id, date, subject, content, image) VALUES ('' , '$date1' , '$subject' , '$content' , '$image')";
if ($result = @mysql_query($sql)){
echo 'Event successfully entered!!!';
@mysql_close();
exit();
}else{
echo 'System Error, Contact Nathan, Sorry ;)';
@mysql_close();
}
}else{
echo 'Please Try Again';
}
?>
</span></div></td>
</tr>
</table>
</body>
</html>
bump
Try it without the column identifiers…
INSERT INTO calendars VALUES (’’ , ‘$date1’ , ‘$subject’ , ‘$content’ , ‘$image’)
I don’t think you need to include a blank id. I’m just learning php too, but I wrote an insert statement. What I would try is printing out the statement before you run the query.
Also I forgot to mention, run the query either cli or phpMyAdmin to check and make sure it works. if it doesn’t, then something is wrong with the query. If it does, then you know…
You don’t need to include a column if you declare the columns before the VALUE.
Ive printed out a statement already and it works. Ive also ran an insert query and it worked too. Im seriously confused on whats the problem here
Change this:
if ($result = @mysql_query($sql)){
echo 'Event successfully entered!!!';
@mysql_close();
exit();
}else{
echo 'System Error, Contact Nathan, Sorry ;)';
@mysql_close();
}
to:
$result = @mysql_query($sql);
$n = @mysql_affected_rows();
if ($n == 1){
echo 'Event successfully entered!!!';
@mysql_close();
exit();
}else{
echo 'System Error, Contact Nathan, Sorry ;)';
@mysql_close();
}
Also a thing I do is set in a config file a variable to turn debugging on and off.
(in config file:)
$debug = true; // set to false when live
Then thru out my pages I echo variables to see what they are as I go. You see the results…
So for instance you can do this:
$result = @mysql_query($sql);
$n = @mysql_affected_rows();
if ($n == 1){
echo 'Event successfully entered!!!';
@mysql_close();
exit();
}else{
echo 'System Error, Contact Nathan, Sorry ;)';
@mysql_close();
}
if ($debug) {
echo $sql."<br />";
echo $result."<br />";
echo $n."<br />";
}
And you should see what the values are against what they should be. This will pinpoint where the script is failing… Then when you go live just change $debug to false while still keeping the debugging values in there.
in case that didnt do it yet.
--> @mysql_query($sql);
--> @mysql_affected_rows();
#remove the @
thx ill try it;)
That will show the db errors if any, later on ill take a closer look at ure form and ill post something back (today)
what exactly does the @ do?
well i would say try it…
make a fake query with some wrong fields use it one time with @ and one time without
in both cases use die (mysql_error());
still doesnt work
here is my form page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>calendar update</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#000000" leftmargin="0" topmargin="0">
<div id="Layer2" style="position:absolute; left:14px; top:-8px; width:654px; height:223px; z-index:2">
<form name="form1" method="post" action="calendarinsert.php">
<p align="center"><br>
<br>
<span><strong>Calendar Update Page </strong> </span></p>
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td >Date : </td>
<td ><select name="date1" id="date1">
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sep</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<select name="date2" id="date2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="date3" id="date3">
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
</select></td>
</tr>
<tr>
<td >Subject:</td>
<td ><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td >Content:</td>
<td ><textarea name="content" cols="50" rows="4" id="content"></textarea></td>
</tr>
<tr>
<td >Image Name(include extention):</td>
<td ><input name="image" type="text" id="image" size="25"></td>
</tr>
<tr>
<td > </td>
<td ><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
<p>Remember the image needs to be uploaded before you will be able to see it. </p>
<p><br>
</p>
</form>
</div>
<table width="780" height="297" border="0" cellpadding="0" cellspacing="0" bgcolor="#00A0DE">
<tr>
<td height="102"><div align="center"><span class="style4 style3 style11"><br>
<br>
</span></div></td>
</tr>
</table>
<?php
include ('templates/links.inc');
?>
</body>
</html>
Here is my insert page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>calendar update</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#000000" leftmargin="0" topmargin="0">
<table width="780" height="297" border="0" cellpadding="0" cellspacing="0" bgcolor="#00A0DE">
<tr>
<td height="102"><div align="center"><span class="style1">
<?php
require_once '../mysql_connect.php';
if ( isset($_POST['Submit']) ){
$subject = trim($_POST['subject']);
$content = trim($_POST['content']);
$date1 = $_POST['date1'];
$image = trim($_POST['image']);
if($subject == ""){
echo 'You forgot the subject';
mysql_close();
exit();
}
if($content == ""){
echo 'You forgot the content';
mysql_close();
exit();
}
$sql = "INSERT INTO calendar (date, subject, content, image) VALUES('$date1' , '$subject' , '$content' , '$image')";
$result = mysql_query($sql);
$n = mysql_affected_rows();
if ($n == 1){
echo 'Event successfully entered!!!';
mysql_close();
exit();
}else{
echo 'System Error, Contact Nathan, Sorry ;)';
mysql_close();
}
}else{
echo 'Please Try Again';
}
?>
</span></div></td>
</tr>
</table>
</body>
</html>
thanks for the help;)
what does print_r($POST); //return
And agian ill take a closer look at the form later on… little busy @ moment lol