Ok so this being my first post i hope im doing it correctly i took this from another post and tried to modify it to what i was supposed to do as u can see basic knowledge here.. ahhaah so i dont even know where to start what i need is 2 dynamic lists generated by a SQL table and after selecting both it should record on table_products on the storenumber column on produc XX the Number from the Store

<?php
$connection = mysql_pconnect("localhost:8889", "root", "root") or die("Error connecting. ".mysql_error());
mysql_select_db("crazy") or die("Error selecting db. ".mysql_error());

if(!isset($_POST['save']))
{
	$query = "SELECT * FROM store";


	$result = mysql_query($query) or die("Error in query. ".mysql_error());

	echo "<form method = 'post' action = '".$_SERVER['PHP_SELF']."'>";
	echo "<table width = '450' align = 'left'>";
	echo "<tr>";
	echo "<td align = 'right'>Store : &nbsp;</td>";
	echo "<td>";
		echo "<select name = 'Store'>";
			echo "<option value = ''>Select Store</option>";
			while($Store = mysql_fetch_object($result))
			{
				echo "<option value = '".$Store->Storenumber."'>".$Store->Storename."</option>";
			}
		echo "</select>";
	echo "</td>";
	echo "</tr>";
        echo "</Form>";


echo "<form method = 'post' action = '".$_SERVER['PHP_SELF']."'>";
        $Ark = "SELECT * FROM products";
        $eds = mysql_query ($Ark) or die("Error in Query. ".mysql_error());

        echo "<tr>";
		echo "<td align = 'right'>Product : &nbsp;</td>";
		echo "<td>";
		echo "<select name = 'Product'>";
			echo "<option value = ''>Select Product</option>";
			while($Product = mysql_fetch_object($eds))
			{
				echo "<option value = '".$Product->Storenumber."'>".$Product->prodname."</option>";
			}
		echo "</select>";
	echo "</td>";
   
	echo "</tr>";
	echo "<tr>";
		echo "<td></td>";
		echo "<td>";
		echo "<input type = 'submit' name = 'save' value = 'SAVE PRODUCT'>";
		echo "<input type = 'reset' value = 'CLEAR FORM'>";
		echo "</td>";
	echo "</tr>";
	echo "</table>";
	echo "</form>";



        echo "$Store";
echo "$Product";
}
else
{
	if(empty($_POST['Store']) || empty($_POST['Product']))
	{
            echo "$Store";
		echo "Either you didn't select a Store or the Product field is empty!";
        }
	else
	{
		$Product = mysql_real_escape_string($_POST['Product']);
		$query = "INSERT INTO products (Storenumber) VALUES('".$_POST['Store']."','$Product', NOW())";

		if(mysql_query($query))
		{
			echo "Product successfully Related!";
		}
		else
		{
			echo "Unknown error has occurred.";
		}
	}
}

?>

Recommended Answers

All 10 Replies

Member Avatar for diafol

Sorry to be picky, but...

> Ok so this being my first post i hope im doing it correctly i took this from another post and tried to modify it to what i was supposed to do as u can see basic knowledge here.. ahhaah so i dont even know where to start what i need is 2 dynamic lists generated by a SQL table and after selecting both it should record on table_products on the storenumber column on produc XX the Number from the Store

..this sounds like Vicky Pollard on speed. Could you punctuate/rewrite this as it is difficult to follow. Unless your name is Peter Carey or cummings?

Sorry to be picky, but...

> Ok so this being my first post i hope im doing it correctly i took this from another post and tried to modify it to what i was supposed to do as u can see basic knowledge here.. ahhaah so i dont even know where to start what i need is 2 dynamic lists generated by a SQL table and after selecting both it should record on table_products on the storenumber column on produc XX the Number from the Store

..this sounds like Vicky Pollard on speed. Could you punctuate/rewrite this as it is difficult to follow. Unless your name is Peter Carey or cummings?

Ok so this being my first post, i hope im doing it correctly
I took this from another post and tried to modify it to what i was supposed to do

as you can see basic knowledge here.. ahhaah.
So i dont even know where to start what i need is:
2 dynamic lists generated by a SQL table
after selecting both options in the lists,
it should record the Number from the Store(selected from the first list)
1)on table- products
1.2)on the storenumber column
1.3)on produc xx (Where xx=the choice on the 2nd dynamic list)


X.x

Member Avatar for diafol

Ok, so if I get you correctly, you're using somebody else's code and you tried to modify it to your purposes. So what's the problem? The lists aren't being generated?

BTW - that code is horrible - echo city.

Ok, so if I get you correctly, you're using somebody else's code and you tried to modify it to your purposes. So what's the problem? The lists aren't being generated?

BTW - that code is horrible - echo city.

eheheh i know that is why i'm asking for help....
and yes i did grab the code from another person
since mine was actually a lot shorter to populate the lists but couldnt do much more than that

so in basic
i need to make a set of lists out of 2 separate tables in mysql
1st table using store_number and storename,
2nd table using productstore and productname,

then somehow select from the first list the storename
from the second list the productname,

and then insert store_number value into productstore.

Member Avatar for diafol

Well, I'm a little confused as to what you need from us. You have a script and you have the procedures. You want somebody to write it for you?

Well, I'm a little confused as to what you need from us. You have a script and you have the procedures. You want somebody to write it for you?

ehhe not actually, i guess the last few days writing this project has been a bit bad for my brain,

ok let me explain i would love for someone to point me into the right direction, as to why my code is not working it actually wont update the database,
all i need is if someone can help me find why it is not working i guess i must be doing some of the post procedures in a unproper manner or perhaps my whole code is all tangled up.

perhaps a few ideas on how to make it happen even if it is not with 2 dynamic lists.
my system is all cooked up and deadline is tomorrow noon so any help would be greatly apreciated

ok so i've rewritten my code to host something i believe is a bit less complicated,
now issue not updating DB,

query does work if run directly to DB,
i believe there is something wrong with the way i'm trying to $_POST
<---- learned php 3 days ago so bring on the slaughter posts... ><

and yes i do know its echo heaven as long as it works ill be happy :D

<?php
$connection = mysql_pconnect("localhost", "root", "pass") or die("Error connecting. ".mysql_error());
mysql_select_db("ouch") or die("Error selecting db. ".mysql_error());

if(!isset($_POST['valtbl1']))
{
	$query = "SELECT * FROM products";


	$result = mysql_query($query) or die("Error in query. ".mysql_error());

	echo "<form method = 'post' action = '".$_SERVER['PHP_SELF']."'>";
	echo "<table width = '450' align = 'left'>";
	echo "<tr>";
	echo "<td align = 'right'>Product : &nbsp;</td>";
	echo "<td>";
		echo "<select name = 'selectvalue'>";
			echo "<option value = ''>Select Product</option>";
			while($pdr = mysql_fetch_object($result))
			{
				echo "<option value = '".$pdr->productid."'>".$pdr->prodname."</option>";
			}
		echo "</select>";
               
               
                }
                else {
                       $selectvalue = $_POST['select_value'];
                       
                     }

                echo "<form method= 'post' action='".$_SERVER['PHP_SELF']."'>";
                echo "<input type='text' name='inputvalue'>";
                echo "<input type = 'submit' name = 'submit'>";


if (isset($_POST['submit']))
  {
  // Execute this code if the submit button is pressed.
  $formvalue = $_POST['input_value'];
  


     
$q=$_POST["input_value"];
$z=$_POST['select_value'];


$chl = "UPDATE `ouch`.`products` SET `prodvendornum` = '$q' WHERE `products`.`productid` ='$z'";

}

mysql_close($connection);
?>
Member Avatar for diafol

You don't have any close form tags. You seem to have two forms for some reason? You also have name mismatches: selectvalue and select_value.

The two different forms will ensure that only ONE form is submitted at a time. So you can't have fields from two different forms sent to the same $_POST var.

I suggest that you just have one form with all the fields in that.

<?php
$prodcode = $_POST['prodcode'] ;
$vendcode = $_POST['vendcode'] ;

$Revy = mysql_connect("localhost:8889","root","root");
if (!$Revy)
 {
    die('Could not connect: Check connection to DB ' . mysql_error());
 }
 mysql_select_db("crazy" , $Revy);




echo $prodcode;
echo $vendcode;
$Freya = "UPDATE `products`
  SET `prodvendorid` = $vendcode WHERE 'productid' = $prodcode";




$aereal = mysql_query($Freya) or die("Error in query. ".mysql_error());
printf ("Updated records: %d\n", mysql_affected_rows());
echo $prodcode;
        echo $vendcode;

mysql_free_result($Kanade);
mysql_free_result($Hisako);
mysql_free_result($Freya);
mysql_free_result($aereal);
mysql_close($Auth);
?>

ok so after a while i droped the idea an came back with something new.. i have a form that does the following

<form name="dbform" method="post"  action="">

<fieldset>
<legend>Basic Information</legend>

<p><label for="prodcode">Product Code:</label><input type="text" name="prodcode" id="prodcode" size="20" /></p>
 <p><label for="vendcode">Vendor Code:</label><input type="text" name="vendcode" id="vendcode" size="20" /></p>
    <p><input type="submit" value="Submit" name="submit" /></p>

</fieldset>

So pretty much is type and click and it should update but i keep getting no updates and in error of mysql,

i get Error in query. 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 'WHERE 'productid' =' at line 2

any words of wisdom_???? id really apreciate it

Member Avatar for diafol

You should quote values NOT fieldnames. You can place backticks around fieldnames though:

WHERE 'productid' = $prodcode

could be

WHERE productid = $prodcode

or

WHERE `productid` = $prodcode
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.