Jump to content

Search the Community

Showing results for tags 'variable'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I have the following array: $available_seasons = array ( 0 => array ( 'season_id' => 226, 'season_name' => '2022 - Season 1', 'season_price' => '25.99', 'season_start_date' => 'Jan. 1, 2022', 'season_end_date' => 'Mar. 31, 2022', 'prize' => 100, ), 1 => array ( 'season_id' => 227, 'season_name' => '2022 - Season 2', 'season_price' => '28.99', 'season_start_date' => 'Apr. 1, 2022', 'season_end_date' => 'Jun. 30, 2022', 'prize' => 100, ), 2 => array ( 'season_id' => 238, 'season_name' => '2022 - Season 3', 'season_price' => '40.99', 'season_start_date' => 'Jul. 1, 2022', 'season_end_date' => 'Sep. 30, 2022', 'prize' => 230, ), 3 => array ( 'season_id' => 239, 'season_name' => '2022 - Season 4', 'season_price' => '30.65', 'season_start_date' => 'Oct. 1, 2022', 'season_end_date' => 'Dec. 31, 2022', 'prize' => 300, ), ) I'm using the following loop to create the form: echo "<form name='seasonForm' method=\"post\" action='execute.php'>"; foreach ( $available_seasons as $k => $season ) { echo "<input name='choice' class='uk-checkbox' type='checkbox' value='{$season[ 'season_price' ]}' onchange='checkTotal()'/>"; } echo "<button type='submit'>Continue</button>"; I have the following JS to calculate the total price: function checkTotal() { document.seasonForm.total.value = \'\'; var sum = 0; for (i=0;i<document.seasonForm.choice.length;i++) { if (document.seasonForm.choice[i].checked) { sum = sum + (document.seasonForm.choice[i].value *1); } } document.seasonForm.total.value = "Total: $" + sum; } I am showing the total price to my users, before they click on submit. As it is, I am only able to able to get the value of one checkbox, which is season_price in my execute.php. What I need is to pass the all season_id and season_price values of the selected checkboxes to execute.php. I am not sure how to do this. Thank you for your help in advance.
  2. Dear Friends, I am alot before doing the mixed content of php and HTML in single variable in PHP.. I could not get the data even though there is not SYNTAX error.. please look my code and advise $htmlcontent .=" <tr> <td colspan=\"8\">".$details."></td> </tr>"; for($k=0;$k<count($reg_years[$details]);$k++) { $year = (int)($reg_years[$details][$k]); $singlecount[$year] = array_filter($result[$details],function($details1) use ($year){ return ($details1['reg_year'] == $year && $details1['bench_type'] == 1); }); $divisioncount[$year] = array_filter($result[$details],function($details2) use ($year){ return ($details2['reg_year'] == $year && $details2['bench_type'] == 2); }); $fullcount[$year] = array_filter($result[$details],function($details3) use ($year){ return ($details3['reg_year'] == $year && $details3['bench_type'] >= 3); }); $rpcount[$year] = array_filter($result[$details],function($rp) use ($year){ return ($rp['reg_year'] == $year && $rp['bench_type'] == 'RP'); }); $mjccount[$year] = array_filter($result[$details],function($mjc) use ($year){ return ($mjc['reg_year'] == $year && $mjc['bench_type'] == 'MJC'); }); $cocount[$year] = array_filter($result[$details],function($co) use ($year){ return ($co['reg_year'] == $year && $co['bench_type'] == 'X'); }); $total = 0; $total = (int)(count($singlecount[$year])+count($divisioncount[$year])+count($fullcount[$year])+count($rpcount[$year])+count($mjccount[$year])+count($cocount[$year])); $htmlcontent .=" <tr> <td>".$year."</td> <td align=\"center\"> if(count($singlecount[$year])>0) { echo (count($singlecount[$year])); } else { echo "-"; } </td> <td align=\"center\"> if(count($divisioncount[$year])>0) { ".count($divisioncount[$year])." } else { "-" } </td> <td align=\"center\"> if (count($fullcount[$year]) > 0) { echo (count($fullcount[$year])); } else { echo "-"; } </td > < td align =\"center\"> if(count($rpcount[$year])>0) { echo (count($rpcount[$year])); } else { echo " - "; } </td> <td align=\"center\"> if(count($mjccount[$year])>0) { echo (count($mjccount[$year])); } else { echo " - "; } </td> <td align=\"center\"> if(count($cocount[$year])>0) { echo (count($cocount[$year])); } else { echo " - "; } </td> <td align=\"center\"> echo $total; </td> </tr>"; } } $htmlcontent .= "</tbody></table>"; $mpdf = new \Mpdf\Mpdf(); $mpdf->WriteHTML($htmlcontent); $mpdf->Output(); Waiting for FAST reply Thanks Anes
  3. Say I have this array. $block_io->get_current_price(array()); That array will give me this output. { "status" : "success", "data" : { "network" : "BTC", "prices" : [ { "price" : "1500.01", "price_base" : "AUD", "exchange" : "coinspot", "time" : 1488955012 }, { How can I convert the above output into individual variables? For eg. $status = 'success'; $network = 'BTC'; $price = '1500.01'; ...etc
  4. Hi All, couldn't seem to figure how to pass data from page 2 to page 1. On page 2 I have this code block: # if the form has been posted if ($_SERVER["REQUEST_METHOD"] == "POST") { # check for empty fields if (!empty(trim(($_POST['name'] == '')))) { $nameErr = "<span class=\"error\">Name is required</span>"; } if (!empty(trim(($_POST['email'] == '')))) { $emailErr = "<span class=\"error\">Email is required</span>"; } # if all is fine, then add data to the database else { $sql = 'INSERT INTO author SET name = :name, email = :email'; $query = $dbConnection -> prepare($sql); $query -> bindValue(':name', $_POST["name"]); $query -> bindValue(':email', $_POST["email"]); $query -> execute(); $message = 'done'; header('Location: index.php'); } } The variable $message I wanted to pass to page 1, where I have this in: <?php if(isset($_POST['message'])) { echo $_POST['message']; } ?> I can't seem to figure out the problem? Any tips? Thanks
  5. Hey! I want to create a website that can test your counting pace. I’ll make colored, square div that change color after 10 to 30 seconds when you hover over it, and then you’ll type down how long you think it took in a form to check if you’re right. My solution to do this is to create the PHP variable $time = rand(10,30), and in CSS get the div:hover transition-delay to be $time. Then, after the form, I need the same variable for if($_POST[timeguess] = $time) {echo “Correct!”}. I have no idea how to access the same variable in both the CSS and HTML, so I hope some of you can help me out! Thanks
  6. Below I have "Input" where it shows the original string. Basically I want to remove everything before " - ". I would like to know how can I get the "Output" results using PHP? Input $variable_1 = Lulu-free - Swimsuit swimwear red $variable_2 = Pap & Jones - Bard Mini Dress Output $variable_1 = Swimsuit swimwear red $Variable_2 = Bard Mini Dress
  7. I've got a function in my WordPress functions file that sends a Word doc based on what venue the ordered product is from. However I also need to be able to paste variables such as the customer name and others onto the specified word document. It also needs to be in specific places. How can I go about doing this? Please let me know if you have any idea or don't understand me! Thanks!
  8. Hello so I have a simple code here that will check if a random number already exists in the database and will generate a new one: $rand = mt_rand(100000, 999999); $sid = array( ":sponsorID" => $rand ); $accounts = $db->select("accounts", "sponsorID = :sponsorID", $sid) while(count($accounts) > 0) { $newNum = mt_rand(100000, 999999); } What I wanted to do is to echo out $newNum. When I echo it out I get undefined index of that variable. How can I solve this?
  9. Hi, I want to set a variable based on the contents of another variable - I think I've see CASE used for this before but not entirely sure. Basically I'm trying to tidy this up: if ($var1 = "1") { $var2 = "a" } if ($var1 = "2" ) { $var2 = "b" } if ($var1 = "3") { $var2 = "c" } Any help appreciated. Thanks.
  10. How can i Add Screen Resolution to PHP Variable and Echo it? i am quite confused on how to do this as getting resolution is done in javascript right? Please help me with this. i have coded my first wordpress theme and this is the only part i am stuck at p.s. I want to save screen height in different variable and screen width in different variable.
  11. I have a register form where a user enters a full name, email and password. I do not want to give them the option of choosing their own "username"; rather I want to automatically create the username from their "full name". So far I can create the username by removing space and symbols from full name. Like this. $fullname = trim($_GET['fullname']); $username = preg_replace('/\s+/', '', $fullname); Looking at that, John Smith would become "johnsmith". Since there could be dozens of people with the name "john smith", I was thinking of assigning unique number to each of them. Like this "johnsmith1", "johnsmith2", "johnsmith3"..etc. How would you say I go on incrementing the username like that?
  12. Alright I am so close but can not figure this out, thanks in advance for any help. So what I am trying to do is take the input variables from a form and have them load a specific PDF . <html> <body> <?php if( $_GET["startpoint"] || $_GET["endpoint"]) { $a = $_GET["startpoint"]; $b = $_GET["endpoint"]; echo "Your Startpoint is:". $_GET["startpoint"]. "<br />"; echo "Your Endpoint is: ". $_GET["endpoint"]. "<br />"; echo $a,$b,".pdf"; } ?> </body> </html> This is what I have and it works to display what the two points are what the final pdf file should be. The final echo generates the PDF name echo $a,$b,".pdf"; How can I get it to load a file using this as a variable or the name it generates, thanks.
  13. I have the following three links in same page. http://localhost/folder/file.php?x=link1 http://localhost/folder/file.php?x=link2 http://localhost/folder/file.php?x=link3 i want to show URLs as they are... link1 is to include a file named "x.php" link2 is to include a file named "y.php" link3 is to include a file named "z.php" Can it be done in php only? PS: its not about creating hash ids. and i want to do it without any sql db connection.
  14. I have a mysql field that I want to store a php variable in and then retrieve it. Example: Color table has the field named colorBackground with the value of #FF0000 CSS table has the field named cssBackground with the value of .background { background-color: #444444; } What I want to do is make Color/colorBackground a variable {{$backgroundcolor = rsColor['colorBackground'] Then I want to change the CSS/cssBackground value to .background { background-color:$backgroundcolor; } Creating the $backgroundcolor works fine. I'm just not sure how to put the $backgroundcolor in my CSS/cssBackground field.
  15. undefined variable errorString. what's wrong with this? Notice: Undefined variable: errorString in /Applications/XAMPP/xamppfiles/htdocs/finalproject/donate/thankyou.php on line 97 Notice: Undefined variable: messageString in /Applications/XAMPP/xamppfiles/htdocs/finalproject/donate/thankyou.php on line101 <?php require "config.php"; require "connect.php"; if(isset($_POST['submitform']) && isset($_POST['txn_id'])) { $_POST['nameField'] = esc($_POST['nameField']); $_POST['websiteField'] = esc($_POST['websiteField']); $_POST['messageField'] = esc($_POST['messageField']); $error = array(); if(mb_strlen($_POST['nameField'],"utf-8")<2) { $error[] = 'Please fill in a valid name.'; } if(mb_strlen($_POST['messageField'],"utf-8")<2) { $error[] = 'Please fill in a longer message.'; } if(!validateURL($_POST['websiteField'])) { $error[] = 'The URL you entered is invalid.'; } $errorString = ''; if(count($error)) { $errorString = join('<br />',$error); } else { mysql_query(" INSERT INTO dc_comments (transaction_id, name, url, message) VALUES ( '".esc($_POST['txn_id'])."', '".$_POST['nameField']."', '".$_POST['websiteField']."', '".$_POST['messageField']."' )"); if(mysql_affected_rows($link)==1) { $messageString = '<a href="donate.php">You were added to our donor list! »</a>'; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Thank you!</title> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <body class="thankyouPage"> <div id="main"> <h1>Thank you!</h1> <h2>Add Yourself to our Donor Section</h2> <div class="lightSection"> <form action="" method="post"> <div class="field"> <label for="nameField">Name</label> <input type="text" id="nameField" name="nameField" /> </div> <div class="field"> <label for="websiteField">Web Site</label> <input type="text" id="websiteField" name="websiteField" /> </div> <div class="field"> <label for="messageField">Message</label> <textarea name="messageField" id="messageField"></textarea> </div> <div class="button"> <input type="submit" value="Submit" /> <input type="hidden" name="submitform" value="1" /> <input type="hidden" name="txn_id" value="<?php echo $_POST['txn_id']?>" /> </div> </form> <?php if($errorString) { echo '<p class="error">'.$errorString.'</p>'; } else if($messageString) { echo '<p class="success">'.$messageString.'</p>'; } ?> </div> </body> </html> <?php function esc($str) { global $link; if(ini_get('magic_quotes_gpc')) $str = stripslashes($str); return mysql_real_escape_string(htmlspecialchars(strip_tags($str)),$link); } function validateURL($str) { return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i',$str); } ?>
  16. I've been baffled by this for 2 days now and cannot figure it out after exhaustive searches. I'd like to think I'm doing this correctly, but cannot get it to work. I'm trying to use a variable within a query WHERE statement, and it shows 0 results. If I directly hardcode the text instead of using the variable, it works. The variable is pulling from a $_GET, and if I echo that variable, it is showing the correct text. Here's my code: $Domain = $_GET['Domain']; $result = mysql_query(SELECT Code, Title, Domain, Status FROM tablename WHERE Domain="$Domain" ORDER BY Code'); If I swap out "$Domain" for direct text, like "ABC", it works. I have tried swapping out the quotes and single quotes throughout the statement, removing the quotes around $Domain, concatenating the statement separately....all yield erros or the same result. And as stated, if I echo $Domain, it shows "ABC" (or whatever it's supposed to show), so i know it's pulling correctly from the $_GET. Anyone know what I'm doing wrong?
  17. I'm new to php and i have a html form with 2 forms and 2 submit buttons, 1 of the forms is solely for uploading an image i downloaded the php script as i don't understand the code well enough to write it myself. The second form asks for your name and email then when you click submit it writes a new html file with the included information. I have managed to upload a file successfully and write the html document with the information successfully but i can't get the image to write into the html document. My file_upload.php script contains the variable for the image name, now how would i get the variable string from file_upload.php and use that name in compile.php. Here's my code. -------------- Form.html -------------- <!DOCTYPE html> <html lang="en"> <head> <title></title> </head> <body> <form action="compile.php" method="post"> <p>input name:<input type="text" name="name"/></p><br /> <p>email:<input type="text" name="email" /></p><br /> </form> <br /> <form enctype="multipart/form-data" method="post" action="file_upload.php"> Choose your file here: <input name="file1" type="file" /><br /><br /> <input type="submit" value="Upload It" /> </form> </body> </html> ------------- compile.php ------------- <?php $name = $_POST['name']; $price = $_POST['price']; $desc = $_POST['desc']; $file = "new.html"; $handle = fopen($file,'w'); $data = "<!DOCTYPE html> <html> <head> <title></title> </head> <body> <table style='border-radius:8px;'> <tr> <td style='border-radius:8px;'> <h1>$name</h1> </td> </tr> </table> <table> <tr> <td> <ul> <lh>Product name: $name</lh> <br><br> <li>Price: $price</li><br> <li>Description: $desc</li><br> </ul> </td> <td> <img src='uploads/$fileName' width='' height='' alt='' title='' /> </td> </tr> </table> </body> </html>"; fwrite($handle, $data); print "data written"; fclose($handle); ?> ------------ file_upload.php ------------ <?php // Set local PHP vars from the POST vars sent from our form using the array // of data that the $_FILES global variable contains for this uploaded file $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is $fileSize = $_FILES["file1"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true // Specific Error Handling if you need to run error checking if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } else if($fileSize > 5000000000) { // if file is larger than we want to allow echo "ERROR: Your file was larger than 5mb in file size."; unlink($fileTmpLoc); exit(); } else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) { // This condition is only if you wish to allow uploading of specific file types echo "ERROR: Your image was not .gif, .jpg, or .png."; unlink($fileTmpLoc); exit(); } // Place it into your "uploads" folder mow using the move_uploaded_file() function move_uploaded_file($fileTmpLoc, "uploads/$fileName"); // Check to make sure the uploaded file is in place where you want it if (!file_exists("uploads/$fileName")) { echo "ERROR: File not uploaded<br /><br />"; echo "Check folder permissions on the target uploads folder is 0755 or looser.<br /><br />"; echo "Check that your php.ini settings are set to allow over 2 MB files, they are 2MB by default."; exit(); } // Display things to the page so you can see what is happening for testing purposes echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />"; echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />"; echo "It is a <strong>$fileType</strong> type of file.<br /><br />"; echo "The Error Message output for this upload is: <br />$fileErrorMsg"; ?>
  18. Hi all, So im trying to improve on my PHP as my knowledge isn't that great. lets say for argument sake my ip is: 192.168.0.1 im trying to set a external variable to set this as the url. so on each page i use, for each link instead of typing out the ip address i can simply type: <a href="{url}/index.php">Home</a> and then if it is possible, to do something like this: <link rel="stylesheet" href="{url}/main.css" type="text/css"> all in one file so in my php pages i can simple include 1 php file and it will have all of the relevant stylesheets ect linked to it.
  19. Hello, I'm running php using classes and here's my dilema. I have a web form that pull data from an MySQL database as a <SELECT> <OPTION> drop down as a while loop; I have two while loops and no problem getting data for each. I have no problem calling the data for the <OPTION> however I need to pull two pieces of information and the <OPTION> from what I know only pulls one. The second while loop from the "sender" table has a "sender_name" & "sender_email". My problem is I can only have one value in the <OPTION> tag but I need to $POST two variables. when I select my drop down which only displays "sender_name" I would like to post "sender_email" so that I can echo this in my functions page for other things. My MySQL table for "sender" has the following: sender_id, sender_name, sender_email Plan is to create an Entry Form > Form Submitted > Data is run and verified on functions page > if Good execute code and send email to sender with details of the entry data... Currently I have it working if I enter a static email address in the mail() function however I would like when the Entry Form is filled out for it to pull the "sender_email" from the associated "sender_name" on that table as a variable to the functions page which has a mail() script Should I be using JavaScript or another PHP function? Thank you in advance, my code below My form: <form method="post" action="form-post.php"> <input type="hidden" name="add-tracking" value="true" /> <input type="hidden" name="tracking_method_id" id="tracking_method_id" value="2" /> <table> <tr> <td><label for="tracking_number">Tracking Number:<br />(No Dashes)</label></td> <td><input type="text" name="tracking_number" id="tracking_number" /></td> </tr> <tr> <td><label for="tracking_recepient">Tracking Recepient:</label></td> <td><input type="text" name="tracking_recepient" id="tracking_recepient" /></td> </tr> <tr> <td><label for="tracking_date">Tracking Date:<br />(YYYY-MM-DD)</label></td> <td><input type="text" name="tracking_date" id="tracking_date" value="<?php echo date('Y-m-d');?>" /></td> </tr> <tr> <td><label for="tracking_cost">Cost $:</label></td> <td><input type="text" name="tracking_cost" id="tracking_cost" value="0.0000" /></td> </tr> <tr> <td><label for="tracking_dept">Dept:</label></td> <td><select name="tracking_dept" id="tracking_dept"> <option value=""></option> <?php $sql = "SELECT * FROM department"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)) { echo '<option value="' . $row['dept_name'] . '">' . $row['dept_name'] . '</option>';} ?> </select></td> </tr> <tr> <td><label for="tracking_requestor">Requested By:</label></td> <td><select name="tracking_requestor" id="tracking_requestor"> <option value=""></option> <?php $sql1 = "SELECT * FROM sender"; $res1 = mysql_query($sql1) or die(mysql_error()); while($row1 = mysql_fetch_assoc($res1)) { echo '<option value="' . $row1['sender_name'] . '" $row1>' . $row1['sender_name'] . '</option>'; } ?> </select></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> My Function function add_tracking($p) { $tracking_id = mysql_real_escape_string($p['tracking_id']); $tracking_number = mysql_real_escape_string($p['tracking_number']); $tracking_recepient = mysql_real_escape_string($p['tracking_recepient']); $tracking_date = mysql_real_escape_string($p['tracking_date']); $tracking_cost = mysql_real_escape_string($p['tracking_cost']); $tracking_dept = mysql_real_escape_string($p['tracking_dept']); $tracking_requestor = mysql_real_escape_string($p['tracking_requestor']); $tracking_method_id = mysql_real_escape_string($p['tracking_method_id']); $tracking_number = preg_replace('/[^a-zA-Z0-9s]/', '', $tracking_number); $headers = ""; $headers .= "From: Anaheim Receiptionist <anaheimreceptionist@powerplus.com>\n"; $headers .= "X-Sender: anaheimreceptionist@powerplus.com\n"; $headers .= "X-Mailer: PHP\n"; $headers .= "X-Priority: 3\n"; $headers .= "Content-Type:text/html; charset=\"iso-8859-1\"\n"; $message = ' <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style type="text/css"> .right {text-align: right; min-width: 150px;} * {font-family: arial, tahoma, "Times New Roman";} body {font-size: 15px;} #wrap {width:550px; margin: 0 auto;} </style> </head> <body> <div id="wrap"> <p><h1>Your Shipping Item Is Scheduled For Delivery</h1></p> <p><h3>Below Is Your Details:</h3></p> <div style="border: 1px solid #000000;"> <table cellpadding="5"> <tr> <td class="right">Date: </td><td>' . $tracking_date . '</td> </tr> <tr> <td class="right">Sent To: </td><td>' . $tracking_recepient . '</td> </tr> <tr> <td class="right">Tracking Number: </td><td><a href="' . $row1['method_link'] . $tracking_number . '">' . $tracking_number . '</a></td> </tr> <tr> <td class="right">Department No: </td><td>' . $tracking_dept . '</td> </tr> <tr> <td class="right">Sent By: </td><td>' . $tracking_requestor . '</td> </tr> </table> </div> </div> </body> </html> '; if(!$tracking_number || !$tracking_recepient || !$tracking_date || !$tracking_cost || !$tracking_dept || !$tracking_requestor): if(!$tracking_number): echo '<p>The Tracking Number is required</p>'; endif; if(!$tracking_recepient): echo '<p>The Recepient Name is Required</p>'; endif; if(!$tracking_date): echo '<p>The Tracking Date is Required</p>'; endif; if(!$tracking_cost): echo '<p>The Tracking Amount is Required</p>'; endif; if(!$tracking_dept): echo '<p>The Tracking Dept is Required</p>'; endif; if(!$tracking_requestor): echo '<p>The Requested By Name is Required</p>'; endif; echo '<p><a href="tracking-method.php">Try again!</a></p>'; else: $sql = "INSERT INTO tracking VALUES (null, '$tracking_number', '$tracking_recepient', '$tracking_date', '$tracking_cost', '$tracking_dept', '$tracking_requestor', '$tracking_method_id')"; $res = mysql_query($sql) or die(mysql_error()); echo '<p>Added Sucessfully</p>'; echo '<p><img src="ok.png" />'; echo '<p><a href="index.php">Go Back to Tracking # Table</a></p>'; mail($sender_email, 'Your Tracking ID: ' . $tracking_number, $message, $headers); endif; }
  20. Hello All: I am not very familiar with php, and need some advice about how to do something. Really appreciate a little advice. I am making a forum with MODX, it has a module for forums called Discuss. Discuss has a built-in functionality to organize new topics into questions or discussions, regardless of the board a topic is in. So when you try to make a new topic it has got two buttons, question or discussion, and if you don't choose one it throws an error (its suppose to warn you but doesn't now). I want to remove this function completely, not because of the error but just because its not suitable for my site which is not a support site. I don't care if the system considers all posts as questions, or as discussions, I just want the users to not have to choose and they can just post their topics, no buttons, no choice, and no error. Removing the buttons is easy enough, but I need to change a little php to tell the system to either not need this info, or just give it a default variable so that the user can post (I don't know the variable names right now but that is next I guess). Anyway, here is the code which will probably be clearer than the above: $discuss =& $modx->discuss; $modx->lexicon->load('discuss:post'); $fields = $hook->getValues(); unset($fields[$submitVar]); if (empty($fields['board'])) return $modx->error->failure($modx->lexicon('discuss.post_err_ns')); $board = $modx->getObject('disBoard',$fields['board']); if ($board == null) return false; My first thought was to change the "If empty" line, and tell it, if empty then return (one of the two possible values). Then, everything would be ok, it seems to me. But could I also just strip out the check for the variable completely? If I took out the three lines starting with $fields all the way to the "If empty" line, wouldn't that mean the check is gone and the post will post without concern that this value doesn't exist? Or would this set off the system somehow (as it presumably never contemplated that this value would not be there)? Or, am I barking up the wrong tree here? Really looking forward to some advice about this. Thanks in advance!
  21. This is the function I am currently working with... /** * Retrieve search query text * * @return string */ public function getQueryText() { if (!isset($this->_queryText)) { $this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName()); $noescape = preg_replace("/%u([0-9a-f]{3,4})/i","\\1;",urldecode($this->_queryText)); if ($this->_queryText === null) { $this->_queryText = ''; } else { /* @var $stringHelper Mage_Core_Helper_String */ $stringHelper = Mage::helper('core/string'); $this->_queryText = is_array($this->_queryText) ? '' : $stringHelper->cleanString(trim($this->_queryText)); echo '<span style="display: none;">'; echo '<pre>'; var_dump ( $noescape ); echo '</pre>'; echo '</span>'; $maxQueryLength = $this->getMaxQueryLength(); if ($maxQueryLength !== '' && $stringHelper->strlen($this->_queryText) > $maxQueryLength) { $this->_queryText = $stringHelper->substr($this->_queryText, 0, $maxQueryLength); $this->_isMaxLength = true; } } } return $this->_queryText; } I can echo what I need to output in this function with $noescape however I need to modify return $this->_queryText; to include the preg_replace and rawurldecode from $noescape. Please could someone be kind enough to advise of the correct syntax/way of handling this? I did post this on StackOverflow but had no response as of yet. Thanks in advance.
  22. so i found a pdo class to connect to mysql with pdo and looks easy to customize however i have an error that i can't figure it out class <?php class ApplicationResourcePool { static var $_dbHandle; // line 5 private static $_dbConfig = array( 'dsn' => 'mysql:dbname=vax', 'username' => 'vax', 'password' => 'veryrandpasswd', ); public static getDbHandle(){ if(self::$_dbHandle == null){ self::$_dbHandle = new PDO( self::$_dbConfig['dsn'] , self::$_dbConfig['username'], self::$_dbConfig['password'] ); } return self::$_dbHandle; } } class StockMapper { protected $_dbh; public __construct($dbh = null) { if($dbh == null){ $this->_dbh = ApplicationResourcePool::getDbHandle(); } else { $this->_dbh = $dbh; } } public getStockById($stockId){ $sth=$this->_dbh->prepare("SELECT * from stock WHERE id = :stockId"); $sth->bindParam(":stockId", $stockId); $sth->execute(); $result = $sth->fetch(PDO::FETCH_ASSOC); return $result[0]; } } $stockMapper = new StockMapper(); $stockData = $stockMapper->getStockById('302'); ?> Parse error: syntax error, unexpected 'var' (T_VAR), expecting variable (T_VARIABLE) in /path/index.php on line 5 i really don't know what to do
  23. Hey guys, I am learning some basic OOP rules and application right now. I was trying to understand setting a property inside of an object. $name = $_GET['user']; if(isset($name)){ class BankAccount{ public $balance = 3500; public function DisplayBalance(){ return $name . ' your Balance Currently is: ' .$this->balance; } public function Withdraw($amount){ $balance = $this->balance; if($balance < $amount){ $this->balance = 'Sorry you can\'t withdraw any funds right now, not enough to cover amount request of: $' .$amount . '. '; } else{ $this->balance = $this->balance-$amount; } } } So here i am trying to add an extra property into this class by grabbing the variable of $name, which is a dynamic string given from a user submit form. When i add public $user = $name; || $user = $name; I get an error, so my syntax is wrong So ultimately my question is, how do i correctly add the variable of $name into my class ? thanks guys,
  24. Hi, I'm trying to pass a variable from my php script on the page into the og;metadata, but on the timeline all that is shown is the standard html metadata, am I using the correct php code to call the variable so that it shows up on the timeline? <meta property="og:title" content="<?php $_GET['$title']; ?>"/> the title variable comes from here; $title = urlencode("Take The Test!"); Any help on this is much appreciated, Gareth
  25. Howdy folks, I am trying to get sessions to cooperate, but am at a loss. I am trying to copy the variable of userlevel in a session. The array displays correctly on pointerface.php. For some reason, the session doesn't seem to carry over to other pages, and the session ID's are different. I'd appreciate some input as to where I may be going wrong. pointerface.php: session_start(); { include('../htconfig/dbConfig.php'); mysql_connect("$hostname","$username","$password"); mysql_select_db("$database")or die("cannot select DB"); $tbl_name="members"; $sql2="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'"; $result2=mysql_query($sql2); $userlevel=mysql_result($result2,$i,"userlevel"); $_SESSION["userlevel"] = "$userlevel" ; echo session_id(); echo "<br>"; Print_r ($_SESSION); adminnotes.php: session_start(); print_r ($_SESSION); echo session_id(); if($_SESSION['userlevel']=='Admin'){
×
×
  • 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.