
moosey_man1988
Members-
Posts
75 -
Joined
-
Last visited
Everything posted by moosey_man1988
-
Hi Guys Can someone point me in the right location for creating a dynamic dropdown list, I'm currently creating an edit user page so i can edit users on my system what i want is like below: ( text box (type part of a username here) A dropdown list of users that dynamically updates as a word is typed in the text box above } This will be pulling from a database, i don't mind if you give me a guide for any of the following i can work out the rest, mysqli or pdo are preffered. Any help is greatly appreciated and I thank you in advance
-
Need help with a Javascript function
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
You literally just responded after i head banged a bit and figured it out, I'm having massive trouble with getting my head around javascript.... Maybe I A training course is required its about £2500 though :| Thanks for the response Ch0cu3rI really appreciate all the help I get on this site. -
Hi Everyone I'm having some troubles (again) with jquery, I have a table which is created by a while loop which loops out this info here: //Contains a hidden input so we can submit a deletion of the receipt echo "<tr><td>".$receiptName."</td><td>".$receiptNote."</td><td>£".$receiptValue."</td><td>".$receiptDate."</td><td> <a href=".$url . $receiptPath . $receiptFile."><img class='zoom-image' style='width:auto;' src=".$url . $receiptPath . $justfileName.".jpg></img></a></td> <td class='hidden'><input id='ReceiptId' class='hidden' name='FileID' value='".$fileId."'></td> <td><a type='submit' href='#' OnClick='removeReceipt()'><h1 class='glyphicon glyphicon-remove-circle' style='opacity: 0.25;'></td></tr>"; } else { //Contains a hidden input so we can submit a deletion of the receipt echo "<tr><td>".$receiptName."</td><td>".$receiptNote."</td><td>£".$receiptValue."</td><td>".$receiptDate."</td><td> <a href=".$url . $receiptPath . $receiptFile."><img class='zoom-image' style='width:auto;' src=".$url . $receiptPath . $receiptFile."></img></a></td> <input id='ReceiptId' class='hidden' name='FileID' value='".$fileId."'> <td><a type='submit' href='#' class='btn' OnClick='removeReceipt()'><h1 class='glyphicon glyphicon-remove-circle' style='opacity: 0.25;'></td></tr>"; and my Jquery is <script type="text/javascript"> function removeReceipt() { $.ajax({ url: '<?php echo Thisurl();?>', data:{ReceiptId: $('#ReceiptId').val() }, type: 'post', success:function() { window.location.reload(true); } }); } </script> But I just realized this will only delete the top item on the list because ReceiptId Is exactly the same on every row so it just chooses the first one and deletes it. Is there a way I can do something like? OnClick='removeReceipt(".<?php echo $fileId.") and have the javascript function read that variable? e.g It would be something like OnClick='removeReceipt(32)' the Javascript function can then take that 32 a supply it to the rest of the php from below <?php //This will call the remove receipt function if called by the ajax form above. if (isset($_POST['ReceiptId'])){ $receiptId = $_POST['ReceiptId']; removeTheReceipt($receiptId); } ?>
-
button to perform function without reloading the page
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Yeh i have it in a "database" directory, so for instance I have Functions/functions.php and I have Tasks/tasks.php, but i also have index.php which is in the root directory which if there is no session it points you to secure/login.php, If i try to perform a function using Functions/functions.php from index.php It needs needs to be database/mysqli_connection.php but if I need a function performed by Tasks/tasks.php It needs ../database/mysqli_connection.php, the problem is if I call a function using Functions/functions.php from a root file e.g index.php it needs the directory to be database/mysqli_connection.php, but if I call that same function from Tasks/tasks.php is needs the directory to be ../database/mysqli_connection.php, I've never quite figured out how to get around this one. -
button to perform function without reloading the page
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Well I've put everything in a directory up bar a few main pages. So if it's not in the directory below and then database then it must just be up one directory although if you have a better solution for this I would be your best buddy forever lol -
button to perform function without reloading the page
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Hi maxed. Yeah don't worry I am well aware of MySQL injections luckily this will not be for the "open world" just yet. I am working on functionality then I'll be making security improvements thanks again. -
button to perform function without reloading the page
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Hey Thanks for your help maxxd, I have got it working any way i could clean this up, or is this acceptable? AJAX script (in dashboard.php) <script> function removeTask() { $.ajax({ url: '<?php echo Thisurl();?>', data:{TaskName: $('#taskName').val(), TaskId: $('#taskId').val() }, type: 'post', success:function(output) { alert(output); } }); } </script> php (in dashboard.php) <?php // This is if AJAX has inputted the post information. if (isset($_POST['TaskName'])) { if (isset($_POST['TaskId'])){ $TaskName=$_POST['TaskName']; $taskID=$_POST['TaskId']; //Remove the Task with the correct information removeTask($TaskName,$taskID); echo "welldone"; } } functions.php (called in my layout.php so all pages load functions) function removeTask($TaskName,$taskID){ if (isset($TaskName)){ echo "Taskname is set"; } else { header ('Location: index.php?error="Task completion variables not set [E/1]"'); } if (isset($TaskID)){ echo "TaskID is set"; } else { header ('Location: index.php?error="Task completion variables not set [E/2]"'); } if (file_exists('../database/mysqli_connection.php')){ require('../database/mysqli_connection.php'); } else { require('database/mysqli_connection.php'); } $updateTask = "UPDATE MC_Tasks SET status='2' WHERE TaskName ='".$TaskName."' AND TaskId='".$taskID."'"; $completedTaskResult = mysqli_query($mysqli_connection,$updateTask); if (mysqli_affected_rows($mysqli_connection) > 0){ echo "task Completed!"; } else { echo "Task could not be removed, lets check the query on what went wrong"; echo $updateTask; } } Thanks for all your help Maxxd really appreciate the advice -
button to perform function without reloading the page
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Hey so i've been reading up on AJAX, i dont "do" those guides so well i usually learn from examples and then can manipulate them until i fully understand it, Although I can get the AJAX to work as it is displaying the page alert, I cant get its to POST to my php script here's the code below: the AJAX part <script type="text/javascript"> function removeTask() { $.ajax({ url: 'dashboard.php', data:{action:'removeTask'}, type: 'post', success:function(output) { alert(output); } }); } </script> The PHP part <?php echo "error should be here"; if (isset($_POST['action'])){ echo "try removing this task"; /* will soon be calling the function with this once the echo works removeTask($TaskName,$taskID); */ } ?> Any help would be massively appreciated, I am really work hard to learn as much as i can -
Hi everyone bit of a funny one, but im looking for someone who can help me with my PHP in the south of england / brighton & hove area, I am okay with php but I would like to further my skills and vice versa, I would be happy to offer help with other stuff if someone would like to benefit from me I code, bin/bash, I can create from asterisk IVR's or full asterisk phone systems, do networking, teach DNS, Can diagnose voip systems and even further down the line with termination, im pretty good at mysql, and also database migration and have really good knowledge of using rsync for massive advantages. These are just a few that come to mind
-
Hi Everyone I'm pretty new to coding, and I have come across my first page where i need to perform a function, within a bootstrap modal without refreshing the page, I have looked this up and I'm guessing ajax is what i need. I have never coded Ajax before What i have is a list of "tasks" displayed as alerts within the modal which is created by a while loop within php In those action bars i have 2 buttons 1 is 'dismiss' (just basically hides the task, which is working) and the 2nd button is 'completed' which needs to perform a function that sets a status of 2 (0 being new, 1 being extended, 2 being completed) against that note, I dont have a problem performing this, what i need help with is running that function without leaving the page or closing the modal. Any advice or help with implementing Ajax would be greatly appreciated. Thanks
-
create a php file using exec with variables
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Hey Jaques, Thank you for your response again your answer solved it for me VERY quickly, I will remember in future that magical backslash Resulting Code below //Lets create the mysqli_connection page for all other php pages to use with the new DB user $mysqli_file = "database/mysqli_connection.php"; $mysqli_connection_setup = "<?php \$mysqli_connection = mysqli_connect($servername, $dbnewuser, $newuserpass, $dbname); if (!\$mysqli_connection){ die('Connection Failed: ' . mysqli_connect_error()); } ?>"; file_put_contents($mysqli_file, $mysqli_connection_setup); Thanks again you must grow tired of PHP newbs -
create a php file using exec with variables
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
i created a test script, still no luck <?php $servername = "localhost"; $username = "root"; $DBpassword = "testPassword"; $dbname = "testDB"; $invoiceDB = "invoices"; $dbnewuser = "testUser"; $newuserpass = "testPass"; $file = "database/mysqli_connection.php"; $myString = "<?php $mysqli_connection = mysqli_connect($servername,$dbnewuser,$newuserpass,$dbname); if (!$mysqli_connection){ die('Connection Failed: ' . mysqli_connect_error()); } ?>"; file_put_contents($file, $myString); $getData = file_get_contents($file); echo $getData; ?> Ignore the unused variables, this was just something quick to see if can be accomplished. here's the error PHP Notice: Undefined variable: mysqli_connection in /var/www/html/test.php on line 14 PHP Notice: Undefined variable: mysqli_connection in /var/www/html/test.php on line 19 I really do hope to make a connection script, as once the installation finished it, all the rest of my script call upon the mysqli_connection.php -
create a php file using exec with variables
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
those are yet languages on my list to learn this script will ever be improved upon with new langues as I learn more languages etc etc. Thanks for the advice, im still not clear on ALL of a functions that PHP can do, but this is what forums and guides are for I will test out the put_file_contents, Thanks for a swift response -
Hi Everyone im currently creating an install script and i was hoping to touch and cat to a lot of files for them to be created, but im having troubles. You will easily see in the code below what im trying to achieve. //Lets create the mysqli_connection page for all other php pages to use with the new DB user exec ('touch database/mysqli_connection.php'); exec ('echo "<?php $mysqli_connection = mysqli_connect('.$servername.','. $dbnewuser.','. $newuserpass.','. $dbname.'); if (!$mysqli_connection){ die("Connection Failed: " . mysqli_connect_error()); } ?>" > database/mysqli_connection.php'); the issue I have is this is how the file comes out, its having trouble passing $mysqli_connection as a string. see the mysqli_connection.php below <?php = mysqli_connect(localhost,testuser,testPassword,testDB); if (!){ die(Connection Failed: . mysqli_connect_error()); } ?> I did try using single quotes around the $mysqli_connection variable like so '.$mysqli_connection.' but the file then comes out blank. any help given would be greatly appreciated, and i thank everyone for their help in advance
-
Export csv from mysql pipe Delimited
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Hi I've for the function to work now but it is still inserting the html code within the php pages below is the end of the script which calls the function include('test.php'); sql2csv($db_mysqli, $sql, $filename='', $headings=0); } ?> and the function is now its own page named test.php -
how i can i let user to download a data from query in mySQL
moosey_man1988 replied to VanillaRose's topic in MySQL Help
apologies, this was my first function, I have the function working now, but still the excel file contains the echo's from the webpage + the data from the the query.. like so <head> <title>Newfies Page</title> </head> <body> <h2>Lets take a look at a table </h2> exporting!</br>created newfies table</br>prepared 1000 numbers7415354264 7428357984 7428748979 7500332817 7504051767 7504299246 7504822797 7505149835 7506677762 7506878021 7510330942 7510935466 7510941052 7511362543 7511732442 7511889806 7512215911 7512575544 7513832701 Here is my code: require('test.php'); sql2csv($db_mysqli, $sql, $filename='myNewfile.csv', $headings=0); } ?> <?php $sql = 'SELECT * FROM newfies'; function sql2csv($db_mysqli, $sql, $filename='', $headings=0) { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $db_mysqli->query($sql); if ($res) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$f.'"'); header('Pragma: no-cache'); header('Expires: 0'); $row = $res->fetch_assoc(); if ($headings) { fputcsv($fp, array_keys($row),'|'); } do { fputcsv($fp, $row); } while ($row = $res->fetch_assoc()); } else echo "Error in query"; fclose($fp); } } ?> -
Export csv from mysql pipe Delimited
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Wow, I think im going insane, I've tried that with no luck is doesn't create a csv at all and doesn't download one. here's my code. $sql = 'SELECT * FROM newfies'; function sql2csv($db_mysqli, $sql, $filename='myNewfile.csv', $headings=0) { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $db_mysqli->query($sql); if ($res) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$f.'"'); header('Pragma: no-cache'); header('Expires: 0'); $row = $res->fetch_assoc(); if ($headings) { fputcsv($fp, array_keys($row),'|'); } do { fputcsv($fp, $row); } while ($row = $res->fetch_assoc()); } else echo "Error in query"; fclose($fp); } } } -
Export csv from mysql pipe Delimited
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
okay, so I have got the fputcsv working, and it is pulling out what i want and i can easily manipulate it now, but the headers give me an excel file with the webpage echo's When all I need is the CSV file that was created, If I FTP onto the server I can see the csv file with the correct fields // path to csv file to write data to $data_file = 'myNewfile.csv'; header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename='.$data_file); $result = $db_mysqli->query('SELECT * FROM newfies'); // open/create the csv file $handle = fopen($data_file, 'w'); // loop over results from query while($row = $result->fetch_row()) { // write row contents to csv file fputcsv($handle, $row, '|'); } fclose($handle); } -
Export csv from mysql pipe Delimited
moosey_man1988 replied to moosey_man1988's topic in PHP Coding Help
Excellent, will this also download the CSV, I have a submit button that performs the query and then downloads the CSv using header. will this do the same? -
Hi Everyone I'm pretty new to PHP and I have worked out how to do a CSV export from my contacts database which works perfectly. but I need to export a pipe delimited csv, which im really struggling with. This is how I need my csv to look like 1234567890|surname|forename|[email protected]|test-contact|1|address|city|state|US|unit| I just need help with the echoing out this file right. I have a while loop that grabs the data like so $data_string .= "\"" . $row['number'] ."\" "\"\n"; of course this only does the number but im sure you get the jist. any help given I thank in advance.
-
hi guys, i dont know why i got in such a cuffufle with that code... I decided to re-write it with a fresh head on and its owrking perfectly now just got to get it to remove the first row, but thats easy <?php include('header.php'); ?> <?php error_reporting(E_ALL); ini_set('display_errors', 1); if (!$_POST) { ?> <html> <body> <form action="" method="post" enctype="multipart/form-data"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <br /> <br /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> <?php } else { $connect = new mysqli("localhost","root","blah","PDNumbers"); if ($_FILES[csv][size] >0) { //get the csv file $file = $_FILES[csv][tmp_name]; $handle = fopen($file,"r"); $info = 0; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import = "INSERT IGNORE INTO LepusData (mobile,landline,title,forename,surname,Address1,Address2,Address3,Town,County,postcode) VALUES ( '$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[10]','$data[11]')"; $connect->query($import); } $info++; } fclose($handle); print "import done"; echo $info." records imported"; } ?> Thank you for all your help
-
well i tested the query in phpmyadmin but of course took out the $data variables and put in the top line from my CSV and it went in just fine, I am pretty new to php so im not the best at finding out issues yet, I'm going to take a loooong look through the script on monday and see if i can echo out the error as i really need to get this working. I have about 550 csv files to import, and i thought this will make my life easier lol, i found this so easy to do with mysql but mysqli is prooving more tricky to me, maybe because i dont understand its functions as well.
-
Well i changed it to one field to see if it would insert instead of blank fields, sorry i'm no pro at php that's for sure, I am okay at debugging php errors, but when it comes to debugging the mysql commands within php its where i get stuck, when i am working on a script i tend to tail -f /var/log/apache/error.log which usually gives me the info, but this one is working its just not putting in the entries, i'll have a look into php list thanks
-
Hi peeps I have been using mysql commands for most of my php coding, and i've been told it would be wise to move to mysqli im trying to create a csv upload to database page but its just adding blank fields can someone tell me where im going wrong? as my code wont tell me <?php include('header.php'); ?> <!DOCTYPE html> <head> <title>Upload New Numbers files to the database</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form action="importData.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" value="Upload file"> </form> </body> </html> <?php error_reporting(E_ALL); ini_set('display_errors', 1); if (isset($_FILES['uploaded_file'])) { //Make sure the file was sent without errors if ($_FILES['uploaded_file']['error'] == 0) { //connect to the database $mysqli = new mysqli ('localhost','root','','PDNumbers'); if (mysqli_connect_errno()) { die("Mysqli connection failed: ". mysqli_connect_error()); } //gather all the required data from the CSV $file= $_FILES['uploaded_file']['tmp_name']; $handle = fopen($file, "r"); $row= 1; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row == 1) { //skip the first row } else { //csv format like this //$data[0] = mobile number //$data[1] = landline //$data[2] = title //$data[3] = forename //$data[4] = surname //$data[5] = Address1 //$data[6] = Address2 //$data[7] = Address3 //$data[8] = blank field //$data[9] = Town //$data[10] = County //$data[11] = postcode } } } //$import_query = "INSERT IGNORE INTO LepusData (mobile,landline,title,forename,surname,Address1,Address2,Address3,Town,County,postcode) //VALUES ( //'".$data[0]."','".$data[1]."','".$data[2]."','".$data[3]."','".$data[4]."','".$data[5]."','".$data[6]."','".$data[7]."','".$data[8]."','".$data[10]."','".$data[11]."' //)"; $import_query = "INSERT INTO LepusData(mobile) VALUES ('".$data[0]."')"; $result = $mysqli->query($import_query); if ($result) { echo "Success! The file was added into the database"; } else { echo "Error! failed to insert the file"; } // close the mysqli connection $mysqli->close(); } else { echo "Error! The file was not sent!"; } ?> any help is greatly appreciated thanks oh forgot to add, I am ignoring data[9] on purpose, its a blank field
-
Hi guys so basically I've tried to do it as best i can but unfortunately it doesnt seem to be possible, but what someone did suggest is using something like convert or imagemagik that will convert the pdf into an image and then have them display as a scale-able image, I've got it to convert the pdf's just find but it does it page by page so what I'm left with is document.pdf (4 pages converted to) document1.jpg document2.jpg document3.jpg document4.jpg Does anyone know who i can display all these images on 1 page as a load of scalable images, like thumbnails that expand? e.g I have document1, document2, document3 with 100 by 100px but when mouse over, the scale to 1000,1400 px for example, I may draw an image to help explain if this is a little tricky to understand