I don´t understand the error:


Parse error: syntax error, unexpected T_VARIABLE in /home/eduardli/public_html/web_designer/insert.php on line 21

php file:

<html>
<body>

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("eduardli_company", $con);


mysql_query ("INSERT INTO Products (Description, Price, Quantity)  
VALUES ('$description', '$price', '$quantity')");

mysql_query("SELECT*FROM Products='"$result"'");                  

while($row = mysql_fetch_array($result))
{
echo $row['Description'] . " " . $row['Price'] . " " . $row['Quantity'];
echo "<br />";
}

mysql_close($con);
?>

</body>
</html

form.html:

<html>
<head>
<style type="text/css">

#desc
{
width:10%;
height:5%;
}
</style>
<title>POST</title>
</head>

<body>


<form action='insert.php' method="post">

Description: <input type="text" name="description" id="description"><br />
Price: <input type="text" name="price" id="price" /><br />
Quantity: <input type="text" name="quantity" id="quantity" />
<input type='submit' value='submit' />


</form>



</body>
</html>

Recommended Answers

All 85 Replies

Hi

In line number 21 the statement is

mysql_query("SELECT*FROM Products='"$result"'");
Please change as mysql_query("SELECT*FROM Products='$result'");

you need to replace this line.

mysql_query("SELECT*FROM Products='"$result"'");

to

$result = mysql_query("SELECT * FROM Products");

Use code tags to place your codes

Thanks! But unfornately this is´n the solution!


Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/eduardli/public_html/web_designer/insert.php on line 23


P. s. I want to show the output in a diagram on my website (www.eduardlid.com/insert data)!

Can you try this code?

echo 'Query:'.$sql = "SELECT * FROM Products";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
	echo $row['Description'] . " " . $row['Price'] . " " . $row['Quantity'];
	echo "<br />";
}

Can you try this code?

echo 'Query:'.$sql = "SELECT * FROM Products";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
	echo $row['Description'] . " " . $row['Price'] . " " . $row['Quantity'];
	echo "<br />";
}

Thanks! However, neither are these improvements good:

Query:SELECT * FROM Products
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/insert.php on line 23

Hi

Pls try this code

<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("table_name", $con);


mysql_query ("INSERT INTO Products (Description, Price, Quantity) 
VALUES ('$description', '$price', '$quantity')");

$q="select * from Products";
$result=mysql_query($q,$con);
while($row = mysql_fetch_array($result))
{
echo $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}

mysql_close($con);
?>

Hi

Pls try this code

<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("table_name", $con);


mysql_query ("INSERT INTO Products (Description, Price, Quantity) 
VALUES ('$description', '$price', '$quantity')");

$q="select * from Products";
$result=mysql_query($q,$con);
while($row = mysql_fetch_array($result))
{
echo $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}

mysql_close($con);
?>

Thanks!
But neither these improvements are good:


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/insert.php on line 23

Thanks!
But neither these improvements are good:


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/insert.php on line 23

I have checked the php file, that´s ok! Could the error be in my form.html?

Hi,
"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given"
This could mean that $result (the first parameter passed) is boolean. Just to check this, could you echo $result right before you start the while loop?

Also, I suppose you have made changes to your original code in insert.php. If you could perhaps post your current code...

Post again what code your using, it looks like your not initializing $result right, you need to be setting it to a SQL handle and the phrase "boolean given" looks like its either returning a false value or your not querying what you want to be.

Woops sorry missed the second page looks like you beat me to it.

Hi,
"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given"
This could mean that $result (the first parameter passed) is boolean. Just to check this, could you echo $result right before you start the while loop?

Also, I suppose you have made changes to your original code in insert.php. If you could perhaps post your current code...

<html>
<body>

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("eduardli_company", $con);


mysql_query ("INSERT INTO Products (Description, Price, Quantity)
VALUES ('$description', '$price', '$quantity')");

$q="select * from Products";
$result = mysql_query($q,$con);
while($row = mysql_fetch_array($result))
{
echo $row . " " . $row . " " . $row;
echo "<br />";
}

mysql_close($con);
?>

</body>
</html

if you intend to search for specific result use where clause

//if you are trying to concat dont forget to add (.)
mysql_query("SELECT*FROM Products where field_name ='".$result."'");

Just echo your query as follows

echo $q="select * from Products";

In the output copy this query and paste it in SQL section of your PhpMyAdmin. See what is the result?

//youre code
mysql_query("SELECT*FROM Products='"$result"'");

//it should be
$string= 'test'; //youre specific string you want to search in you're database
$result = mysql_query("SELECT*FROM Products where field_name='".$string."'");

eduardc,
Your code looks to be OK. As Karthik suggested, try executing the line (select * from Products) in phpmyadmin (or your sql dbms).

Also, I suggest using mysql_error() in your codes to identify the exact error the database is returning. That is,

mysql_select_db("eduardli_company", $con) or die(mysql_error());


mysql_query ("INSERT INTO Products (Description, Price, Quantity) 
VALUES ('$description', '$price', '$quantity')") or die(mysql_error());

$q="select * from Products";
$result = mysql_query($q,$con) or die(mysql_error());

Regards.

commented: useful post +3

$result is not assigned with any value
and use
mysql_query("SELECT * FROM Products='$result'");
it may work

HI

Its Working fine for me.

Pls check the attachment

//youre code
mysql_query("SELECT*FROM Products='"$result"'");

//it should be
$string= 'test'; //youre specific string you want to search in you're database
$result = mysql_query("SELECT*FROM Products where field_name='".$string."'");

Thanks! But also doesn´t work!


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/insert.php on line 24

HI

Its Working fine for me.

Pls check the attachment

Thanks! (I used your attachements, however it isn´t working?)

Table 'eduardli_company.Products' doesn't exist

Thanks! (I used your attachements, however it isn´t working?)

Table 'eduardli_company.Products' doesn't exist

It´s working now! However, I want the latest (only one!) output!

hi

you have to use one more field as serial number, to fetch the latest one try to use the below code with your requirement

<?php
$latest="select * from tablename order by sno desc limit 0,1";
$res=mysql_query($latest,$conn);
$row=mysql_fetch_array($res);
?>

Hi

Pls try this code

<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("table_name", $con);


mysql_query ("INSERT INTO Products (Description, Price, Quantity) 
VALUES ('$description', '$price', '$quantity')");

$q="select * from Products";
$result=mysql_query($q,$con);
while($row = mysql_fetch_array($result))
{
echo $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}

mysql_close($con);
?>

This Coding in perfect just check your html tags.

Thanks! But also doesn´t work!


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/eduardli/public_html/web_designer/insert.php on line 24

can you post youre new/latest code of insert into query?so we can see what is the error.

hi

you have to use one more field as serial number, to fetch the latest one try to use the below code with your requirement

<?php
$latest="select * from tablename order by sno desc limit 0,1";
$res=mysql_query($latest,$conn);
$row=mysql_fetch_array($res);
?>

Thanks!

hi

you have to use one more field as serial number, to fetch the latest one try to use the below code with your requirement

<?php
$latest="select * from tablename order by sno desc limit 0,1";


$res=mysql_query($latest,$conn);
$row=mysql_fetch_array($res);
?>

Hi,

I don´t understand your reply well!
I have to make an extra field to my table (Products) e. g. in phpMyAdmin?
And your code: Do I have to add it to mine or do I have to change mine with it?

hi

you have to use one more field as serial number, to fetch the latest one try to use the below code with your requirement

<?php
$latest="select * from tablename order by sno desc limit 0,1";
$res=mysql_query($latest,$conn);
$row=mysql_fetch_array($res);
?>

I changed the file, but got this error:

Parse error: syntax error, unexpected ')' in /home/eduardli/public_html/web_designer/insert.php on line 23

<html>
<body>

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("eduardli_company", $con) or die(mysql_error());


mysql_query ("INSERT INTO Products (description, price, quantity)
VALUES ('$description', '$price', '$quantity')") or die(mysql_error());

$latest="select * from Products order by serial no. desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result));
{
echo $row . " " . $row . " " . $row;
echo "<br />";
}

mysql_close($con);
?>

</body>
</html>

Hi,

There is an extra parenthesis in the following line.

$row = mysql_fetch_array($result)); //the last parenthesis is not required
//it should be
$row = mysql_fetch_array($result);

Also, wrap your code in CODE tags to make your codes easily readable.

Hope this helps.

Hi,

There is an extra parenthesis in the following line.

$row = mysql_fetch_array($result)); //the last parenthesis is not required
//it should be
$row = mysql_fetch_array($result);

Also, wrap your code in CODE tags to make your codes easily readable.

Hope this helps.

I got this error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc limit 0,1' at line 1

<html>
<body>

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("eduardli_company", $con) or die(mysql_error());


mysql_query ("INSERT INTO Products (description, price, quantity)
VALUES ('$description', '$price', '$quantity')") or die(mysql_error());

$latest="select * from Products order by serial no. desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result);
{
echo $row . " " . $row . " " . $row . " " . $row;
echo "<br />";
}

mysql_close($con);
?>

</body>
</html>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.