june_c21 Posted February 25, 2008 Share Posted February 25, 2008 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> Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted February 25, 2008 Share Posted February 25, 2008 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") Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 25, 2008 Author Share Posted February 25, 2008 yeah, i try to edit the error but it still the same. why? Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 25, 2008 Author Share Posted February 25, 2008 anyone can help? Quote Link to comment Share on other sites More sharing options...
themistral Posted February 25, 2008 Share Posted February 25, 2008 You have a number of fields all called the same within one form. To my knowledge all fieldnames should be unique unless part of a radio group. You will need to find a different way of handling this - maybe insert just one row at a time. Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 26, 2008 Author Share Posted February 26, 2008 ok. Thanks. I think i better use one row at one time... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.