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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sagarchandratrey
Forum Newbie
Posts: 3
Joined: Tue Nov 05, 2002 3:34 am
Contact:

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

Post 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>
smesquita
Forum Newbie
Posts: 7
Joined: Wed Oct 23, 2002 5:53 am

Post by smesquita »

Your prod_id is a string!?!?
If not, have you tryed:

$mystring ="insert into product (prod_id,prod_name) values(2,'fridge')";
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

try

Post by AVATAr »

try:

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

check de ' and "
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: try

Post 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
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post 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.
sagarchandratrey
Forum Newbie
Posts: 3
Joined: Tue Nov 05, 2002 3:34 am
Contact:

It worked

Post by sagarchandratrey »

Thanks friends,
It worked !!!!1
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

problem?

Post by AVATAr »

What was the problem?
Post Reply