PHP - Variable = Variable + Number - Script Not Working
I have a script that adds points together based upon the placing. This is the actual script:
Code: [Select] <? $points = 0; if($place === '1st') {$points = $points + 50;} elseif($place === '2nd') {$points = $points + 45;} elseif($place === '3rd') {$points = $points + 40;} elseif($place === '4th') {$points = $points + 35;} elseif($place === '5th') {$points = $points + 30;} elseif($place === '6th') {$points = $points + 25;} elseif($place === '7th') {$points = $points + 20;} elseif($place === '8th') {$points = $points + 10;} elseif($place === '9th') {$points = $points + 10;} elseif($place === '10th') {$points = $points + 10;} elseif($place === 'CH') {$points = $points + 50;} elseif($place === 'RCH') {$points = $points + 40;} elseif($place === 'TT') {$points = $points + 30;} elseif($place === 'T5') {$points = $points + 30;} elseif($place === 'Champion') {$points = $points + 50;} elseif($place === 'Reserve Champion') {$points = $points + 40;} echo "Total HF Points: $points"; ?>What it *should* do (my friend's script works the same way and it works) it starts at points = 0, than if there is a first place, it adds 50, and so forth until it reaches the end. It is included into a file, in this area: Code: [Select] <div class="tabbertab"> <h2>Records</h2> <? $query92 = "SELECT * FROM THISTABLE WHERE VARIABLE='$id' OR VARIABLE = '$name' ORDER BY ABS(VARIABLE), VARIABLE"; $result92 = mysql_query($query92) or die (mysql_error()); echo "<table class='record'> <tr><th>Show</th> <th>Class</th> <th>Place</th></tr> "; while($row92 = mysql_fetch_array($result92)) { $class = $row92['class']; $place = $row92['place']; $entries = $row92['entries']; $race = $row92['show']; $purse = number_format($row92['purse'],2); echo "<tr><td>$race</td> <td>$class</td> <td>$place</td></tr>"; } ?> <tr><td colspan='3'><div align='right'><? include('includes/points.php'); ?></div></td></tr> </table> </div> This is the code that is relevant. When ended here, it echoes the last place that appears in the results (such as a 5th place echoing 30 points). When I move it to be included in the while loop, it shows Total Points: 50 Total Points: 25 Total Points: 10 (depending on the results displayed on that page). What am I doing wrong? Similar TutorialsHello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu Hi, I'm just starting PHP and I ran into a simple problem (that I can fix), but I just want to understand why my first approach doesn't work. I was testing multiplications and additions and the result I got was unexpected. Here is the code that doesn't work: Code: [Select] <?php $number1 = 5; $number2 = 10; print $number1." multiplied by ".$number2." + 1000 = ".$number1*$number2+1000; ?> Obviously, what I want as a result when I'm displaying the page is: "5 multiplied by 10 + 1000 = 1050" What I get: "1005". That's right, nothing else. On top of getting an erroneous answer, the sentence that's supposed to display right before the equation doesn't display at all. It's even worse if I switch it around like that: Code: [Select] print $number1." multiplied by ".$number2." + 1000 = ".1000+$number1*$number2; I get an error message and nothing displays. The obvious solution works: using a parenthesis at the beginning and at the end of the equation, which I should do regardless, but still, it's bugging me and since I just started learning PHP today, I want to understand how the code is compiled / interpreted so I don't make stupid mistakes like this one. Thanks in advance for the replies. Hi Guyz, I need to check the variable $itemDescription to see if the client has entered a '1' before the item description(example: 1 table) Reason, is the client would like to add sales tax to all NOn-Food related items of 6.25% This is for a local auction house. It needs to be simple. i,e. Don't wanna add any more form fields. Just let the user type the number 1 before all items that need to be taxed. Here's my code: Code: [Select] <?php ob_start(); ?> <link rel="stylesheet" href="style.css" type="text/css"> <style type="text/css"> </style> </head> <?PHP session_start(); ob_start(); # Config settings below # Change these to whatever you want :) ############################# $cellsPerRow = '6'; ############################# include('connect.php'); // These queries get the amount of bidders that are in the database $getAllBidders = mysql_query("SELECT `id` FROM bidders"); $totalBidders = mysql_num_rows($getAllBidders); // This section is to check if the Add New Item form has been submitted if($_POST['addNewItem']) { // Retrieve Query Strings from URL $itemDescription = $_POST['itemDescription']; $itemPrice = $_POST['itemPrice']; $winningBidder = $_POST['winningBidder']; $totalDeals = $_POST['totalDeals']; $totalPrice = ($totalDeals*$itemPrice); // Check the submitted data and make sure all is correct if(!$itemDescription) { $message = 'You must enter an Item Description.'; } else if(!$itemPrice) { $message = 'You must enter an Item Price.'; } else if(!$winningBidder) { $message = 'You must enter a Winning Bidder ID.'; } else if(!$totalDeals) { $message = 'You must enter the amount of Deals.'; } else if(!is_numeric($winningBidder)) { $message = 'The Winning Bidder ID can only be numbers.'; } else { // Check to see if the bidder ID already exists $checkBidder = mysql_query("SELECT * FROM bidders WHERE biddersId='$winningBidder' LIMIT 1"); $checkBidder = mysql_fetch_assoc($checkBidder); // If the Bidder ID does not exist, we re-direct to allow us to save the Bidder ID if(!$checkBidder) { header("Location: ?action=confirmListing&iDesc=".$itemDescription."&iPrice=".$itemPrice."&wBidder=".$winningBidder."&tDeals=".$totalDeals.""); } else { // If Bidder ID exists we just insert the transaction accordingly mysql_query("INSERT INTO transactions (`itemDescription`, `itemPrice`, `bidderId`, `itemQty`, `totalPrice`) VALUES ('$itemDescription', '$itemPrice', '$winningBidder', '$totalDeals', '$totalPrice');"); $message1 = 'The transaction has been successfully added.'; mysql_query("SELECT owed From bidders WHERE biddersId='$winningBidder'") or die(mysql_error()); if ($row['owed']==0) { mysql_query("UPDATE bidders SET owed='1' WHERE biddersId='$winningBidder'") or die(mysql_error()); } } } } // This section is to check if the Add Bidder to database form has been submitted if($_POST['confirmBidder']) { $itemDescription = $_POST['itemDescription']; $itemPrice = $_POST['itemPrice']; $winningBidder = $_POST['winningBidder']; $totalDeals = $_POST['totalDeals']; $totalPrice = ($itemPrice*$totalDeals); $addBidder = $_POST['addBidder']; $checkInput= preg_match([1]+*); if ($itemDescription== $checkInput) $itemPrice= $itemPrice * 6.25%; mysql_query("INSERT INTO transactions (`itemDescription`, `itemPrice`, `bidderId`, `itemQty`, `totalPrice`) VALUES ('$itemDescription', '$itemPrice', '$winningBidder', '$totalDeals', '$totalPrice');"); $message1 = 'The transaction has been successfully added.'; if($addBidder == 'Yes') { mysql_query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder');"); $message1 .= '<br> The Bidder ID has also been added.'; mysql_query("SELECT owed From bidders WHERE biddersId='$winningBidder'") or die(mysql_error()); if ($row['owed']==0) { mysql_query("UPDATE bidders SET owed='1' WHERE biddersId='$winningBidder'") or die(mysql_error()); } } if($addBidder == 'No') { $message1 = '<br><font color= "red"> Bidder has NOT been logged.</font>'; } // $itemDescription = ''; // $itemPrice = ''; // $winningBidder = ''; // $totalDeals = ''; // $totalPrice = ''; // $addBidder = ''; } ?> <?PHP // This line of code will check the current task we are doing if($_GET['action'] == 'confirmListing') { $itemDescription = $_GET['iDesc']; $itemPrice = $_GET['iPrice']; $winningBidder = $_GET['wBidder']; $totalDeals = $_GET['tDeals']; ?> <form name="confirmBidder" method="POST" action="?"> <?PHP // This is the hidden data from the previous form // Better than using sessions and GET query ?> <input type="hidden" name="itemDescription" id="itemDescription" value="<?PHP echo $itemDescription;?>"> <input type="hidden" name="itemPrice" id="itemPrice" value="<?PHP echo $itemPrice;?>"> <input type="hidden" name="winningBidder" id="winningBidder" value="<?PHP echo $winningBidder;?>"> <input type="hidden" name="totalDeals" id="totalDeals" value="1"> <table cellpadding="0" cellspacing="1" border="0" style="background: #ffffff; margin: auto;"> <tr> <td colspan="2" class="formHeader"> Add New Auction Item </td> </tr> <tr> <td class="formField"> Add This Bidder? </td> <td class="formValue"> <select name="addBidder" id="addBidder" class="input" style="width: 195px;"> <option value="Yes">Yes</option> <option value="No">No</option></select> </td> </tr> <tr> <td colspan="2" class="formButton"> <input type="submit" name="confirmBidder" id="confirmBidder" value="Confirm Bidder Action?"> <input type="reset" name="reset" id="reset" value="Reset Form"> </td> </tr> </table> </form> <?PHP // If the action is not to confirm a listing then show add item section } else { ?> <?PHP//----- Add New Item Section -----\\?> <?PHP if($message) { echo '<div class="Error">',$message,'</div><div style="height: 10px;"></div>'; } else if($message1) { echo '<div class="Success">',$message1,'</div><div style="height: 10px;"></div>'; } ?> <form name="addNewItem" method="POST" action="?"> <table cellpadding="0" cellspacing="1" border="0" style="background: #ffffff; margin: auto;"> <tr> <td colspan="2" class="formHeader"> Add New Auction Item </td> </tr> <tr> <td class="formField"> Item Description </td> <td class="formValue"> <input type="text" name="itemDescription" class="formText" id="itemDescription" value="<?=$itemDescription;?>" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> Item Price </td> <td class="formValue"> <input type="text" name="itemPrice" class="formText" id="itemPrice" value="<?=$itemPrice;?>" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> Winning Bidder ID </td> <td class="formValue"> <input type="text" name="winningBidder" class="formText" id="winningBidder" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> How Many Deals? </td> <td class="formValue"> <input type="text" name="totalDeals" class="formText" id="totalDeals" value="1" style="width: 195px;"> </td> </tr> <tr> <td colspan="2" class="formButton"> <input type="submit" name="addNewItem" id="addNewItem" value="Add New Auction Item?"> <input type="reset" name="reset" id="reset" value="Reset Form"> </td> </tr> </table> </form> <?PHP//----- Add New Item Section -----\\?> <?PHP } ?> All help appreciated to the fullest... I have the following code in my index.php: <?php $files = array(); $files = glob('download/*.iso'); $file = $files[count($files) - 1]; $strlen ( string $file ) : int /* length of $file */ $filelen = $strlen -9 /* length of unwanted characters - "download/" */ $filename = /* how do I get the filename starting at the 10th position */ ?> <div class="container"> <div class="divL"> <h3>Get the latest version of FoxClone iso</h3> <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt="" width="200" height="60"></a> I'd like to replace "Get the latest version of FoxClone iso" in the next to last line with "Get Foxclone "<?php echo "/{$filename}";?>". How do I extract just the file name from $file? I know that I have to:
1. get the length of $file Step 3 is where I just don't know how to accomplish the task. I'd appreciate some help on this.
Thanks in advance, how can you increase the page number in the following line until $status returns an empty result? curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: xxxxxxxxxxxxx:xxxxxxxxxxxxxxxx", "Page: 2")); I'm new at PHP and have a problem. I have a MySql database with lists of students grouped into classrooms. A typical group is shown in the attached screenshot screenshot.docx. I want to be able to select one or more of the names by using the associated checkbox, and upgrade a student or students into a different group as defined in the radio button list also in the screenshot. I have the rudiments of the file attached, but I have absolutely no idea how I can post the array so that the records are updated. Each student has an individual record with a field name userGroup which holds a string nominated by their classroom teacher, such as "year7", "year 8" and so on while they are in one of the several classrooms, but when they leave school this is recorded in a field named noGroup with a value of 0 or 1. I can post further details as required, but it would be great if someone could help me. Hi, How can I check if a variable only has these characters: - number (0-9) - decimal point (.) - positive (+) - negative (-) - dollar ($) I tried is_numeric, but it doesn't like negative values... I need to add the variable value to another variable. I have to accept numbers (including negative and decimals)... ex: 0.1 = TRUE -.1 = TRUE 12 = TRUE 1000.00 = TRUE 12a = FALSE thanks Hi everyone, Like the title says I need to count the amount of 1's in a column but I can't figure out how. Gr and thanx already Ryflex I'm trying to increase the variables $schedulemonth, $scheduledate, $scheduleyear in each loop so that they look like $schedulemonth1, $schedulemonth2, $schedulemonth3, etc... for each of them. I've tried several options and know I'm on the right track, but no go. The customer will choose how many payments and the script below will loop that many times - I have that part working - but the calendar I'm using with the variables above is the issue. Here's the code I'm using. while ($balance > 0){ if ($balance>$monthlypayment){ $myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear); //output the calendar $myCalendar->writeScript(); echo " "; echo "<input type=\"text\" name=\"payment" . $monthlypayment . "\" value=\"" . $monthlypayment . "\">\n"; $paymenttotal=($monthlypayment+$paymenttotal); $balance=round(($invoicetotal-$paymenttotal),2); echo " Balance: $balance\n"; $schedulemonth++; if ($schedulemonth==13){ $schedulemonth=1; $scheduleyear=($scheduleyear+1); } echo "<br>\n"; } if ($balance<$monthlypayment||$balance==$monthlypayment){ $myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear); //output the calendar $myCalendar->writeScript(); echo " "; echo "<input type=\"text\" name=\"payment" . $paymentnumber . "\" value=\"" . $balance . "\">\n"; $paymenttotal=($balance+$paymenttotal); $balance=round(($invoicetotal-$paymenttotal),2); echo " Balance: $balance\n"; $schedulemonth++; if ($schedulemonth==13){ $schedulemonth=1; $scheduleyear=($scheduleyear+1); } echo "<br>\n"; } } Additionally it needs to pick up each of these variables on the next page the variables are part of hidden fields in an form later in the page. So my question is actually 3 fold. 1. How do I increase the variable count in the loop above. 2. How do I put the <input type="hidden".......> in the form so that it loops through and catches the increasing variables 3. How do I loop through on the insertion page after the form is submitted to catch how many inserts to the database are needed. This one has me bent over. Hello all. I am very new to PHP, and I am not sure where to look or what I'm looking for in my current assignment. My task is to take in two numbers between 0-100. Once I take in that number, it should state beside it "The __ was accepted." The program should not accept any numbers greater than 100 or any characters. Once I do this, I must take a second number and do a similar thing. Finally, I must have a statement show up at the bottom stating which number is greater. Essentially, I need help in determining what I should use to place parameters, and how I can keep the program from echo ing any statement until input has been taken and tested for parameters. Any help you can provide will be greatly appreciated! I am trying to allow the user to update a variable he chooses by radio buttons, which they will then input text into a box, and submit, to change some attributes. I really need some help here. It works just fine until I add the second layer of variables on top of it, and I can't find the answer to this question anywhere. <?PHP require('connect.php'); ?> <form action ='' method='post'> <select name="id"> <?php $extract = mysql_query("SELECT * FROM cars"); while($row=mysql_fetch_assoc($extract)){ $id = $row['id']; $make= $row['make']; $model= $row['model']; $year= $row['year']; $color= $row['color']; echo "<option value=$id>$color $year $make $model</option> ";}?> </select> Which attribute would you like to change?<br /> <input type="radio" name="getchanged" value="make"/>Make<br /> <input type="radio" name="getchanged" value="model"/>Model<br /> <input type="radio" name="getchanged" value="year" />Year<br /> <input type="radio" name="getchanged" value="color" />Color<br /><br /> <br /><input type='text' value='' name='tochange'> <input type='submit' value='Change' name='submit'> </form> //This is where I need help... <?PHP if(isset($_POST['submit'])&&($_POST['tochange'])){ mysql_query(" UPDATE cars SET '$_POST[getchanged]'='$_POST[tochange]' where id = '$_POST[id]' ");}?> Hi guys, I have a problem with the code on below. When I input the value into $name and $email method, the page come into blank page. <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $name = clean($_GET['name']); $email = clean($_GET['email']); $comments = clean($_GET['comments']); $type = clean($_GET['type']); if($name == '') { $errmsg_arr[] = 'name or member ID missing'; $errflag = true; } if($email == '') { $errmsg_arr[] = 'email address ID missing'; $errflag = true; } else { } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['name'])) { $insert[] = 'name = \'' . clean($_GET['name']) .'\''; // echo "tested"; } if(isset($_GET['email'])) { $insert[] = 'email = \'' . clean($_GET['email']) . '\''; } if(isset($_GET['type'])) { $insert[] = 'type = \'' . clean($_GET['type']) . '\''; } if(isset($_GET['comments'])) { $insert[] = 'comments = \'' . clean($_GET['comments']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $email = $_GET['email']; $headers = "From: "$email"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $email ."; mail($to, $subject, $message, $headers, $add); } echo "Thank you for sent us your email"; } } } ?> There must be the problem coming from this: if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $email = $_GET['email']; $headers = "From: "$email"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $email ."; mail($to, $subject, $message, $headers, $add); } I am not sure where the problem is, so please could you help me?? I have this script and i want to take this in one variable & print where i want is this possible Code: [Select] if ($nro > 0) { echo "<table id='gridview' align='center'> <tr> <td bgcolor='#99CC00'>E.T.D.</td> <td bgcolor='#99CC00'>E.T.A.</td> <td bgcolor='#99CC00'>Quantity</td> </tr>"; $totqty=0; while ($row=mysql_fetch_array($result)) { $etd = $row['etd']; $etd = GetDateUserFormat($etd); $eta = $row['eta']; $eta = GetDateUserFormat($eta); $qty = $row['shptqty']; echo "<tr>"; echo "<td>" . $etd . "</td>"; echo "<td>" . $eta . "</td>"; echo "<td>" . $qty . "</td>"; echo "</tr>"; $totqty = $totqty + $qty; } $remqty = $styleqty - $totqty; echo "<br>"; echo "<tr>"; echo "<td bgcolor='#99CC00' colspan='2'> Total Entered Quantity</td>"; echo "<td>" . $totqty . " Kg.</td>"; echo "<td bgcolor='#99CC00'> Remaining Quantity</td>"; echo "<td>" . $remqty . " Kg.</td>"; echo "</tr>"; echo "</table>"; } My login script stores the user's login name as $_SESSION[ 'name'] on login. For some unapparent reason, i'm getting errors stating that $user and $priv are undefined variables, though I've attempted to define $user as being equal to $_SESSION['name'], using $user to look up the the user's privilege level (stored as the su column ) in the SQL table, and then where the result of the sql query is $priv which is then evaluated in an if statement. I can't seem to figure out why this might not be working. The code I'm using: <?php session_start(); function verify() { //verify that the user is logged in via the login page. Session_start has already been called. if (!isset($_SESSION['loggedin'])) { header('Location: /index.html'); exit; } //if user is logged in, we then lookup necessary privleges. $_SESSION['name'] was written with the login name upon login. Privleges // are written in db as a single-digit integer of of 0 for users, 1 for administrators, and 2 for special users. $user === $_SESSION['name']; //Connect to Databse $link = mysqli_connect("127.0.0.1", "database user", "password", "database"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //SQL Statement to lookup privlege information. if ($result = mysqli_query($link, "SELECT su FROM accounts WHERE username = $user", MYSQLI_STORE_RESULT)) { //LOOP TO CYCLE THROUGH SQL RESULTS AND STORE Privlege information as vairable $priv. while ($row = $result->fetch_assoc()) { $priv === $row["su"]; } } // close SQL connection. mysqli_close($link); // Verify privleges and take action. Only a privlege of "1" is allowed to view this page. A privlege of "2" indicates special //accounts used in other scripts that have certain indermediate additional functions, but are not trusted administrators. if ($priv !== 1) { echo $_SESSION['name']; echo "you have privlege level of $priv"; echo "<br>"; echo 'Your account does not have the privleges necessary to view this page'; exit; } } verify(); ?>
I have just re-installed Xampp and suddenly my sites are now displaying lots of: Notice: Use of undefined constant name - assumed 'name' in ... Notice: Use of undefined constant price - assumed 'price' in ... this is an example of the line its refering too: $defineProducts[1001] = array(name=>'This is a product', price=>123); Hi, I have a variable named $siteName stored in the server.php file in the data directory data/server.php Now in the header.php page I want to retrieve the $siteName variable so it can be used in the header information. This is what I have but it isnt working. server.php Code: [Select] <?php $siteName = 'My+Test+Site'; ?><?php $adminEmail = 'pwithers2009@hotmail.co.uk'; ?><?php $sendmailLoc = '/usr/sbin/sendmail'; ?><?php $imgdir = 'http://www.tropicsbay.co.uk/images/'; ?><?php $imgdirbase = '/home/tropicsb/public_html/images/'; ?> header.php Code: [Select] <?php include("data/server.php"); $siteName = $_GET['siteName']; echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>$siteName Admin Panel</title> <link rel="stylesheet" href="admin.css" type="text/css" /> </head> <div id="pagehead"> <div id="navigation"> <img alt="" src="images/leftNav.gif" height="32" width="4" id="leftNav" /> <img alt="" src="images/rightNav.gif" height="32" width="4" id="rightNav" /> <div id="globalLink"> <a href="admin.php?cmd=manage&username=admin&password=$adminpw" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">Users</a><a href="admin.php?cmd=editTemplate&username=admin&password=$adminpw" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">Templates</a><a href="admin.php?cmd=mysqlBackup&username=admin&password=$adminpw" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">Database</a><a href="admin.php?cmd=paymentLog&username=admin&password=$adminpw" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">Payment</a><a href="admin.php?cmd=profileFields&username=admin&password=$adminpw" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">Setup</a><a href="admin.php?cmd=changeAdminpw&username=admin&password=$adminpw" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">Preferences</a><a href="admin.php?cmd=logout&username=admin&password=$adminpw" id="gl7" class="glink" onmouseover="ehandler(event,menuitem6);">Logout</a></div> </div></div> <div id="pagelayout"> <img alt="" src="images/leftCurve.gif" height="6" width="6" id="left" /> <img alt="" src="images/rightCurve.gif" height="6" width="6" id="right" /> <div id="pageName"> <h2>$siteName Admin Panel<h2> </div>'; ?> Any ideas on how to do this, it seems to work ok in one of my other scripts. Thanks basically if you read this, then you can see they have a "passing-var.php" and a "catching-var.php" How can i make this happen without the passing-var.php and make the catching-var.php actually GET a variable Hi, I have this script, it all works fine apart from when I pass the variable on, it only passes the first word and not the whole variable The form that actions to the samples page passes the $siteName as My Test Site, if I type echo $siteName in the sameples page, it will print My Test Site, however when I use this Code: [Select] createSample&siteName=$siteName to pass the variable to the next page, it just echos 'My' instead of My Test Site. Even when I scroll over the link above it just shows My in the url. Code: [Select] case "samples": // Get submitted data and assign to variables $siteName = $_POST['siteName']; $adminEmail = $_POST['adminEmail']; $sendmailLoc = $_POST['sendmailLoc']; $imgdir = $_POST['imgdir']; $imgdirbase = $_POST['imgdirbase']; // Write variable data to text file $FileName = "data/server.txt"; $FileHandle = fopen($FileName, 'w') or die("can't open file"); $data = "<?php\n\$siteName = '$siteName';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$adminEmail = '$adminEmail';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$sendmailLoc = '$sendmailLoc';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$imgdir = '$imgdir';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$imgdirbase = '$imgdirbase';\n?>"; fwrite($FileHandle, $data); fclose($FileHandle); // Displays the create sample pages page ECHO <<<SAMPLES <table border=0 align=center bgcolor=#00CCFF> <tr> <td><span class=style1><b><center>Create Sample Pages</center></b></span></td> </tr> <tr> <td>Would you like Member Site Maker to create sample pages for: <ul> <li>index.html</li> <li>login.html</li> <li>search.html</li> <li>register.html</li> </ul> </td> </tr> <tr> <td><a href=installation.php?cmd=createSample&siteName=$siteName>Yes</a> </td> <td><a href=installation.php?cmd=mysql>No</a> </td> </tr> </table> SAMPLES; break; Can anybody tell me where I am going wrong please? Thanks i've been programming in PHP for years, and have done a substantial amount of work on applications of this nature. this problem has me stumped, not because i can't fix it (i did), but because i have no idea what the problem is. there are hundreds of lines of code involved here, so i'll break it down into a post-friendly format. take this for example, and forgive any typos. it's late, and i've been beating my head against this for over two hours... =\ this is from my form: Code: [Select] /* ... numerous form fields being passed as $_REQUEST arrays */ <input type="hidden" name="option_id[]" value="<?php print $query_result->option_id; ?>" /> /* a couple hundred more lines */ here's the DB update handler: Code: [Select] if (!empty($_REQUEST['option_name'])) { foreach ($_REQUEST['option_name'] as $k => $v) { if ($v != '') { $option_id = $_REQUEST['option_id'][$k]; $option_name = $_REQUEST['option_name'][$k]; $option_price = $_REQUEST['option_price'][$k]; $option_desc = htmlentities($_REQUEST['option_desc'][$k], ENT_QUOTES); if (!$option_id = '') { $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $option_id "'"; if (!$query_function($sql_options)) { $error = true; } } else { $sql_options = "INSERT INTO table (option_name, option_price, option_desc)" . " VALUES ('" . $option_name . "', '" . $option_price . "', '" . $option_desc . "')"; if (!$query_function($sql_options)) { $error = true; } } } } } the above code doesn't post to the database because the $option_id variable returns a null value. however, if i replace the $option_id variable where i build the query string with $_REQUEST['option_id'], it works just fine. Code: [Select] /* in relevant part */ $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $_REQUEST['option_id'] . "'"; needless to say i was infuriated by having spent a couple of hours to come to this conclusion. i only used the variables in the first place because i need to expand the function that this lives inside and i don't want to have to type $_REQUESTs over and over. the only thing i can think is that it might be a type issue. the data is coming out of the mysql table from an INT field and being placed into the value for the hidden field straight from the row collection. would forcing a variant data type by not strongly typing my variable have caused this problem? i haven't tested the theory because i'm still too ticked off to open my code editor. i'm bouncing this off the community and posting my experience in the hope that it might help someone who comes after. |