Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL - no errors, but no connection made

         

ahndymac

12:27 am on Nov 13, 2003 (gmt 0)

10+ Year Member



So this was working, I changed the language and time area to en_US and everything stopped. I'm freaking baffled. Any ideas?

No errors, but it doesn't insert anything into the database!

<?php

$dbhost = "localhost";
$db = "pics";
$dbuser = "bob";
$dbpasswd = "password";
$table = "comments";

//local settings
setlocale(LC_TIME, en_US); //set to your localization, currently German
$tid = strtotime('now'); // makes UNIX timepstamp of current time

//end edit!

// set variables
$ikke_tom = 0;
$url = $_GET['url'];

//connects to daqtabase
$link = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Could not connect: " . mysql_error());
mysql_select_db($db, $link) or die ('Can\'t use $db : ' . mysql_error());

//if you have posted the form this is performed:
if (isset($_POST['date'])) {

//gets the variables from the form and inserts them into PHP variables
$date = $_POST['date'];
$forfatter = $_POST['forfatter'];
$url = $_POST['url'];
$comment = $_POST['comment'];

//MySql query to insert comment into database
$settin = "INSERT INTO `$table` (`date`, `forfatter`, `id`, `comment`)
VALUES ('$date', '$forfatter', '$url', '$comment')" ;
mysql_query($settin);

//end of MySql query
echo 'Thank you for adding your comment<br>'; // this is a message to thank the user for inserting his comment
echo '<a href="javascript:window.close();">close window</a>'; // and asking the user to close the window (currently written in norwegian
}

// If the form has not been posted yet, the form must bee displayed
else {
?>
<form name="form1" method="post" action="<?php echo $PHP_SELF?>">
<font size="-1" face="Verdana, Arial, Helvetica, sans-serif"> Name:<br>
<input name="forfatter" type="text" size="50">
</font> <br>
Comment:<br>
<textarea name="comment" cols="40" rows="5" wrap="VIRTUAL"></textarea>
<br>
<input type="submit" name="Submit" value="O K ">
<input type="reset" name="Submit2" value="R E S E T">
<input name="date" type="hidden" id="date" value="<?php echo strftime('%A, %d. %B, %Y - %X')// this is the date variable, with local formatting and language according to the setlocale in the begging of the file?>">
<input name="url" type="hidden" value="<?php echo $_GET['url']?>">
</form>
<?php
}
?>

jatar_k

12:37 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld ahndymac,

If there is no error then I would guess at the error coming from mysql but not being passed on by php.

try or die statements on all your mysql calls and see if you can get an error to spit out.

mysql_query($settin) or die ("<p>INSERT:<br>" . mysql_error() [ca.php.net]);

or something like that

ahndymac

2:29 am on Nov 13, 2003 (gmt 0)

10+ Year Member



Dude - good call.

I trapped the error from MySQL, I *stupidly* failed to set the index to autoincrement.

That would explain the problem!

Thanks again.

--Andrew

jatar_k

2:48 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when I am in the dev stage I usually use "or die" statements on pretty much everything. Then before I put them live I, either, remove them or handle all possible errors and log them. It all depends on the environment.