| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (permalink) |
|
Registered User
Fresh Surpasser
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... |
|
|
|
|
|
#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 |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Fresh Surpasser
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.. |
|
|
|
|
|
#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 |
|
|
|