Jump to content

sheldon_cooper

New Members
  • Posts

    5
  • Joined

  • Last visited

sheldon_cooper's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi folks, I'm having a little trouble with a little script that I wrote to try and update dates in a user table. I'm still learning PHP as I go, but this has had me stumped for the past few days!! Basically, it selects a list of users from a table with their end dates (if they have one) and I should be able to update multiple users at once by entering dates or removing the values, ticking the checkbox and clicking 'Update' but it doesn't work! It either only updates the first record, or gives me multiple errors about '2015 not being a valid day for a date/time column'. If I run the SQL directly into the database, then everything works fine, I have a suspicion that its something to do for my for loop in the updateNow() function. Can anyone help !? <?php include 'connect.php'; ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); date_default_timezone_set('Europe/Berlin'); function multiupd(){ $con = ingres_connect("testserver::testdb") or die("Could not connect"); $sql="select name, expire_date from test_user order by name asc"; $result = ingres_query($con, $sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Update multiple users: </strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Expiry Date</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Update Required</strong></td> </tr> <?php while($rows=ingres_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><?php echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><input name="expiry_date[]" type="text" id="expiry_date[]" value="<?php if (!is_null($rows['expire_date'])) { $convert_date = strtotime($rows['expire_date']); if ($convert_date > 0) { echo date('d.m.Y', $convert_date); } } ; ?>"</td> <td bgcolor="#FFFFF" align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['name']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="update" type="submit" id="update" value="Update"></td> <td><input type=hidden value="Update multiple users" name="userDBupdate"></td> </tr> <?php ingres_close($con); } // end of multiupd function updateNow(){ ?> <form name="updateUsers" method="post" action=""> <td><input type=hidden value="Update multiple users" name="userDBupdate"></td> <?php for($i=0;$i<count($_POST['checkbox']);$i++){ $userid = $_POST['checkbox'][$i]; $date_to_upd = $_POST['expiry_date'][$i]; $sql = "update test_user SET expire_date = ingresdate('" . $date_to_upd . "') where name = '" . $userid . "'"; $con = ingres_connect("testserver::testdb") or die("Could not connect"); $db_update = ingres_query($con, $sql); echo $date_to_upd; if (ingres_errno()) { echo ingres_errno() . "-" . ingres_error() . "\n"; } echo $date_to_upd; echo $sql; if ($db_update == TRUE){ echo "<br>User <b>" . $userid . "</b> has had expiry date updated until <b>" . $date_to_upd . "</b>"; } else echo "There has been an error processing your request."; } ingres_commit($con); ingres_close($con); } // end of updateNow ######################################################################################### ######################################################################################## ## Main Prog ## ## ## ######################################################################################## ######################################################################################### if (isset($_POST['update'])) { updateNow(); } elseif (empty($_POST['update'])) { multiupd(); } elseif (empty($_POST['checkbox'])) { echo "No users selected! Please check the box where an update is required"; } else { echo "Nothing to see here"; } ?> </table> </form> </td> </tr> </table> Can anyone help !? It's driving me crazy! Cheers!
  2. Thanks cyberRobot, you are a genius!!! Cannot thank you enough! Think I might need to go through another few tutorials before I attempt a few pages on my own.
  3. You sir, are a genius!! I was banging my head off a brick wall with that one and didn't even think to look at my forms! Thank you again! Now I just need to figure out a way to fix the if/else isset/empty statements at the bottom so when it displays the 'testingMe' function, it doesn't ask for a username input (second form) at the same time!
  4. Hi cyberRobot, thanks for your reply. My forms look like : <?php include 'connect.php'; ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); function pickacolour(){ ?> <form name="colourlist" method="post" action="<?php print $_SERVER['PHP_SELF'] ?>"> <table border=0> <tr> <td>Select this colour: </td> <?php $colourlist = file("colourlist.txt"); echo '<td><select name="colourname">'; foreach ($colourlist as $list) { echo '<option value="' . $list .'">' .$list. '</option>'; } echo '</select>'; ?> <input type=hidden value=<?php print $_POST['colourForm']; ?> name=colourForm> <td><input type=submit tabindex=1 value="Next" name="colour"></td></tr> </table></form> <?php } // end of pickacolour() function selectUser(){ ?> <form name"enteruser" method="post" action"<?php echo $_SERVER['PHP_SELF'] ?>"> <table border=0> <tr><td>Enter username (Favourite colour being <?php echo "". $_POST['colourname'] ?>) <input type="text" name="user"></td> <input type=hidden value=<?php echo $_POST['colourForm']; ?> name=colourForm> <td><input type=submit tabindex=1 value="Submit" name="resetNOW"></td></tr> <?php } // end of selectUser function testingMe(){ echo "This is a test"; echo "<br>You just entered " . $_POST['user']; echo "<br>You just selected " . $_POST['colourname']; } //end of testingMe ////////////////////////////////// // Main prog // ////////////////////////////////// if (empty($_POST['colourname'])) { pickacolour(); } if (!empty($_POST['colourname'])) { selectUser(); echo "You have selected " . $_POST['colourname']; } if (isset($_POST['resetNOW'])) { if (isset($_POST['resetNOW'])){ testingMe(); echo "<br>You just entered " . $_POST['user']; echo "<br>You just selected " . $_POST['colourname']; } else{ echo "Nothing to see here"; } } ?> Probably not the most efficient or cleanest code, but I'm still learning! Thanks for looking
  5. HI folks, Been reading the forums for a while, but this is my first post - what a wealth of knowledge on these boards! I've been trying to learn PHP and followed a few tutorials, thought I was doing well but have hit some trouble with a page I've been creating. Basically I've created a single page with two forms that take input (one from a list, one from a text box) and those work fine. However when I attempt to read the value of the of the POST variables into the third function to display, it only displays one and I can't figure out why! I think I've made errors in my if/else statement at the bottom but I've rewrote it a few times and think i'm just getting confused! Here is the code: if (empty($_POST['colourname'])) { pickacolour(); } if (!empty($_POST['colourname'])) { selectUser(); echo "You have selected " . $_POST['colourname']; } if (isset($_POST['resetNOW'])) { if (isset($_POST['resetNOW'])){ testingMe(); echo "<br>You just entered " . $_POST['user']; echo "<br>You just selected " . $_POST['colourname']; } else{ echo "Nothing to see here"; } } It gets to the end and prints the 'testingMe' function (which basically just echos to say we made it that far) and the user entered but won't print the colourname, that is always blank. But it does print the colourname when I am selecting a user in the 'selectUser' function - I just can't figure out why it doesn't echo it with the 'testingMe' function and its driving me insane! Thanks for any help guys
×
×
  • 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.