Jump to content
Killersites Forums

perseas

Member
  • Posts

    10
  • Joined

  • Last visited

perseas's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I have tested your corrections, and finally the code works! Thanks a lot! You're amazing!
  2. The drop down list is empty. And the error log has two notices [14-Oct-2013 18:59:37 UTC] PHP Notice: Uninitialized string offset: 1 in C:\xampp\htdocs\haa\ben.php on line 51 [14-Oct-2013 18:59:37 UTC] PHP Notice: Uninitialized string offset: 1 in C:\xampp\htdocs\haa\ben.php on line 51 pointing this command: <option value="<?php $array[$k]?>"><?php $array[$k]?></option> (all the code is updated at the previous post)
  3. Thanks for the correction, but still the list is empty. I can't understand why..
  4. Ι corrected the code with the count command. Αnd I edited the previous post with my code. For your first notice. I didn't undesrtand. I have already the $array with the data. Is it necessary to have a mysql_query again? This is why I commented out. about the $row['$k'], it was my mistake, I corrected it.
  5. The new code. the data are retrieved (succesfully) outside the renderform, and i pass them inside the function. <?php //add_flight.php session_start(); $hostname = "myhostname"; $database = "mydatabase"; $username = "username"; $password = "password"; $link = mysql_connect( $hostname , $username , $password ) or die("Attention! Server Connection Problem : " . mysql_error()); mysql_select_db($database,$link); ?> <?php $i=0; $result = mysql_query("SELECT * FROM users",$link); while($row = mysql_fetch_array($result)) $array[$i]=$row['name']; //for ($k=0;$k<=$i;$k++) echo $array[$k]; // I can see the content of $array. It's right. ?> <?php function renderForm($fdate, $pic, $planetype,$link, $array,$error) { ?> <html> <head> <title>Add New Flight</title> </head> <body> <?php if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <?/*php $result = mysql_query("SELECT * FROM users",$link)or die(mysql_error()); $row == mysql_fetch_array($result); echo $row[name];*/?> <form action="add_flight.php" method="post"> <table> <tr><td><B>Date:</B></td><td><input type="text" name="fdate"value="<?php echo $fdate; ?>"/></td></tr> <tr><td><B>PIC:</B></td><td><select name="pic"value="<?php echo $pic; ?>"/> <?php $count=count($array); for ($k=0;$k<$count;$k++)?> <option value="<?php $array['$k']?>"><?php $array['$k']?></option> //// line 48 ?> </select> </td></tr> <tr><td><B>planetype:</B></td><td><select name="planetype"value="<?php echo $planetype; ?>"/> <option value="cessna">cessna</option> <option value="piper">piper</option> <option value="diamond">diamond</option> </select> </td></tr> <input type="submit" name="submit" value="Submit"> </form> </body> </html> <?php } if (isset($_POST['submit'])) { $fdate = mysql_real_escape_string(htmlspecialchars($_POST['fdate'])); $planetype = mysql_real_escape_string(htmlspecialchars($_POST['planetype'])); $pic = mysql_real_escape_string(htmlspecialchars($_POST['pic'])); if ($fdate == '' || $pic == '') { $error = 'ERROR: Please fill in all required fields!'; renderForm($fdate, $pic, $planetype,$link, $array,$error); } else { mysql_query("INSERT flights SET fdate='$fdate', pic='$pic', planetype='$planetype'") or die(mysql_error()); header("Location: add_flight.php"); } } else { renderForm('','','', '','', ''); } ?> error log [14-Oct-2013 18:52:22 UTC] PHP Notice: Uninitialized string offset: 1 in C:\xampp\htdocs\haa\ben.php on line 48 [14-Oct-2013 18:52:22 UTC] PHP Notice: Uninitialized string offset: 1 in C:\xampp\htdocs\haa\ben.php on line 48
  6. $global link; added in the code. Only one warning, but nothing happened. I'm sending in a few minutes the code you asked for...(retrieve data outside the renderform) PHP Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\haa\ben.php on line 26
  7. I declare $link as global, over the mysql_connect. e.g. global $link; $link = mysql_connect( $hostname , $username , $password ) or die("Attention! Server Connection Problem : " . mysql_error()); I'll post the code in which the access and the data are retrieved outside the form, and stored in an array to the function. Soon!
  8. Hello all! I'm new in PHP and I'm trying to create a dynamic drop-down list. I have two tables, pilots and flights. So, when I want to insert a flight, I'd like to select from a dynamic list with the pilots (i can add pilots, with another php file). But, when I'm trying to run the code, nothing happens. Here is my code: <?php //add_flight.php session_start(); $hostname = "myhostname"; $database = "mydatabase"; $username = "myusername"; $password = "mypassword"; $link = mysql_connect( $hostname , $username , $password ) or die("Attention! Server Connection Problem : " . mysql_error()); mysql_select_db($database,$link); ?> <?php function renderForm($fdate, $pic, $planetype, $error) { ?> <html> <head> <title>Add New Flight</title> </head> <body> <?php if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <form action="add_flight.php" method="post"> <table> <tr><td><B>Date:</B></td><td><input type="text" name="fdate"value="<?php echo $fdate; ?>"/></td></tr> <tr><td><B>PIC:</B></td><td><select name="pic"value="<?php echo $pic; ?>"/> <?php global $link; $result = mysql_query("SELECT * FROM pilots",$link)or die(mysql_error()); while($row == mysql_fetch_array($result)) {?> <option value="<?php $row['pname']?>"><?php $row['pname']?></option> <?php }?> </select> </td></tr> <tr><td><B>planetype:</B></td><td><select name="planetype"value="<?php echo $planetype; ?>"/> <option value="cessna">cessna</option> <option value="piper">piper</option> <option value="diamond">diamond</option> </select> </td></tr> <input type="submit" name="submit" value="Submit"> </form> </body> </html> <?php } if (isset($_POST['submit'])) { $fdate = mysql_real_escape_string(htmlspecialchars($_POST['fdate'])); $planetype = mysql_real_escape_string(htmlspecialchars($_POST['planetype'])); $pic = mysql_real_escape_string(htmlspecialchars($_POST['pic'])); if ($fdate == '' || $pic == '') { $error = 'ERROR: Please fill in all required fields!'; renderForm($fdate, $pic, $planetype, $error); } else { mysql_query("INSERT flights SET fdate='$fdate', pic='$pic', planetype='$planetype'") or die(mysql_error()); header("Location: add_flight.php"); } } else { renderForm('','','', ''); } ?> Here is the php_error_log: PHP Notice: Undefined variable: link in C:\xampp\htdocs\haa\ben.php on line 32 PHP Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\haa\ben.php on line 32 - I also tried the same code with a second function which retrieves succesfully the data outside the renderform and i passed them in renderform. No luck. - I declared $link as a global variable (global $link), nothing happened, but the notice of the error log stayed on. - I abbrogated the renderford and modified the code. I can see the data outside the form, but not inside. Thanks in advance!
  9. Thanks for the response! I've tried that, but nothing happened. As I mentioned previously, inside the renderform there's no problem, I can see the data. The problem is that when I reallocate the commands (cut-paste!), inside the form, nothing happens and I don't know why...
  10. Hi all! nice tutorial. It helped to learn some things. I'm new in PHP/MySQL and I have a question. In case I want to modify the new.php to create a dynamic drop down list (with data from another table of the database) in the form, how can I use that? I tried but I failed. When Ι try to retrieve the data outside the form, it's OK, but when I'm trying to relocate the commands into the form this time, nothing happens! why is that? In the form, are there local variables or sth like that? Thanks in advance!
×
×
  • Create New...