june_c21 Posted February 22, 2008 Share Posted February 22, 2008 hi, i try to run this code but appear error. can someone help me figure out what is the problem? thanks a lot <?php session_start(); $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'eclaim'; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); $event_desc = $_POST['event_desc']; $pic_id = $_POST['pic_id']; $venue = $_POST['venue']; $staffs_involved = $_POST['staffs_involved']; $person = $_POST ['person']; while ($event_desc != NULL) { $query= "INSERT INTO add1( event_desc,pic_id,venue,staffs_involved,person) VALUES ('$event_desc','$pic_id','$venue','$staffs_involved','$person')"; $result = mysql_query($query,$dblink); } $redirect = 'main.php'; header ("location: $redirect"); ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted February 22, 2008 Share Posted February 22, 2008 And the error that appears is what? Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 22, 2008 Author Share Posted February 22, 2008 there is no data store in the database. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 22, 2008 Share Posted February 22, 2008 try this: $result = mysql_query($query,$dblink) or die("QUERY: ".$query."<br>".mysql_error()); hope this helps, Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 22, 2008 Author Share Posted February 22, 2008 sorry, but it stil doesnt work. Code no error but why can't store? weird Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 22, 2008 Share Posted February 22, 2008 what are you trying to do with: while ($event_desc != NULL) { careful - this could create an indefinite loop. try: if($event_desc != NULL) { $query= "INSERT INTO add1( event_desc,pic_id,venue,staffs_involved,person) VALUES ('$event_desc','$pic_id','$venue','$staffs_involved','$person')"; $result = mysql_query($query,$dblink) or die("Query: ".$query."<br>".mysql_error()); echo($query); }else{ echo("\$event_desc == null"); } hope this helps, Quote Link to comment Share on other sites More sharing options...
Barand Posted February 22, 2008 Share Posted February 22, 2008 what are you trying to do with: while ($event_desc != NULL) { careful - this could create an indefinite loop. Exactly, but I can't reconcile that with the stated error message ??? Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 22, 2008 Author Share Posted February 22, 2008 while ($event_desc != NULL) { i want to stop inserting data when $event_desc is NULL / no data input. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 22, 2008 Share Posted February 22, 2008 event desc is either going to be NULL or NOT NULL for the entire script no matter how many time you loop it unless you unset() it after the loop, in which case you dont need a loop at all... Why do you want to stop insert when event_desc is null, please try to explain your problem and idea and fully and as plainly as possible. thanks, (did you try my solution? what did the page say (exactly, copy+paste if you have to) , Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 22, 2008 Author Share Posted February 22, 2008 ya, i try but still no data insert into database. ok, here is my 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-Type" content="text/html; charset=iso-8859-1" /> <title>KEV Calendar</title> <link rel="stylesheet" href="http://www.zapatec.com/website/main/../ajax/zpcal/themes/winter.css" /> <style type="text/css"> <!-- .style8 {font-family: Arial; font-weight: bold; font-size: 14px; } body { background-color: #FFFF99; } .style12 {font-family: Arial; font-weight: bold; font-size: 12px; color: #FF3300; } .style13 { font-family: Arial; font-weight: bold; } --> </style> <script type="text/javascript" src="http://www.zapatec.com/website/main/../ajax/zpcal/../utils/zapatec.js"></script> <script type="text/javascript" src="http://www.zapatec.com/website/main/../ajax/zpcal/src/calendar.js"></script> <!-- Loading language definition file --> <script type="text/javascript" src="http://www.zapatec.com/website/main/../ajax/zpcal/lang/calendar-en.js"></script> </head> <body> <p class="style8"> </p> <form id="form1" name="form1" method="post" action="add.php"> <label></label> <p> <label></label> <span class="style13">KEV Calender </span></p> <table width="516" height="138" border="1"> <tr> <td><span class="style12"> <label>Event </label> </span></td> <td><textarea name="event_desc" id="event_desc"></textarea></td> <td class="style12"><p>Registered By (staff no.)100xxxxx / skxxxxx </p> </td> <td><input name="pic_id" type="text" id="pic_id" /></td> <td class="style12">Venue</td> <td><input name="venue" type="text" id="venue" /></td> <td><span class="style12"> <label>Staff Involved</label> </span></td> <td><input name="staffs_involved" type="text" id="staffs_involved" /></td> <td><span class="style12"> <label>Person In Charge </label> </span></td> <td><input name="person" type="text" id="person" /></td> </tr> <tr> <td><span class="style12"> <label>Event </label> </span></td> <td><textarea name="event_desc" id="event_desc"></textarea></td> <td class="style12"><p>Registered By (staff no.)100xxxxx / skxxxxx </p> </td> <td><input name="pic_id" type="text" id="pic_id" /></td> <td class="style12">Venue</td> <td><input name="venue" type="text" id="venue" /></td> <td><span class="style12"> <label>Staff Involved</label> </span></td> <td><input name="staffs_involved" type="text" id="staffs_involved" /></td> <td><span class="style12"> <label>Person In Charge </label> </span></td> <td><input name="person" type="text" id="person" /></td> </tr> <tr> <td><span class="style12"> <label>Event </label> </span></td> <td><textarea name="event_desc" id="event_desc"></textarea></td> <td class="style12"><p>Registered By (staff no.)100xxxxx / skxxxxx </p> </td> <td><input name="pic_id" type="text" id="pic_id" /></td> <td class="style12">Venue</td> <td><input name="venue" type="text" id="venue" /></td> <td><span class="style12"> <label>Staff Involved</label> </span></td> <td><input name="staffs_involved" type="text" id="staffs_involved" /></td> <td><span class="style12"> <label>Person In Charge </label> </span></td> <td><input name="person" type="text" id="person" /></td> </tr> </table> <p> <label> <input type="submit" name="Submit" value="Enter" /> </label> </p> </form> <p> </p> </body> </html> user will input data according to rows. For example, user A will input for 2 rows only and user input for all rows. So i want to stop inserting data when the rows is empty. Since $event_desc is the first column, so i using when $event_desc is empty (NULL) stop inserting data into database Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 22, 2008 Author Share Posted February 22, 2008 anyone can help? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 22, 2008 Share Posted February 22, 2008 im sorry but i dont understand you user will input data according to rows. For example, user A will input for 2 rows only and user input for all rows. So i want to stop inserting data when the rows is empty. Since $event_desc is the first column, so i using when $event_desc is empty (NULL) stop inserting data into database can you explain a little better? Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 22, 2008 Share Posted February 22, 2008 take it step by step. First add "or die(mysql_error())" on your db query to see if there is an error. If there is no error, remove the while statement completely and see if that works. You do understand that when a form is submitted to your php script, the $_POST's will only come through once? A while loop shouldn't be of any use at all. Quote Link to comment Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 $event_desc = $_POST['event_desc']; comes from the textarea in his html. You can't loop a string from the textarea , so you while loop is wrong basically. You need to split the string by commas or spaces, or whatever separates the stuff in there. Quote Link to comment Share on other sites More sharing options...
june_c21 Posted February 22, 2008 Author Share Posted February 22, 2008 oh, so i just can loop int like ID != Null ?? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 22, 2008 Share Posted February 22, 2008 In reply #5 above, Uniflare posted some error-trapping / debugging code and asked you to post the output. You really do need to help us to help you - we aren't clairvoyant 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.