PHP - Trouble With Variables In If/else
Hello everyone, I am having major issues trying to figure this one out. So here is the code....
$useranswer= ( $_POST["Text1"]); $query = "SELECT Answer FROM images_guess WHERE id=16"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Answer :{$row["Answer"]} <br>"; echo "User Answer:$useranswer <br>"; } $result2 = $result. " "; $useranswer2 = $useranswer . " "; if ($result2==$useranswer2) echo "right"; else echo "wrong"; ?> Basically, I am taking whatever was put into "Text1" and finding out if it matches what was in the Answer row in my table. The two variables I used, $result and $useranswer are both working because they do print out on the next page. The problem is the If/else statement is not working with them. They are both text if that helps. Any advice would help a ton, i'm at a loss. Thanks! Similar TutorialsAny idea why this wont work? Think it has something to with how i'm passing the variables? $latinsk =$row['latinsk']; $ID =$row['id']; //-display the result of the array echo "<ul>\n"; echo "<li>" . "<p style='font-family:verdana;font-size:150%;'><a href='javascript:void()' onclick='window.location.href='search.php?id= '" . $ID . "'&latinsk= '" . $latinsk . "''; parent.scrollTo(0,0); return false'> " .$latinsk . " </a></li>\n</p>"; echo "</ul>"; I've got the following code: echo <<<myStringEcho <script src="$myPluginPath/jquery.dummy.js"></script> myStringEcho; The problem is that $myPluginPath already has a / character at the end, so I don't need to put it in above But, I can't just remove it, otherwise I'll get $myPluginPathjquery.dummy.js How can I insert and have no spaces? Thanks OM I am trying to insert values stored within two dimensional array into mysql database but it does not work as I would expect it. The locations in mysql are defined as char length of 2. When I print_r the array it shows: Array( [0] => Array ( [0] => 04 [1] => 22 [2] => 27 [3] => 28 [4] => 39 [5] => 43 [6] => 47 )) but when I insert them into the mysql like this: Number1A='$MaxMillionsNumber[0][0]', Number1B='$MaxMillionsNumber[0][1]', Number1C='$MaxMillionsNumber[0][2]', Number1D='$MaxMillionsNumber[0][3]', Number1E='$MaxMillionsNumber[0][4]', Number1F='$MaxMillionsNumber[0][5]', Number1G='$MaxMillionsNumber[0][6]'; my values in mysql all show as Ar What am I doing wrong? does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; Hi. I have some code which needs to return a single variable from the function and stored as a variable within this page, so it can be echoed later on in the page. I couldn't get it to return as a variable, so i used "return compact();" to return the variable and "extract (myFunction());" to extract it to variables. However, when I turned on php's display errors and error reporting function, I got an error message saying "Warning: extract() [function.extract]: First argument should be an array in /my/web/site/index.php on line 6" (which is where my extract function is). This works fine with passing more than one variables through, is there another way pass one variable from a function to be stored as a variable on the page which called the function? Here is the function: Code: [Select] <?php //This is a list of numeric error codes against their text. this will return the error code as the variable $issue function checkLoginIssue() { //If there is an error code if (isset($_GET["issue"])) { //cycle through the list until the code is reached, return the text and break the switch switch ($_GET["issue"]) { case "1": $issue = '<p class="warning">Please log in to view this page</p>'; break; case "2": $issue = '<p class="warning">Wrong Username or Password</p>'; break; case "3": $issue = '<p class="warning">No user found with those details</p>'; break; } //return the variable in an array with a single value return compact('issue'); } } ?> And here is the code which calls the function: Code: [Select] <?php extract(checkLoginIssue()); ?> Hello everyone, I am new to this forum and PHP world. Doing my first project, a pretty complicated one to start with. I will be needing your help a lot to accomplish it. Here is the first one. 1. I have a certain field called 'country' 2. I have small flag icons for every country. WHAT DO I WANT TO DO? Example - If the country is U.S.A., the U.S. flag shows up and is a link to www.domain.com/usa If the country is Germany, the German flags shows up and is a link to www.domain.com/germany If the country is not set, no flag shows up. END. How do I execute this? This is what I am doing to get the image <img src="images/flags/<?php echo $row_rsPilots['country']; ?>.gif" alt="" name="Flag" width="20" height="20" id="Flag" /> How do make it a link to www.domain.com/'country' Thanks in advance Hi Chaps, I have a PHP FTP App, where users can log in using a unique code and a password. Their unique code corresponds to an FTP folder, e.g. Quote \FTP_Root\Customer A & Co\ So when the user logs in, they can see their FTP directory and contents, in this case an Inbox and an Outbox. This works as the FTP folder contains both an Inbox and an Outbox. The problem I am having is when I try browsing within this directory (say the Inbox), ftp-chdir fails. I have a hyperlink that sends a 'dir' parameter to the same ftp.php page, and if set, will attempt to change to the given directory. So even though the URL Hyperlink reads: Quote ....server.co.uk/ftp.php?dir=/FTP_Root/Customer A & Co/Inbox When you click on this link, the page tries to load: Quote ....server.co.uk/ftp.php?dir=/FTP_Root/Customer A So my question is what do I need to change, the Hyperlink to read something like: Quote ....server.co.uk/ftp.php?dir=/FTP_Root/Customer%20A%20&%20Co/Inbox Do something to the ftp-chdir function, where I encode/decode/whatever to make sure it tries to change to the correct FTP directory? Or exclude all ampersand entirely? Building a website for work. I am struggling with the login for some reason. I`m using a lot of the same code as I did for my personal site and a few other websites I`ve programmed which has always worked. But for some reason, it isn`t working now. I`ve already told it to display to me the information that`s being processed and that is all correct (it even updates the database like it`s supposed to). It just won`t show the person being logged in, which defeats the purpose of logging in, yanno? Here are all the files in question. login.php <?php include "file_calls.php"; $title = "Business Name (Beta): Log In"; include "functions.php"; session_start(); echo "$title"; echo "<p>"; echo "Log into the Business Name website. Only authorized members of the Business Name Staff can log into the website."; echo "<p>"; include "login_form.php"; ?> login_form.php <?php echo "<form action='logging.php' method='post'>"; echo "E-Mail Address:"; echo "<br><input type='text' name='email' size=60 maxlength=100>"; echo "<p>"; echo "Password:"; echo "<br><input type='password' name='pass' size=60 maxlength=25>"; echo "<p>"; $buttonlabel = "Log In"; include "formbutton_format.php"; echo "</form>"; ?> logging.php <?php include "file_calls.php"; $title = "Business Name (Beta): Logging In"; include "functions.php"; session_start(); echo "$title"; echo "<p>"; echo "Logging into the Business Name website. Only authorized members of the Business Name Staff can log into the website."; echo "<p>"; $email = $_POST['email']; $pass = $_POST['pass']; $entry_date = strftime("%B\ %e\,\ %Y %I:%M:%S %p", time()); $res = mysql_query("SELECT id, memlev, pwd1, pwd2, email, name FROM user_data WHERE email='$email'"); $by = mysql_fetch_row($res); mysql_free_result($res); $log = $by[4]; $pas = $by[2]; $pas2 = $by[3]; if ($email && $pass) { if ($by[0]) { if ($by[1] == 2) { $passwd = crypt($_REQUEST['pass'],$by[5]); if ($pass == $pas2) { mysql_query("UPDATE user_data SET lastlogin='$entry_date' WHERE email='$email'"); mysql_close($con); header("Location: index.php"); } elseif ($passwd != $pas) { header("Location: nolog.php?logout=1&m=4"); } } elseif ($by[1] == 1) { header("Location: nolog.php?logout=1&m=2"); } elseif ($by[1] == 0) { header("Location: nolog.php?logout=1&m=3"); } } elseif (!$by[0]) { header("Location: nolog.php?logout=1&m=1"); } } elseif (!$email || !$pass) { echo "<b>Error:</b> Both username and password must be entered in order to log in."; echo "<p>"; include "login_form.php"; } ?>[/php index.php [php]<?php include "file_calls.php"; $title = "Business Name (Beta)"; include "functions.php"; session_start(); echo "$title"; echo "<p>"; echo "This website is currently under construction. Thank you for your patience."; echo "<p>"; if ($lev > 1) { echo "Hello, $loggeduser !"; } elseif ($lev < 2) { echo "Not logged in."; } echo "<p>"; echo "$lev"; echo "<br>$loggeduser<br>$email"; ?> auth.php <?php // Defines DEFINE('SESSION_MAGIC','sadhjasklsad2342'); // Initialization @session_start(); @ob_start(); /* Redirects to another page */ function Redirect($to) { @session_write_close(); @ob_end_clean(); @header("Location: $to"); } /* Deletes existing session */ function RemoveSession() { $_SESSION = array(); if (isset($_COOKIE[session_name()])) { @setcookie(session_name(), '', time()+(60*60*24*365), '/'); } } /* Checks if user is logged in */ function isLoggedIn() { return(isset($_SESSION['magic']) && ($_SESSION['magic']==SESSION_MAGIC)); } /* read message count */ function CountMessages($id) { if ($res=mysql_query("SELECT * FROM user_data WHERE email='$email'")) { $count=mysql_num_rows($res); mysql_free_result($res); return($count); } return 0; } /* Go login go! */ function Login($email,$pass) { global $nmsg, $rows; $ok=false; if ($res=mysql_query("SELECT id, email, name, pwd1, pwd2, memlev FROM user_data WHERE email='$email' AND pwd2='$pass'")) { if ($rows=mysql_fetch_row($res)) { $_SESSION['sess_name'] = $rows[2]; $_SESSION['pass'] = $pass; $_SESSION['gal'] = $rows[0]; $_SESSION['level2'] = $rows[5]; $_SESSION['email'] = $rows[1]; $_SESSION['magic'] = SESSION_MAGIC; $nmsg = CountMessages($rows[0]); $ok=true; } else { include('login_failed.php'); } mysql_free_result($res); } return($ok); } /* Terminates an existing session */ function Logout() { @RemoveSession(); @session_destroy(); } /* Escape array using mysql */ function Escape(&$arr) { if (Count($arr)>0) { foreach($arr as $k => $v) { if (is_array($v)) { Escape($arr[$k]); } else { if (function_exists('get_magic_quotes')) { if(!get_magic_quotes_gpc()) { $arr[$k] = stripslashes($v); } } $arr[$k] = mysql_real_escape_string($v); } } } } // ----------------------------------------------- // Main // ----------------------------------------------- Escape($_POST); Escape($_GET); Escape($_COOKIE); Escape($_REQUEST); Escape($_GLOBALS); Escape($_SERVER); ?> file_calls.php <?php include "info_con.php"; include "auth.php"; ?> functions.php <?php echo "<title>$title</title>"; $lev=isset($_SESSION['level2'])?$_SESSION['level2']:0; $logged=isset($_SESSION['gal'])?$_SESSION['gal']:0; $loggeduser=$_SESSION['sess_name']; $nmsg = 0; $rows = isset($_SESSION['rows'])?$_SESSION['rows']:array(); $email = isset($_SESSION['email'])?$_SESSION['email']:''; $pass = isset($_SESSION['pass'])?$_SESSION['pass']:''; function rand_chars($c, $l, $u = FALSE) { if (!$u) for ($s = '', $i = 0, $z = strlen($c)-1; $i < $l; $x = rand(0,$z), $s .= $c{$x}, $i++); else for ($i = 0, $z = strlen($c)-1, $s = $c{rand(0,$z)}, $i = 1; $i != $l; $x = rand(0,$z), $s .= $c{$x}, $s = ($s{$i} == $s{$i-1} ? substr($s,0,-1) : $s), $i=strlen($s)); return $s; } function ShowLoggedInBar() { global $email,$pass,$rows,$logid; $nmes=""; if($nmsg){ $nmes="($nmsg New)"; } echo "Hello, $loggeduser !"; } /* check if we are logging out */ if (isset($_REQUEST['logout'])) { Logout(); } /* check if already logged in */ if (isset($_SESSION['magic']) && ($_SESSION['magic']==SESSION_MAGIC)) { ShowLoggedInBar(); } else { /* not logged in, is it a form post? */ if (isset($_REQUEST['email']) && isset($_REQUEST['pass'])) { $email = $_REQUEST['email']; $pass = crypt($_REQUEST['pass'],$email); Login($email,$pass); } else { } } ?> Can anyone see why it works on everything but getting the person logged in? I am using PHP Version 5.3.1 and MYSQL 5.1.41 and I have my select statement here however i was not sure with the php that im using to filter the results if I should have or could have posted it here or in the PHP section, as part of my question pertains to it as well...if i am posting in the wrong place please let me know and i will move it. ok this is killin me its not working and when it works it works backwards...whats happening is when I use $DArea anywhere in the Query it doesnt work, If I choose a different Area than one in the database It executes the Else Statement(not supposed to do that) and it post data from the same Month, Year and Area to the database...once again what im trying to do is not allow any information from an Area "$DArea" in the database unless the Month or the Year is different. In other words If I fill out information from area "Gym" on November("DMonth") of 2010("DYear") the next time i will be allowed to enter data on it is next month. And if you were wondering Dmonth and DYear are variables tied to the time() function abd it does pass the correct month and time to the database. $DArea = $areaReported; $query = mysql_query("SELECT * FROM $table_name WHERE Month ='$DMonth' AND Year= '$DYear' AND Area = '$DArea'") or die(mysql_error()); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbMonth = $row['Month']; $dbYear = $row['Year']; $dbArea = $row['Area']; } if ($DMonth==$dbMonth&&$DYear==$dbYear&&$DArea==$dbArea) { mysql_query("INSERT INTO $table_name (user_id, Date, Month, Year, Area, percent1, stat1) values ('{$user_id}', '{$realdate}', '{$DMonth}', '{$DYear}', '{$DArea}', '{$percent1}', '{$stat1}')"); // defining the output include("output.inc"); if ($total == "1"){ $output = $output1; } else if ($total == "2"){ $output = $output2; } else if ($total == "3"){ $output = $output3; } else if ($total == "4"){ $output = $output4; } else if ($total == "5"){ $output = $output5; } else if ($total == "6"){ $output = $output6; } else if ($total == "7"){ $output = $output7; } else if ($total == "8"){ $output = $output8; } else if ($total == "9"){ $output = $output9; } else if ($total == "10"){ $output = $output10; } } else echo "<p style=\"color:red;\">A Report for this $areaReported has already been submitted for this Month</p>"; } I have also tried the statement this way. ("SELECT 'Month', 'Year', 'Area' FROM 'data' WHERE 'Month' ='$DMonth' AND 'Year'='$DYear' AND 'Area' = '$DArea'") If it stops any info from hitting the database it stops it all and when the error message I want to appear when someone tries to enter a duplicate record from a specific area for the same month, it does not show unless its a month that does not exist in the database and to get that to even show up I have to take the Area Clause out of the Select statement. I am out of ideas on this one. Can anyone tell me if im even going in the right direction here? Please help I'm new to php and having some trouble with debugging a piece of code. Could someone please help me understand what's the error. I'm using Code Lobster for debugging and attempting to validate input for a simple sign in form. The error is and code is shown below. If I can understand this, I think I can continue with the rest of the checking. Parse error: syntax error, unexpected T_FOREACH, expecting ')' in C:\wamp\www\login_check_blank.php on line 20 <php // Program name - login_check_Blank.php // Description - checks form for blank fields // Date - 10/26/10 // Programer - R. Langevin ?> <html> <head> <title>Checking for empty fields</title> </head> <body> <?php // set up array for all fields $labels = array( "userName" => "username", "passWord" => "password", // Check each field for blanks foreach ($_POST as $field => $value) { } if ($value =="") { $blank_array[] = $field; } // end of foreach loop for $_post // if any fields were blank, display error message and redisplay form if (@sizeof ($blank_array) >0 { echo "<strong>One or more requied fields were found to be blank</strong>" // display list of blank fields foreach($blank_array as $value) { echo " $nbsp; {$labels[$value] } <br>"; } } echo "$userName "welcome back to the Taft Union High School class of 65 website." exit() ?> </body> </html> Hi: I'm having trouble getting my data to display using SELECT. Maybe someone can point out what I'm missing. I want to display the City and Zip for all 50 states, depending on which abbr_state name is clicked. This my code: Code: [Select] <a href="z.php?abbr_state=NY">New York</a> <br /> <a href="z.php?abbr_state=PA">Pennsylvania</a> <?php include('include/myConn.php'); $result = mysql_query("SELECT city,abbr_state,zip FROM `zip_codes` WHERE `abbr_state` = " . mysql_real_escape_string ( $_GET['abbr_state'] );") while($row = mysql_fetch_array($result)){ echo $row['city']. " - ". $row['zip']; echo "<br />"; } ?> Getting this error: Code: [Select] Parse error: syntax error, unexpected ';' in /var/www/domains/sppcon.com/docs/z.php on line 29 What am I missing? The only ';' I see is at the end but removing it doesn't fix the error. Also - now that I think of it - how would I list the Cities in alphabetical order, and perhaps do pagination to I only show a certain amount each page? There are a lot of cities and I think displaying them all on one page would be a bit much. Thanks! Hello people I'm having some trouble, and I kind think I know what it is, but for some reason I just can't figure it out. I think I need an isset function, but I'm not sure where to put it? Here is my code followed by my errors. <?php echo"<?xml version=\1.0\"encoding=\UFT-8\"\x3f>"; echo"\n"; ?> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"lang="en"> <head> <title>My Second PHP Generated Document</title> </head> <body> <?php if (isset($_POST['submit'])) { if ($_POST['submit'] == "Clear") { $workValue = ""; $workType = ""; } elseif ($_POST['submit'] == "Calculate") { $workValue = $_POST['vfld']; $workType = $_POST['tfld']; $calcValue = (float) $workValue; if (empty($_POST['vfld'])) { echo "<h3>Error</h3>"; echo "<p>You must enter a value!</p>\n"; } elseif ($calcValue == 0) { echo "<h3>Error</h3>"; echo "<p>You must enter a number!</p>\n"; } elseif ($calcValue < 0) { echo "<h3>Error</h3>"; echo "<p>You must enter a positive number!</p>\n"; } elseif (empty($_POST['tfld'])) { echo "<h3>Error</h3>"; echo "<p>You must select a calculation type!</p>\n"; }} else { switch ($workType) { case "circle": $areaValue = $calcValue * $calcValue * pi(); break; case "square": $areaValue = $calcValue * $calcValue; // echo "The area of a square whose sides are" break; case "triangle": $halfSide = $calcValue/2; $otherSide = sqrt(($calcValue * calcValue) - ($halfSide * halfSide)); $areaValue = $otherSide * $halfSide; echo "The area of an equilateral triangle whose sides are $calcValue} is {areaValue}."; break; }} } ?> <form method="post" action="hw04.php" id="form1" name="form1"> <p> Enter a number here : <input type="text" id="vfld" name="vfld" value="<?php echo $workValue; ?>"/> </p> <p> This number is a: <br /> <input type="radio" name="tfld" value="circle" <?php if ($workType == "circle") { echo 'checked="checked"'; } ?> /> : the radius of a circle <br /> <input type="radio" name="tfld" value="square" <?php if ($workType == "square") { echo 'checked="checked"'; } ?> /> : the length of one side of a square <br /> <input type="radio" name="tfld" value="triangle" <?php if ($workType == "triangle") { echo 'checked="checked"'; } ?> /> : the length of one side of an equilateral triangle </p> <p> <input type="submit" name="submit" value="Calculate" /> <input type="submit" name="submit" value="Clear" /> </p> </form> <div id="footer"> <pre>This page written by: <cite>James Cozzy</cite> ©2011 and beyond</pre> </div> </body> </html> And my errors Enter a number here : This number is a: Notice: Undefined variable: workType in /studfs1/j-cozzy/homepage/CISS-225/hw04.php on line 69 /> : the radius of a circle Notice: Undefined variable: workType in /studfs1/j-cozzy/homepage/CISS-225/hw04.php on line 74 /> : the length of one side of a square Notice: Undefined variable: workType in /studfs1/j-cozzy/homepage/CISS-225/hw04.php on line 79 /> : the length of one side of an equilateral triangle any help would be much appreciated? Hey, I am trying to make and then read an array of items. Can someone help please? I have a database field that holds an unlimited number of codes, and I need to get those codes.... at the moment I have a section of php $products= array($products); $array = array_values($products); print_r($array); which generates Array ( => FRE0001,FRE0009,FRE0009,FRE0024,FRE0024 ) as the output... What I need is to know how many of each code there are and the different codes.... i.e. 1 x FRE0001, 2 x FRE0009, 2 x FRE0024 Whats the best way to output the array and then count? Hi all I'm working on a form, i've gotten all the values from the form to the process.php page and it is assigning the correct variables but i can't get it to insert into the database, i know the connection info is correct as i have other page connecting and i can create a recordset on that page. i guess my sql is wrong any help much appreciated. the following is the sql from the database and attached is the process.php page. -- Table structure for table `details` -- CREATE TABLE `details` ( `id` int(6) NOT NULL auto_increment, `first_name` varchar(20) NOT NULL, `sur_name` varchar(20) NOT NULL, `sex` varchar(6) NOT NULL, `age` varchar(3) NOT NULL, `house_no` varchar(5) NOT NULL, `street` varchar(150) NOT NULL, `town` varchar(50) NOT NULL, `bro_sis_cous_friend1` varchar(50) default NULL, `bscf_name1` varchar(150) default NULL, `and` varchar(4) NOT NULL, `bro_sis_cous_friend2` varchar(50) default NULL, `bscf_name2` varchar(150) default NULL, `his_her` varchar(4) default NULL, `him_her` varchar(4) default NULL, `from_name` varchar(150) NOT NULL, `photo_link` varchar(255) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ; [attachment deleted by admin] I have a form that I want the data to e-mail in a message. Everything works except for the checkbox arrays. "Array" displays when I want all values of checked boxes to display. Here is the code, I have bolded where checkbox data should be coming over. I'm not a pro so any help is greatly appreciated. Code: [Select] $message = "<html><body>\r\n"; $message .= "<table width='500' border='0' cellpadding='2'>\r\n"; $message .= " <tr>\r\n"; $message .= " <td width='150'>School</td>\r\n"; $message .= " <td width='350'>" . $_POST['school'] . " </td>\r\n"; $message .= " </tr>\r\n"; $message .= " <tr>\r\n"; $message .= " <td width='150'>Teacher</td>\r\n"; $message .= " <td width='350'>" . $_POST['teacher'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <tr>\r\n"; $message .= " <td width='150'>Subject</td>\r\n"; $message .= " <td width='150'>" . $_POST['subject'] . "</td>\r\n"; $message .= " <td width='150'>Period</td>\r\n"; $message .= " <<td width='50'>" . $_POST['period'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Date</td>\r\n"; $message .= " <td width='50'>" . $_POST['month'] . "</td>\r\n"; $message .= " <td width='15'>" . $_POST['day'] . "</td>\r\n"; $message .= " <td width='15'>" . $_POST['year'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Time In:</td>\r\n"; $message .= " <td width='100'>" . $_POST['timeIn'] . "</td>\r\n"; $message .= " <td width='150'>Time Out:</td>\r\n"; $message .= " <td width='100'>" . $_POST['timeOut'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Teacher Location Upon Entrance</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q6_1Teacher6'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q7_comments7'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Student Engagement</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q11_2Student'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Students Engaged/Total Students</td>\r\n"; $message .= " <td width='350'>" . $_POST['q12_studentsEngagedtotal'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q15_comments15'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Teaching Alignment</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q17_3Teaching17'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q18_comments18'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Identified Learning</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q13_4Identified'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q16_comments16'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Rigor Rate</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q20_5Rigor'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q21_comments21'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Assessment Practice</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q22_6Assessment'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q27_comments27'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Instructional Practice</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q24_studentDirected'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q23_comments23'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= " <td width='150'>Learning Environment</td>\r\n"; [b]$message .= " <td width='350'>" . $_POST['q28_8Learning'] . "</td>\r\n";[/b] $message .= " </tr>\r\n"; $message .= " <td width='150'>Comments</td>\r\n"; $message .= " <td width='350'>" . $_POST['q29_comments29'] . "</td>\r\n"; $message .= " </tr>\r\n"; $message .= "</table>\r\n"; $message .= "</body></html>"; Hi guys, Sorry - this might more belong in the SQL section but I think it is PHP related. I am trying to update a table with: $sql="UPDATE $tbl_name SET (gender, description) VALUES ('$gender', '$description') WHERE image = ('$photoname')"; $result=mysql_query($sql); Needless to say, its not working. Only odd thing is that the $photoname variable is sent with a hidden field on the previous form. I can echo all 3 varaibles though and get the right results. I just dont know why it isnt updating - seems pretty standard to me. Can anyone help? Thanks! Hi Chaps, I've created a web-based FTP site, but having trouble with PHP's FTP_PUT function. I've tried: // FTP access parameters $host = 'ftp.example.org'; $usr = 'example_user'; $pwd = 'example_password'; // file to move: $local_file = './example.zip'; $ftp_path = '/data/example.zip'; // connect to FTP server (port 21) $conn_id = ftp_connect($host, 21) or die ("Cannot connect to host"); // send access parameters ftp_login($conn_id, $usr, $pwd) or die("Cannot login"); // turn on passive mode transfers (some servers need this) // ftp_pasv ($conn_id, true); // perform file upload $upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_BINARY); // check upload status: print (!$upload) ? 'Cannot upload' : 'Upload complete'; print "\n"; // close the FTP stream ftp_close($conn_id); And also Net_FTP's FTP_PUT function: require_once 'Net/FTP.php'; $test = new Net_FTP('www.domain.co.uk', 21); $test->connect('www.domain.co.uk', 21); $test->login('username', 'password'); $file_tmp = $_FILES["file"]["tmp_name"]; $file_name = $_FILES["file"]["name"]; $test->put($file_tmp, 'Uploads/'.$file_name, FTP_BINARY); I've tested this with a very small text file and it works OK, but when I try with a zip file of around 9Mb it takes FOREVER, and sometimes doesn't upload at all, or if it does, it has a size of 0kb. I need the script to handle big files up to 150Mb in size. What can I do to speed up the process and is there something I have missed (current config settings > ini_set('max_upload_filesize', 150000000)) ? Hi, My mother-in-law asked me to check on her laptop (win8) and I tried but was unable to find a solution. The problem is that the hard-drive is at a constant 100% which makes the laptop really slow except in safe mode. Process list shows no process using 100% of the hdd, I already did a chkdsk and it returned no errors. I suspect it's due to the task scheduler and stopping the active tasks indeed lowers the hdd usage to 6-11% but it does not remain there probably because new tasks are started. I also removed several software which I suspected were the ones creating the tasks to no avail. It appears as if Windows itself is running tasks that slow down the laptop to a crawl, but disabling task scheduler does not seem a good idea. Any ideas? Don't have a huge deal of experience with this side of things, well php as a whole really but really struggle with this side, ive coded up a cron but it only works for 1 user, unsure as to why, i want it to do the action for every player that has item 17, the codes below any help would be appreciated, Thanks guys Code: [Select] <?php include("server.php"); $sql = "SELECT * FROM player_inventory WHERE item_id = 17"; $que = mysql_query($sql) or die(mysql_error()); $res = mysql_fetch_array($que); $sql2 = "SELECT * FROM players WHERE id = $res[player_id]"; $que2 = mysql_query($sql2); while($res2=mysql_fetch_array($que2)) { $Weight = 8 / 100 * (100 + $res2['ProductionWeight']); $Quality = 75 / 100 * (100 + $res2['ProductionWeight']); $StreetCred = $Weight * $Quality / 10; $update = "UPDATE players SET StreetCred = StreetCred + $StreetCred WHERE id = $res[player_id]"; mysql_query($update) or die(mysql_error());; $update2 = "INSERT INTO drug_inventory (player_id,quality,weight) VALUES('$res[player_id]',$Quality,$Weight)"; mysql_query($update2) or die(mysql_error());; echo "Grow Completed."; } ?> I'm trying to figure out why my entire if statement is not working properly. What is happening when I run my form is that it puts it into the first if statement regardless of what the value of $style is and I don't know why. The other parts of the for submission works BUT my if statement. And inside of firebug it is passing the RIGHT post data so it has the correct value for style each time. <?php // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submitcharacter'])) { $charactername = mysqli_real_escape_string($dbc, $_POST['charactername']); $charactershortname = mysqli_real_escape_string($dbc, $_POST['charactershortname']); $sortorder = mysqli_real_escape_string($dbc, $_POST['sortorder']); $style = mysqli_real_escape_string($dbc, $_POST['style']); $status = mysqli_real_escape_string($dbc, $_POST['status']); $alignment = mysqli_real_escape_string($dbc, $_POST['alignment']); $division = mysqli_real_escape_string($dbc, $_POST['division']); $query = "INSERT INTO `characters` (charactername, charactershortname, status_id, style_id, division_id, alignment_id, sortorder, creator_id, datecreated) VALUES ('$charactername','$charactershortname','$status','$style','$division', '$alignment', '$sortorder', 1, NOW())"; mysqli_query($dbc, $query); $query_id = mysqli_insert_id($dbc); $query1 = "INSERT INTO `allies` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query1); $query2 = "INSERT INTO `rivals` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query2); if ($style = 1) { $query3 = "INSERT INTO `singles` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query3); } elseif ($style = 2) { $query4 = "INSERT INTO `tagteams` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query4); } elseif ($style = 3) { $query5 = "INSERT INTO `managers` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query5); } } elseif ($style = 4) { $query6 = "INSERT INTO `stables` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query6); } elseif ($style = 5) { $query7 = "INSERT INTO `referees` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query7); } else { $query8 = "INSERT INTO `staff` (character_id) VALUES (".$query_id.")"; mysqli_query($dbc, $query8); } ?> |