Jump to content

Insert data


june_c21

Recommended Posts

hi, i got this problem when i try to run this code. It just insert the first row of data and repeat 4 times. Can i know what's wrong with it? How to make it insert the 2nd row of data?

 

<?php

$host = "localhost";
$user = "root";
$password = "";
$dbase = "eclaim";

$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);
$no1 = $_GET['no1'];

$title = $_POST['title'];
$kadar = $_POST['kadar'];
$jumlah = $_POST['jumlah'];

$i=0;

while ($i<4)
{
	if ($no1=='1' || $no1='2' || $no='3')

{
	$query= "INSERT INTO add1 (title,kadar,jumlah) VALUES ('$title','$kadar','$jumlah') ";
	$result = mysql_query($query,$dblink);
	echo $query;
	}

else
	{
	echo "Hello World";
	}
$i++;
}
?>

 

html code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>No</title>
</head>

<body>

<form method="post" action="add.php">
<table style="width: 100%">
	<tr>
		<td style="width: 97px">No.</td>
		<td>Title</td>
		<td>Kadar</td>
		<td>Jumlah</td>
	</tr>
	<tr>
		<td style="width: 97px"><input name="no1" type="text" /></td>
		<td><input name="title" type="text" /></td>
		<td><input name="kadar" type="text" /></td>
		<td><input name="jumlah" type="text" /></td>
	</tr>
	<tr>
		<td style="width: 97px"><input name="no1" type="text" /></td>
		<td><input name="title" type="text" /></td>
		<td><input name="kadar" type="text" /></td>
		<td><input name="jumlah" type="text" /></td>
	</tr>
	<tr>
		<td style="width: 97px"><input name="no1" type="text" /></td>
		<td><input name="title" type="text" /></td>
		<td><input name="kadar" type="text" /></td>
		<td><input name="jumlah" type="text" /></td>
	</tr>
	<tr>
		<td colspan="4">
		<input name="Submit1" type="submit" value="submit" /></td>
	</tr>
</table>
</form>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/92847-insert-data/
Share on other sites

First you have an error on this line...

"if ($no1=='1' || $no1='2' || $no='3')"

 

That last one I'm guessing should be "$no1"

 

And then they ALL need TWO equal signs.  Otherwise you it will ALWAYS be true.

 

Try just doing this...

 

if ($no1 == "1" || $no1 == "2" || $no1 == "'3")

Link to comment
https://forums.phpfreaks.com/topic/92847-insert-data/#findComment-475616
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.