0
<script type="text/javascript">
function populateHarga() {
var x=document.getElementById("barang").value;
document.getElementById("harga").value=x;  
var y=document.getElementById('barang')[document.getElementById('barang').selectedIndex].innerHTML;
document.getElementById('nama_brg').value=y;
}
function populateTotal()
{
var y=document.getElementById("jumlah").value;
var x=document.getElementById("harga").value;
document.getElementById("totalnya").value=x*y;
}
</script>

	<body>
		&nbsp;<p>

		

		

		<?php
			mysql_connect("localhost","root","");
			mysql_select_db("stageco");
	
		?>
		<table border="1" cellpadding="0" cellspacing="0">
			<?php
				$nama_b=$_GET['nama_brg'];
				$harga_b=$_GET['harga'];
				$jumlah_b=$_GET['jumlah'];
				$total_b=$_GET['totalnya'];
				if($nama_b!="")
				{
					mysql_query("INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')");
				}
				$result=mysql_query("SELECT * FROM temp");
				$i = 0;
				while ($row = mysql_fetch_array($result)) {
					if ($i > 0) {
						echo "<tr valign='bottom'>";
						echo "<td bgcolor='#ffffff' height='1'></td>";
						echo "</tr>";
					}
					echo "<tr valign='middle'>";
					echo "<td class='tabval'><width='10' height='20'></td>";
					echo "<td class='tabval'><b>".$row['t_nama']."</b></td>";
					echo "<td class='tabval'>".$row['t_jumlah']."&nbsp;</td>";
					echo "<td class='tabval'>".$row['t_harga']."&nbsp;</td>";
					echo "<td class='tabval'>".$row['t_total']."&nbsp;</td>";
					echo "<td class='tabval'></td>";
					echo "</tr>";
					$i++;
					}
				echo "<tr valign='bottom'>";
				echo "<td bgcolor='#fb7922' colspan='6'></td>";
				echo "</tr>";
							?>

		</table>

<h2>add Entry</h2>
<?
echo "<form action=phonebook.php method=get>";
$get = mysql_query("select * from inventori");

echo"<table width=649 border=0 cellspacing=3 cellpadding=3>";

echo"<tr>";
echo"<td width=99>Nama Produk</td>";
echo"<td width=198><select id=barang onchange=populateHarga()>";
echo "<option></option>";
while($list=mysql_fetch_array($get))
{
echo "<option value='$list[harga]'>$list[nama_barang]</option>";
}
echo"</select></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Jumlah</td>";
echo"<td><input id=jumlah name=jumlah type=text size=12 onblur=populateTotal() /></td>";
echo"</tr>";
echo"<tr>";
echo"<td>Harga</td>";
echo"<td>";
echo"<input id=harga  name=harga type=text />";
echo"</td>";
echo"</tr><tr><td>";
echo"Total :";
echo"</td><td>";
echo"<input type=text name=totalnya id=totalnya /> </td></tr>";
echo"<input type=text name=nama_brg id=nama_brg />";
echo"<tr>";
echo"<td colspan=2><div align=right><input type=submit  value=Next />
  <input type=reset id=batal value=Reset />
</div></td></tr>";
echo"</table></form>";
?>

	</body>
</html>

My problem is i want to insert the DB from a form i make in the same page.. but it doesnt work at all..thanks b4

5
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by Lius
0

Post your errors.
Then it is easy to find out solution.

the problem is i cant insert the data i filled to the database..no error detected..it confuse me

0

is this phonebook.php file?

yes.. i just testing some part of the main source code..and this little part has a problem.. so the name i use is not really important.

0

after 34th line echo out your query

echo "INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')"

copy the query from output and execute it in the SQL section of your phpmyadmin and see what happens

Edited by karthik_ppts: n/a

0

after 34th line echo out your query

echo "INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')"

copy the query from output and execute it in the SQL section of your phpmyadmin and see what happens

SQL query:

echo "INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')"

#1064 - 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 'echo "INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b'' at line 1

I dont get it

0

dont execute this

echo "INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')"

just put this line in your code after 35th line.
Run this page in browser.
copy the printed query from your browser and execute this in phpmyadmin

Edited by karthik_ppts: n/a

0

dont execute this

echo "INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')"

just put this line in your code after 35th line.
Run this page in browser.
copy the printed query from your browser and execute this in phpmyadmin

Yeah done it and gives me error :
INSERT INTO temp( 't_nama', 't_harga', 't_jumlah', 't_total' )
VALUES (
'Kabel merah', '3000', '9', '27000'
)

#1064 - 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 ''t_nama','t_harga','t_jumlah','t_total') VALUES('Kabel merah','3000','9','27000'' at line 1

just to mention my type of data:
t_nama=varchar
t_harga=int
t_jumlah=int
t_total=int

thx b4..

0

replace your line 36 with

mysql_query("INSERT INTO temp(`t_nama`,`t_harga`,`t_jumlah`,`t_total`) VALUES('$nama_b','$harga_b','$jumlah_b','$total_b')");

just replace the "'" with"`" in your query.

0

Your mistakes are uniformly distributed from line 23-38. Replace those lines with this;

<?php		$conn = mysql_connect("localhost","root","");
			         mysql_select_db("stageco"); 		?>
<table border="1" cellpadding="0" cellspacing="0">			
<?php				
                  $nama_b=$_GET['nama_brg'];
		$harga_b=$_GET['harga'];
		$jumlah_b=$_GET['jumlah'];
		$total_b=$_GET['totalnya'];	
			
[INDENT]if($nama_b!="")	{					
 mysql_query("INSERT INTO temp('t_nama','t_harga','t_jumlah','t_total') VALUES     ('$nama_b','$harga_b','$jumlah_b','$total_b')", $conn);

  }[/INDENT]				

                  $result=mysql_query("SELECT * FROM temp", $conn);

When ever you are sending a query you need your connection identifier; stored in the variable "$conn".

Edited by faroukmuhammad: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.