...

View Full Version : Code working but database keeps blank space



bunty20077
11-25-2011, 07:34 AM
This is my Code which just take names from customer and place it in databases.What i am seeing is that the code working fine,Showing echo message also but in database i created 2 field 1 auto incremented id and other for name.the id is generated but the name field remains blank..please help me.
PHP Code:
<?php

$link = mysql_connect("localhost","root","");
if (! $link) {
die('cannot connect: ' .mysql_error() ) ;
}
$db_selected = mysql_select_db ("adform",$link );
if(!$db_selected){
die('cannot use :' .mysql_error() ) ;
}

$value = $_POST['firstname'];

$sql ="INSERT INTO demo (firstname) VALUES ('$value')" ;

if(!mysql_query($sql) ) {
die ('Error :' . mysql_error());
}
echo "record added to database ";
mysql_close ($link);
?>

djm0219
11-25-2011, 09:23 AM
Try changing



if(!mysql_query($sql) ) {
die ('Error :' . mysql_error());
}
to


mysql_query($sql,$link) or die(mysql_error());

and see what you get.

Old Pedant
11-26-2011, 12:11 AM
But *FIRST* try DEBUGGING!



$sql ="INSERT INTO demo (firstname) VALUES ('$value')" ;

echo "<hr/>DEBUG SQL: " . $sql . "<hr/>\n";

...

Make sure that you really *are* putting in values. Maybe it's the PHP code with the problem.

********

DJM: I really don't see why your suggestion would matter. He says that records are being created (else why would the autoincrement field be there?). I strongly suspect he simply has no data to insert.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum