Jump to content

learningPHP1

Members
  • Posts

    23
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

learningPHP1's Achievements

Member

Member (2/5)

0

Reputation

  1. hello, Trying to convert 2 post variables to strtotime so that it can be saved to a database. The 2 variables are: $testDate = $_POST['date'] ; // containts: 2014-04-22 $testTime = $_POST['time']; // containt: 21:02:17 echo $date_time = $testDate . $testTime; // result: 6969-1212-3131 19:00:00 echo $new_date = date('yy-mm-dd H:i:s', strtotime($date_time)); // result: 6969-1212-3131 19:00:00 how do i go about setting the $new_date variable to 2014-04-22 21:02:17 so that it can be saved to a database(mysql data type: datetime) any help you can provide would be greatly appreciated. Thanks
  2. Thanks for the replay chocu3r but now i have large gaps between menus..not very attractive looking.
  3. Hello, I have a menu and using css to control the display. problem area: mouse over menu and bolding. for most part the menu works, what i like to do is prevent the bold (mouse over) from pushing surrounding menus to make space to display the bold. I know i need to somehow expand the menu spaceing so that when the mouse over wont pushing the other menus over but cant seem to hit that number. any ideas? <style rel="stylesheet" type="text/css"> #navcontainer ul { list-style-type: none; margin: 0; padding: 0; } #navcontainer ul li {display: inline; } #navcontainer ul li a { text-decoration: none; font-size: 18px; color: black; background-color: #FFFFFF;} #navcontainer ul li a:hover { color: darkblue; background-color: #FFFFFF; text-decoration:underline; font-weight:bold;} </style> </head> <body> <div id="navcontainer"> <ul> <li> <a href="#"> Home</a></li> <li>|<a href="#"> Project listing</a></li> <li>|<a href="#"> Directory</a></li> <li>|<a href="#"> Create project</a></li> <li>|<a href="#"> My project</a></li> </ul> </div> </body> </html>
  4. Hello everybody, I'm working on a script which has 2 div tages controled by 2 radio buttons and using jquery to hide/show the div tags based on the users selection. Like to have.. if a user selects one of the radio button i like to maintain the selection radio button and the div tag if the page is refreshed. Problem: if the user selects the second div tag and if the page refreshes the radio button and the div tag returns to the initial setup which is going back to the first radio button and div tag. how do i maintain the selection, radio button and the div tage after a refresh? <script type='text/javascript'> $(document).ready(function() { $("#DivB").hide(); $('input[name="myproject"]').change(function() { if($(this).val() == "A") { $("#DivA").show(); $("#DivB").hide(); } else { $("#DivA").hide(); $("#DivB").show(); } }); }); </script> <div style ="border:1px solid black;"> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='POST'> <div id="div1"> <input type='radio' name='myproject' value='A' checked="checked" <?php echo (isset($_POST['myproject']) && $_POST['myproject'] == 'A') ? 'checked':''; ?> />Have projectID <input type='radio' name='myproject' value='B' <?php echo (isset($_POST['myproject']) && $_POST['myproject'] == 'B') ? 'checked':''; ?> />Lost projectID<br /> </div> <hr /> <div id='DivA'> projectID:<br /> <input type="text" name="proId"><br /> email: <br /> <input type="text" name="email"><br /><br /> <button name="btn_prj_info">View project status</button> <br /> </div> <div id='DivB'> Email: <br /> <input type="text" name="emailR"><br /><br /> <button name="btn_email">Email information</button> <br /> </div> </form> </div>
  5. Hello, I'm working on a small form script which submits the form without refreshing the whole page. its a email form which basically calles sendemail.php and returns either "done" or "failed". NOt yet scripted to send, just testing. I been at it for 3 days with no success and wondering if someone can help me fix the problem. Any help you can provide would be greatly appreciated... Thanks <!doctype html> <html> <head> <title>Submit form without refreshing the page</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" </script> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script> $(function() { $("#send").click(function(e) { e.preventDefault(); $.ajax( { type: "POST", url: "sendemail.php", data: $("#myform").serialize(), success: function(response) { if(response == "done") { alert("Form submitted successfully!"); } else { alert("Form submission failed!"); } } }); }); }); </script> </head> <body> <form id="myform" > Name: <br /><input type="text" name="name" id="name" /><br /> Email: <br /><input type="text" name="email" id="email" /> <br /> Message: <br /><textarea name="msg" id="msg"></textarea> <br /> <input type="submit" id="send" class="send" value="Submit" /> </form> </body> </html> small php script <?php $name = $_POST['name']; $message = $_POST['msg']; if(!empty($name) && !empty($message)) { //Do your MySQL or whatever you wanna do with received data //Do not forget to echo "done" when action was completed successfully. echo "done"; } else { echo "fail"; } ?>
  6. Hello, I wrote a small script that basically displays 20 to 30 categories on a page which a user has the option toeither select one or multiple items from the list. For the sack of argument the user selected the following items from the list: Table-> tbl_category : ‘Green car’, ‘truck’, ‘Van’, ‘minivan’,’ laptop’, ‘iPhone’, ‘great value mixed nuts 80% peanuts’, ‘cup’ Tables I have: Table-> tbl_user Table-> tbl_category What is the best practice in terms of saving the multiple selection: 1.Do I create a field in tbl_user and save the selection or selections into that one field? 2. Create a separate tbl_saveCategoreySelection and save them as individual records and link it to tbl_user? At the same time the saved category list will need to be searchable. Any help you can provide would be greatly appreciated. Thanks
  7. Thanks everybody, I greatly appreciate your post replies back. I ended up going with barands answer. I added the hidden input field and it seem to have fixed the issue in my script.. I did change one thing in Brands answer i changed the value='0' to value=''. this gave me what i needed.. again thanks for the help.
  8. Hello, Problem area: radio buttons in a user form. Initially the radio buttons are unchecked which is fine for what i need If one of the radio button is selected the process.php scripts recives the value via $_POST, which works fine. if the radio button isn't selected nothing is sent via $_POST. This is where the problem is.... I need: f the user forgets to select the radio button noting is sent via $_POST. If nothing is sent via $_POST the process.php script is unable to verify the wheather the user made a selection or not. print_r($_POST) ==>Array ( [name] => => [birthday] => [formSubmit] => Submit ) radiobutton doesn't appear. how can in include the radio button as part of the $_POST so that process.php can process the selection weather its empty or not? form.php <form name="formprocess" method="POST" action="process.php"> Name: <input type="text" name="name" value="<?php echo $name; ?>" > <br /> eMail: <input type="text" name="email" value="<?php echo $email; ?>" > <br /> Birthday:<input type="text" name="birthday" value="<?php echo $birthday; ?>" /><br /> <br /> <p> <input type="radio" name="radiobutton" value="1" <?php echo (isset($_POST['radiobutton']) && $_POST['radiobutton'] == 1) ? 'checked':''; ?>> OptionOne </p> <p> <input type="radio" name="radiobutton" value="2" <?php echo (isset($_POST['radiobutton']) && $_POST['radiobutton'] == 2) ? 'checked':''; ?>> OptionTwo </p> <p> <input type="radio" name="radiobutton" value="3" <?php echo (isset($_POST['radiobutton']) && $_POST['radiobutton'] == 3) ? 'checked':''; ?>> OptionThree</p> <input type="submit" name="formSubmit" value="Submit"> </form> process.php $allowedFields = array( 'name', 'email', 'birthday', 'radiobutton', ); $requiredFields = array( 'name', 'email', 'radiobutton', ); echo 'radiobutton1: '. $_POST['radiobutton']; echo '<br />'; print_r($_POST); //loop through the POST array $fieldErrors = array(); foreach($_POST as $key=>$value) { // allowed fields if(in_array($key, $allowedFields)) { $$key = $value; // required field? if(in_array($key, $requiredFields) && $value == '') { $fieldErrors[] = "The field $key is required."; } } }
  9. Problem keeping a variable in the receiving page. From the index.php, the taskid is sent to the receiving page projectasessment.php and this works, the varialble is received. problem is in the receiving page projectassessment.php (data entry form) it wont keep the variable when it returns back to the same page. - projectassessment page receives the variable $_GET['taskid']; - works - user clicks the save button to save the data. - after saving the page the page returns back to projectassessment.php to add another record. - at this stage $_SESSION['taskid'] = $_GET['taskid']; becomes blank. I'm assuming when the page returns back to projectassessment the $_get returns a blank as it has no values to return and in turn the session variable is blank. can any one recommend an alternative option to keep the session variable live? index.php while($row = mysqli_fetch_assoc($ProjectListResults)) { echo '<tr>'; echo "<td> <a href='projectassessment.php?taskid=" .$row['ci_taskid'] . " ' > " . $row['ci_taskid'] . "</a></td>"; echo '<td>' . $row['ci_firstname'] . ' '.$row['ci_lastname']. '</td>'; echo '<td>' . $row['ci_projectid']. '</td>'; echo '<td>' . $row['ci_sde'] . '</td>'; echo '<td>' . $row['ci_status']. '</td>'; echo '<td>' . $row['ci_title']. '</td>'; echo '</tr>'; } projectassessment.php <?php session_start(); echo $_SESSION['taskid'] = $_GET['taskid']; ... ?>
  10. Hello, PHP file upload script. Problem: Unable to upload file under ubuntu server. I have 2 different webservers setup: 1. xampp on usb and my problametic script works. 2. ubuntu server, exact same php script but it wont upload the file. What i noticed with xampp: <--works echo "<br>tempFile=>:-". $_FILES['data']['tmp_name'][$x] . "<br>"; result: tempFile=>:-G:\xampp\tmp\php2D.tmp print_r($imagearray); Array ( [0] => Array ( [1] => G:\xampp\tmp\php2D.tmp [2] => 1357153942_robinuser_dog.jpg ) ) What i noticed with Ubuntu server: echo "<br>tempFile=>:-". $_FILES['data']['tmp_name'][$x] . "<br>"; tempFile=>:/tmp/phpzN6e8U <-- looks like the "tmp" extention is missing. print_r($imagearray); Array ( [0] => Array ( [1] => /tmp/phpzN6e8U [2] => 1357153182_robinuser_bird.jpg ) ) if the temp file ext is missing how do I fix this?? Any help you can provide would be greatly appreciated if(isset($_POST['action'])=='uploadfiles') { for($x=0; $x<count($allowedUpload); $x++) { echo "<br>tempFile=>:-". $_FILES['data']['tmp_name'][$x] . "<br>"; if(!empty($_FILES['data']['name'][$x])) { $extension = end(explode(".", $_FILES['data']['name'][$x])); if ((($_FILES["data"]["type"][$x] == "image/gif") || ($_FILES["data"]["type"][$x] == "image/jpeg") || ($_FILES["data"]["type"][$x] == "image/png") || ($_FILES["data"]["type"][$x] == "image/pjpeg")) && ($_FILES["data"]["size"][$x] < $fileSize) && in_array($extension, $allowedExts)) { if ($_FILES["data"]["error"][$x] > 0) { echo "Error: " . $_FILES["data"]["error"][$x] . "<br>"; } else { //Sanitize the filename $sanitizedName = str_replace($remove_these, '', $_FILES['data']['name'][$x]); $newImageName = time()."_".$imageUserId."_".$sanitizedName; //move_uploaded_file($_FILES['data']['tmp_name'][$x], $upload_directory . $newImageName); if(!empty($newImageName)) { $imagearray[$x][1] = $_FILES['data']['tmp_name'][$x]; $imagearray[$x][2] = $newImageName; } } } else { echo "Invalid file: ".$_FILES["data"]["name"][$x]; } }// end of IF- if(!empty($_FILES['data']['name'][$x])) } // endo for loop print_r($imagearray); for($y=0; $y< count($imagearray); $y++) { move_uploaded_file($imagearray[$y][1], $upload_directory . $imagearray[$y][2]); echo $imagearray[$y][1] . " " .$upload_directory . $imagearray[$y][2]."<br>"; } } // end of upload button
  11. Thank for the suggestion. is there a something specific i should be searching for, a key word, is the process called anything?
  12. hello Everybody, I have a basic user form and the information is saved or submitted by of course a submit button. In the middle of the form i have a zip code lookup field and what I like to do is run the zip code lookup script and display the country, state, and city before moving to the next field. - I have the script which looks up the zip code and tested ok. How do I run a seprate code in the middle and have the resultes displayed before moving to the next field below? any help you can provide would be greatly appreciated. thanks
  13. Hello, I have 2 radio options, one for a new client and one for a returning client and there respective div tags(Div2 - new client and Div2 - returning client) when radio option 1 is selected div1 appears - works when radio option 2 is selected div2 appears - works problem: if radio option 2 is selected the div2 appears but if the page is submitted the returning page still has radio opiton 2 selected but div1 is displayed. need: 1. radio opiton 1 selected to display div1 and submitted. The returning page should have both radio option 1 and div1 selected 2. radio opiton 2 selected to display div2 and submitted. the returning page should have both radio option 2 and div2 selected. Any help you can provide would be greatly appreciated. Thanks you, <head> <script type="text/javascript" > $(document).ready(function () { $('#div2').hide(); $('#id_radio1').click(function () { $('#div2').hide('fast'); $('#div1').show('fast'); }); $('#id_radio2').click(function () { $('#div1').hide('fast'); $('#div2').show('fast'); }); }); </script> </head> <body> <?php if(isset($_POST['btnsave'])) { $userIdField = $_POST['userIdField']; $userPassword = $_POST['passwordField']; $radopt1 = $_POST['radopt']; $radopt2 = $_POST['radopt']; if($_POST['radopt'] == "1") { echo "STAGE: testing: inside new cient"; } else if($_POST['radopt'] == "2") { echo "Testing Inside returning client";} } ?> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST"> <br/> <center> <?php echo "Test: Radio option==>:". $_POST['radopt']; ?> <div align="center" style="border:2px solid red; width:600px; height:110px;" > <input id="id_radio1" type="radio" value = "1" name="radopt" checked="checked" <?php if ($radopt1 == "1") { echo 'checked="checked"'; } ?> /> New Client <input id="id_radio2" type="radio" value = "2" name="radopt" <?php if ($radopt2 == "2") { echo 'checked="checked"'; } ?> /> Returning Client <br/> <div id="div1" style=" border:2px solid blue; width:500px;"> <table boarder="1"> <tr> <th>userId:<input type = "text" name = "userIdField" value = "<?PHP if(!empty($_POST['userIdField'])) {echo $_POST['userIdField'];} else { echo '';} ?>" /> </th> <th>Password:<input type = "text" name ="passwordField" id = "passwordField" value = "" /> </th> </tr> <tr> <th>Email address:<input type = "text" id = "passwordField" value = "E-Mail address" /> </th> <th>re-enterPassword: <input type = "password" id = "passwordField" value = "" /> </th> </tr> </table> </div> <div id="div2" style=" border:2px solid green; width:500px; height:40px;"> <table boarder="1"> <tr> <th>UserId:<input type = "text" id = "userIdField" value = "User Id" /> </th> <th>Password:<input type = "text" id = "passwordField" value = "" /> </th> </tr> </table> <br/> </div> </div> <div> <br/><br/> <button type="submit" name="btnsave" value ="" >Submit Project</button> </div> </center> </form> </body>
×
×
  • 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.