icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » PHP - Inserting into database problem

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old October 18th, 2005, 12:21 AM   #1 (permalink)
Registered User
Fresh Surpasser
 
JennyLP01's Avatar
 
Joined in Jan 2005
3 posts
Gave thanks: 0
Thanked 0 times
PHP - Inserting into database problem

I've finally decided to come here for help. I am completly lost in what I'm doing wrong. I've got a script that inserts news into a database for my website. It has worked fine up until I moved servers and am now running with MySQL 4.1.13, which I think it might be a problem with the collation (?) of the db. If anyone has any ideas it would be greatly appreciated.

My problem is after running the form, my information does not get inserted into my database. It doesn't give me any errors, it just doesn't work.

Here is the code I'm using. I'm not a PHP guru, but it works on other servers with MySQL vs. < 4.1.13

Code:
<form method="post" action="<? echo $PHP_SELF ?>">
<table width="435px">
	<tr>
		<td width="135px" align="right" class="fine-print">
<b>Article Title:</b> 
		</td>
		<td width="300px" align="left">
<input type="text" name="title">
		</td>
	</tr>
	<tr>
		<td align="center" colspan="2">
<textarea cols="37" rows="8" name="entry"></textarea>
		</td>
	</tr>
	<tr>
		<td align="center" colspan="2">
<input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset">
		</td>
	</tr>
</table>

</form>

<?php
if($submit) {

$date= strtotime("now");
$entry= nl2br($entry);

$connect=mysql_connect ("localhost", "user", "passhere") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

$sql = "INSERT INTO news (id,date,title,entry) VALUES ('$id','$date','$title','$entry')";
$result = mysql_query($sql) or print ("Can't insert into table.<br />" . $sql . "<br />" . mysql_error());

if ($result != false)
{
print "Your entry has successfully been entered into the database!";
}

mysql_close();
}

?>

Last edited by JennyLP01; October 18th, 2005 at 12:23 AM.. Reason: I didn't explain the problem...
JennyLP01 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 18th, 2005, 12:30 AM   #2 (permalink)
Surpass Fan
Super #1
 
Joined in Aug 2004
Hosted on SH58
1,688 posts
Gave thanks: 6
Thanked 7 times
You should not be using if( $submit ){ ... }. Try using if( isset( $_POST['submit'] ) ){ ... }
__________________
- Evan Charlton | [site] | Server - SH58
Kickersny.com is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 18th, 2005, 12:38 AM   #3 (permalink)
Registered User
Fresh Surpasser
 
JennyLP01's Avatar
 
Joined in Jan 2005
3 posts
Gave thanks: 0
Thanked 0 times
Wow I feel stupid sometimes. It works... Thank you very much!
JennyLP01 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 18th, 2005, 12:52 AM   #4 (permalink)
Surpass Fan
Super #1
 
Joined in Aug 2004
Hosted on SH58
1,688 posts
Gave thanks: 6
Thanked 7 times
You're welcome.

Looking back on the script, change $PHP_SELF to $_SERVER['PHP_SELF']

(more information)
__________________
- Evan Charlton | [site] | Server - SH58
Kickersny.com is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 18th, 2005, 12:56 AM   #5 (permalink)
Registered User
Fresh Surpasser
 
JennyLP01's Avatar
 
Joined in Jan 2005
3 posts
Gave thanks: 0
Thanked 0 times
Alright, thanks again. If you read this again, I just realized some of my problem is gone. It is inserting the date into the database, but not 'title' and 'entry'. Any idea?

Last edited by JennyLP01; October 18th, 2005 at 12:58 AM..
JennyLP01 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 18th, 2005, 1:10 AM   #6 (permalink)
Surpass Fan
Super #1
 
Joined in Aug 2004
Hosted on SH58
1,688 posts
Gave thanks: 6
Thanked 7 times
Well, for those variables you should also have $_POST['title'] and $_POST['entry'] (as well as the other form variables).

Regarding the actual SQL statement, field names should be enclosed in `backticks`.
__________________
- Evan Charlton | [site] | Server - SH58
Kickersny.com is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On