Page 1 of 1

oooooooooooops....where does the data go ????

Posted: Tue Nov 05, 2002 3:34 am
by sagarchandratrey
Hello all,
I have written s imple script to insert a row into a table ..In the browser it confirms the data insertion ..but when i go to the backend to check if the data has been inserted properly..theres no data..whats the problem.

heres the code :

Code: Select all

<html>
<body>
<?php

if ($dblink=mysql_connect("localhost","root",""))
{
	echo "conected";

	mysql_select_db("test",$dblink);

	$mystring ="insert into product (prod_id,prod_name) values('2','fridge')";

	if (mysql_query($mystring,$dblink))
	{

	echo "inserted <br> ";
	mysql_query("commit");
	}
	else
	{
		echo "could not insert";
	}


}
else
{
	echo "disconected";

}
?>
</body>
</html>

Posted: Tue Nov 05, 2002 3:54 am
by smesquita
Your prod_id is a string!?!?
If not, have you tryed:

$mystring ="insert into product (prod_id,prod_name) values(2,'fridge')";

try

Posted: Tue Nov 05, 2002 5:13 am
by AVATAr
try:

$mystring ='insert into product (prod_id,prod_name) values(2,"fridge")';

check de ' and "

Re: try

Posted: Tue Nov 05, 2002 5:27 am
by twigletmac
smesquita wrote:Your prod_id is a string!?!?
If not, have you tryed:

$mystring ="insert into product (prod_id,prod_name) values(2,'fridge')";
It shouldn't make a difference to MySQL whether you put that number into quotes or not.
AVATAr wrote:try:

$mystring ='insert into product (prod_id,prod_name) values(2,"fridge")';

check de ' and "
Changing the single and double quotes will definitely make no difference whatsoever, in fact in SQL it is better to use the syntax that sagarchandratrey had already - whole statement encompassed in double quotes and elements within in single quotes.

sagarchandratrey -> why not try some debugging using mysql_error() and or die() to pinpoint if there are any errors that MySQL can report:

Code: Select all

<?php 
@mysql_connect('localhost', 'root', '') or die(mysql_error());
echo 'DEBUG -> connected to database<br />';

@mysql_select_db('test') or die(mysql_error());
echo 'DEBUG -> database `test` selected<br />';

$sql = "INSERT INTO product (prod_id, prod_name) VALUES (2, 'fridge')";
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
echo 'DEBUG -> query "'.$sql.'" worked<br />';
?>
Are you using transactions safe tables?

Mac

Posted: Tue Nov 05, 2002 5:37 am
by DeGauss
If it still fails to work, try doing a straight connection to mysql instead of assigning it to a variable.

If THAT doesn't work... Then uhh... I dunno.

It worked

Posted: Tue Nov 05, 2002 7:45 am
by sagarchandratrey
Thanks friends,
It worked !!!!1

problem?

Posted: Tue Nov 05, 2002 9:49 am
by AVATAr
What was the problem?