got some problem with php programming

Hi there…

I’m doing my project but i’m new to html and PHP. I’ve to extract the array of records form data and i am using xampp local host server. Below is the code that i am using for record extraction.

[php]<?php
$con = mysql_connect(“localhost”, “root”,"");
mysql_select_db(“shoppingmall”, $con);
$qry = mysql_query(“SELECT * FROM Category”);
$qry1 = mysql_query(“SELECT * FROM Category EQUI JOIN Subcategory”);
$qry2 = mysql_query(“SELECT * FROM Category”);
$qry3 = mysql_query(“SELECT * FROM Category EQUI JOIN Subcategory”);

           </table>
	<table width="50%" align="center">
      <tr>
        <td width="19%"><div align="center" class="style2"></div>
		<select>
		<?php while($r = mysql_fetch_array($qry))
			  {
			  	echo"<option><center>".$r["Catid"]."-".$r["Cattitle"]."</center></option>";
			  }?>
		</select>
		</td>
        
		
		<td width="29%"><div align="center" class="style2"></div>
		<select>
		<?php while($r1 = mysql_fetch_array($qry1))
			  {
			  	echo"<option><center>".$r1["Scatid"]."-".$r1["Scattitle"]."</center></option>";
			  }?>
		</select>
		</td>
		<form method="POST" action="productentry.php">
        <td width="22%"><div align="center" class="style2"></div><input type="text" name="pid1"></td>
        <td width="30%"><div align="center" class="style2"></div><input type="text" name="pname1"></td>
      </tr>
	?>[/php]

Its a dropdown list of records actually. What i want to do is to select any record from the list and send that selected record to another page where this will be inserted into another table in database. Please help me out. I would be thankful you you.

You seem to be mixing up your HTML and PHP a bit, and, maybe this is a personal preference, you run 4 queries and then start to pull some results. I prefer to run a query, show the reslt, run the next query, show those results and so forth.

In a ‘.php’ file everything between <?php[/u] and [u]?> is considered PHP. Outside those tags is all HTML. PHP outside the tags renders as code in HTML and HTML inside the tags breaks PHP. Just FYI.

[php]

<?php // connecting $con = mysql_connect("localhost", "root",""); mysql_select_db("shoppingmall", $con); // 'Shoppingmall' is the new 'hello world' ???? // You learned to walk during the New York Marathon? $query = "SELECT * FROM category"; $result = mysql_query( $query ); if ( $result && !mysql_error() ) // We have errors? { echo "\n"; while ( $line = mysql_fetch_array($result) ) { echo "$line['cattitle']\n"; } echo "\n"; } echo "An error occurred: Cannot fetch categories, ". mysql_error(); // and then you run your second query $query = "SELECT * FROM subcategory"; // I assume all subcategories belong to a category. $result = mysql_query( $query ); if ( $result && !mysql_error() ) // We have errors? { echo "\n"; while ( $line = mysql_fetch_array($result) ) { echo "$line['scattitle']\n"; } echo "\n"; } echo "An error occurred: Cannot fetch subcategories, ". mysql_error(); // Now you'll have two selects ?>

[/php] ( that’s how far I understood what you wanted to do )

Then another question, why do you want to insert something into a database that you just pulled out of the database. You’ll get a double record, guaranteed.

I hope this helps a little with your code, it won’t help with the structure. And reading your post I think you need to switch off the computer, get a piece of paper and a pencil and write down ( preferrably structured ) what you want to do.

I hope this helped a little.
Feel free to ask and good luck, ;D
O.

Sponsor our Newsletter | Privacy Policy | Terms of Service