nelquintin Posted September 5, 2007 Share Posted September 5, 2007 please help i have encoded the "id" from another script and want to insert it in the id column in another table.here my code. <? if (isset($_POST["event_desc"])) { $event_desc = $_POST['event_desc']; } if (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) )) { ?> <script language="Javascript" type="text/javascript"> <!-- window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400'); //--> </script> <? } if ( isset($_POST["submit"]) && !empty($event_desc)) { $eventyear = $_POST['eventyear']; $eventmonth = $_POST['eventmonth']; $eventdate = $_POST['eventdate']; $id = $_GET['id']; $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ; if ($day_in_a_mth >= $eventdate ) { $fulldate = $eventyear."-".$eventmonth."-".$eventdate; $event_desc = $_POST['event_desc']; $id = $_GET['id']; $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc', id='$id'"; $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error()); message( "ADD EVENT", "DATA ENTERED"); } else { message( "ERROR", "DATE ENTERED NOT VALID"); } } else { ?> <? $id=$_GET['id']; $query="SELECT * FROM client WHERE id='$id'"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $surname=mysql_result($result,$i,"surname"); $username=mysql_result($result,$i,"username"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68022-solved-what-wrong-there-no-error-messages/ Share on other sites More sharing options...
recklessgeneral Posted September 5, 2007 Share Posted September 5, 2007 Hi, It looks like your problem is caused by mixing the use of $_GET and $_POST. Assuming that the form has been posted, the $_GET array will be empty and as a result your id will also be empty. Now, I don't know how you display your form, but let's say you have a file named showform.php and the URL contains the ID that you wish to eventually insert into your database. The form would be displayed by visiting the URL showform.php?id=xyz. You can then add a hidden input field to your form named "id" with the value passed in as the value of $_GET['id'], as follows: <form action="processform.php" method="POST"> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"> ... rest of form here ... </form> Now, in the code you posted (which I refer to as processform.php), replace the $_GET['id'] with $_POST['id'] and things should start to improve for you. Regards, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/68022-solved-what-wrong-there-no-error-messages/#findComment-342025 Share on other sites More sharing options...
nelquintin Posted September 6, 2007 Author Share Posted September 6, 2007 thanks darren i always confuse the two. Quote Link to comment https://forums.phpfreaks.com/topic/68022-solved-what-wrong-there-no-error-messages/#findComment-342840 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.