PHP - Problem With Load - Null Value
hi
i have this code: Code: [Select] <script type="text/javascript"> $(document).ready(function() { function doAjax(url) { $("#customForm").submit(function() { var formdata = $("#customForm").serializeArray(); $.ajax({ url: url, type: "post", dataType: "json", data: formdata, success: function(data, data1) { switch (data.livre) { case 'tituloLivre': $("#msgbox2").fadeTo(200, 0.1, function() { $(this).html('Titulo Livre').fadeTo(900, 1); }); break; default: $("#msgbox2").fadeTo(200, 0.1, function() { $(this).html('Active a sua conta e pode efectuar o login!').fadeTo(900, 1, function() { $('#conteudo').load('dojo/test_Slider.php'); }); }); break; } } }); return false; }); } doAjax('sent.php'); doAjax('dojo/test_Slider.php'); }); </script> and test_Slider.php Code: [Select] <?php include ('includesMy.php'); $form = $_POST['item']; $oferta = $form['oferta']; var_dump($oferta); echo json_encode ($oferta); ?> i should load the php file with ajax influence, but when i made load (test_Slider.php) obviously i get null because is independent of ajax call. My question is, how can i load a whole php file that is changed by ajax call ? (json return is not the solution because i have much more content, like graphics elements in test_Slider.php) Similar TutorialsHi... i have table EMP_NO LOGIN - DATETIME, NULL LOGOUT - DATETIME, NULL I have this query: Code: [Select] <?php include 'config.php'; $currentEmpID = $_SESSION['empID']; if(!isset($_POST['submit_'])){ $DATE1 = $_POST['firstinput']; $DATE2 = $_POST['secondinput']; $sql = "SELECT EMP_NO, LOGIN, LOGOUT FROM employee_attendance WHERE DATE(LOGIN) BETWEEN '$DATE1' AND '$DATE2'"; $attendance = $conn3->GetAll($sql); $smarty->assign('attendance', $attendance); } $smarty->display('header_att.tpl'); $smarty->display('empAttendance.tpl'); $smarty->display('footer.tpl'); ?> My problem is I have data EMP_NO 00000223 LOGIN NULL LGOUT NULL this data was not displayed because it has a null value.. i want it to displayed also and highlight it because it has a value null.. Thank you I am trying to update the database with isset to set the value of the variable to either null or the value entered by the user. Currently, if no value has been entered null is being set as a string causing the date field to populate with zeros. How do I code it so that it populates or sets the value as null and not as string null?
Here's my code: (yes I know sql injections it's still in development )
<?php hi everyone i've just finnished a lynda.com course and began coding my own site.. i want to be able to put the script it self in the database. Then from read and execute the script from content.php BUT i get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\content.php(35) : eval()'d code on line 1 Call Stack so far it's has been fairly easy to correct the errors, but this one i don't know how to handle.. can anyone give me a hint where I've mistaken The script i put in the database if (!isset($_GET['category'])) { $query = "SELECT * FROM links ORDER BY category ASC"; $result = mysql_query($query); echo "<table border=\"0\" width=\"100%\"> <tr> <td> <ul>"; while ($row = mysql_fetch_assoc($result)) { echo "<li><a href=\"links.php?content=links&category=" . $row['category'] . "\">" . $row['category'] . "</a></li>"; } echo "</ul> </td> </tr> </table>"; } if (isset($_GET['category'])) { $linkcat = $_GET['category']; $query = "SELECT * FROM links WHERE category='{$linkcat}' ORDER BY title ASC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<table border=\"0\" width=\"100%\" height=\"160\"> <tr> <td colspan=\"3\" align=\"center\" valign=\"top\"> <h1><a href=\"" . $row['address'] . "\">" . $row['title'] . "</a></h1> </td> </tr> <tr> <td colspan=\"3\" align=\"center\" valign=\"middle\"> <p>" . $row['description'] . "</p> </td> </tr> <tr> <td align=\"left\" valign=\"bottom\" style=\"float:right\"><a href=\"profile.php?username=" . $row['author'] . "\">" . $row['author'] . "</a></td> <td align=\"center\" valign=\"bottom\"><p>" . $row['votes'] . "</p></td> <td align=\"right\" valign=\"bottom\" style=\"margin-right:10;\"><p>" . $row['clicks'] . "</p></td> </tr> </table> <br /> <hr /> <br />"; } } content.php <?php require_once('includes/connection.php'); ?> <?php $content = $_GET['content']; $query = "SELECT * FROM pages WHERE page_name='{$content}'"; $result = mysql_query($query); if (!$result) { echo "Could not successfully run query from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } $row = mysql_fetch_assoc($result); $str = $row['content']; eval("\$str = \"$str\";"); echo $str; ?> Thank you in advance Dokter G Hi. I'm using SimpleImage.php to do some basic image manipulation. The code is here http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php, but I don't think all the details are important. Basically, I'm trying to read and image and save it with a different name. I'm really new with this stuff, so it's probably something simple. Anyway, here is the code throwing the error, $image_info = getimagesize($filename); where $filename is a string containing the path to the image I want to load, e.g. $filename="images/picture.jpg"; It's throwing a "Read Error!" I know that the path is correct. In fact I first check if the file is there using is_file($filename); and it returns true. I'm guessing that maybe php does not have "permission" to read this file. The permissions for the file are -rw-r--r-- 1 www-data www-data 80211 2011-04-20 16:19 picture.jpg Looks like everyone has "read" permission, so I don't see what the problem is. Also, the permissions of the folder and all parent folders are 777. Not sure what the problem is. I might be way off by guessing that it is a permissions problem. Any help would be great. Thanks. Also, I was wondering if there is a way for this forum to email me whenever there is a reply to my posts. I can't seem to find the option anywhere. I'm having a problem and need an answer to why its happening and how to prevent it. Scenario: I begin load my home page which starts with a session_start(); .... Before it FULLY completes loading I try to navigate to another page and BOOM, that page will not load and any other page that begins with session_start(); will not load unless I close and restart the entire browser or wait about 10 minutes.... I will note my website makes ajax calls every 5 seconds or so, but I use setTimeout for them. Any help??? Thanks ahead! Hello All, I tried searching here and google, but couldn't figure it out on my own... still Bellow is my code, I need some help figuring out how to tell PHP that "If picture is NULL, don't try to display it." Basically I have a dynamic news system set up. Some stories have pictures, some do not. I need PHP to not display the code for showing the picture if the picture value = NULL. Any help would be appreciated! <?php include ("../../includes/connections/newsconnection.php"); $id=$_GET['id']; //declare the SQL statement that will query the database $query = " SELECT * FROM news WHERE id='$id' "; //execute the SQL query and return records $result = mssql_query($query); //display the results //id, school, date, link, title, story, picture while($row = mssql_fetch_array($result)) { echo "<span class='bodyb'>"; echo $row["title"]; echo "</span>"; echo "<br /><i>"; echo date('l, F j, Y', strtotime($row['date'])); echo "</i>"; echo "<br /><br />"; //heres where I need to stop if picture is null echo "<img src='../../images/news/"; echo $row["picture"]; echo "' align='left' class='imgspacer-left'>"; echo fixQuotes($row["story"]); } //close the connection mssql_close($dbhandle); ?> I'm trying to display the null values only, where am I going wrong?
SELECT IFNULL(trans, 0) AS 'Transactions', customer.cID AS 'Customer ID', customer.surname AS 'Surname' FROM customer LEFT JOIN account ON (account.cID = customer.cID) WHERE IFNULL(trans, 0); Can someone help me to get this code working... Code: [Select] public function getBowlContents(){ if is_null($this->contents) { return "The bowl is empty!"; } else { return "The bowl contains " . $this->contents . " soup!"; } TomTees hi all, i have a script in where the user enters there post code and it will provide a price for delivery, how would i echo "please contact us for price" if the db record for the price is (null) or empty?? <?php mysql_connect ("localhost", "root","password") or die (mysql_error()); mysql_select_db ("postcode"); $term = $_POST['term']; $sql = mysql_query("SELECT * FROM uk_postcodes, zones WHERE postcode LIKE '%$term%' AND zone_id = zone_large "); while ($row = mysql_fetch_array($sql)){ echo '<br/> Postcode: '.$row['postcode']; echo '<br/> Town: '.$row['town']; echo '<br/> County: '.$row['county']; echo '<br/> Small: £'.$row['price_s']; echo '<br/> Medium: £'.$row['price_m']; echo '<br/> Large: £'.$row['price_l']; echo '<br/><br/>'; } ?> I have an array which can be empty; in this case, I get error. I want to skip when the array is empty. When calling the array from file, I use the following code if (file_exists($array_file)) { "the doing code" } else { echo "File does not exist"; } How I should use this If Else condition when array comes from a string like $test_array = explode(', ', $examplestring, -1); I have a php page where user/db info is being passed: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Duration</h1>'; if (is_array($duration)) { foreach ($duration as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> And here is the output from that code: Added Activities Exercise 0 : Canoeing, on camping trip 1 : Canoeing, rowing, over 6 mph, vigorous effort 2 : Canoeing, rowing, crewing, competition 3 : Canoeing, rowing, light effort 4 : Canoeing, rowing, moderate effort 5 : Diving, springboard or platform 6 : Kayaking 7 : Sailing, boat/board, windsurfing, general 8 : Sailing, in competition 9 : Skiing, water 10 : Ski-mobiling, water 11 : Skin diving, scuba diving, general 12 : Snorkeling 13 : Surfing, body or board 14 : Swimming laps, freestyle, fast, vigorous effort 15 : Swimming laps, freestyle, light/moderate effort 16 : Swimming, backstroke, general 17 : Swimming, breaststroke, general 18 : Swimming, butterfly, general 19 : Swimming, leisurely, general 20 : Swimming, sidestroke, general 21 : Swimming, sychronized 22 : Swimming, treading water, fast/vigorous 23 : Swimming, treading water, moderate effort 24 : Water polo 25 : Water volleyball 26 : Whitewater rafting, kayaking, or canoeing Duration Canoeing, on camping trip : 20 Canoeing, rowing, over 6 mph, vigorous effort : Canoeing, rowing, crewing, competition : Canoeing, rowing, light effort : Canoeing, rowing, moderate effort : Diving, springboard or platform : Kayaking : Sailing, boat/board, windsurfing, general : Sailing, in competition : Skiing, water : Ski-mobiling, water : Skin diving, scuba diving, general : Snorkeling : Surfing, body or board : Swimming laps, freestyle, fast, vigorous effort : Swimming laps, freestyle, light/moderate effort : Swimming, backstroke, general : Swimming, breaststroke, general : Swimming, butterfly, general : Swimming, leisurely, general : Swimming, sidestroke, general : Swimming, sychronized : Swimming, treading water, fast/vigorous : Swimming, treading water, moderate effort : Water polo : Water volleyball : Whitewater rafting, kayaking, or canoeing : Distance Canoeing, on camping trip : 20 Canoeing, rowing, over 6 mph, vigorous effort : Canoeing, rowing, crewing, competition : Canoeing, rowing, light effort : Canoeing, rowing, moderate effort : Diving, springboard or platform : Kayaking : Sailing, boat/board, windsurfing, general : Sailing, in competition : Skiing, water : Ski-mobiling, water : Skin diving, scuba diving, general : Snorkeling : Surfing, body or board : Swimming laps, freestyle, fast, vigorous effort : Swimming laps, freestyle, light/moderate effort : Swimming, backstroke, general : Swimming, breaststroke, general : Swimming, butterfly, general : Swimming, leisurely, general : Swimming, sidestroke, general : Swimming, sychronized : Swimming, treading water, fast/vigorous : Swimming, treading water, moderate effort : Water polo : Water volleyball : Whitewater rafting, kayaking, or canoeing : Metric 0 : mile 1 : mile 2 : mile 3 : mile 4 : mile 5 : mile 6 : mile 7 : mile 8 : mile 9 : mile 10 : mile 11 : mile 12 : mile 13 : mile 14 : mile 15 : mile 16 : mile 17 : mile 18 : mile 19 : mile 20 : mile 21 : mile 22 : mile 23 : mile 24 : mile 25 : mile 26 : mile As you can see, null values are being passed as well. I am hoping that someone can show me the correct way to use php unset to get rid of these null values. Thank you. 2 PART QUESTION (so I don't have to ask two questions 😀 )
1.)
2.) On my particular coding, I can use either the NULL/isset style, or, the ""/== style, with no errors or ill effects.... but something tells me the expert PHP coders prefer one over the other... Thank you!! Edited July 10 by ChenXiuI'm trying to force a NULL value into the database with a hidden value and I can't seem to get it to work. Any suggestions? <input type="hidden" name="inactive" value=""/> I also tried here too: $sql="UPDATE product SET inactive='NULL' WHERE id = '$item_id'"; I have a for loop that I am looping through. When I use var_dump() I get 10 results (which is what I should be getting). However, when I loop through it using a for() loop I am getting an extra 11th value that is blank. What would be causing this? My code is below: Code: [Select] $legacy = new Legacy(); // Loop through each film in the shopping cart for ($i = 0; $i < $myShoppingCartInfo['row_count']; $i++) { // Determine if the film is of a legacy series if ($legacy->isLegacyCheckout($myShoppingCartInfo['data']['PRODUCTSKUID'][$i])) { // Declare array to hold all legacy film entity_id values $legacyEntityIds = array(); $legacyEntityIds = $legacy->getLegacyEntityIds($myShoppingCartInfo['data']['PRODUCTSKUID'][$i]); var_dump($legacyEntityIds); // Loop through all legacy video entity_id's for ($i = 0; $i < $legacyEntityIds['data']['ENTITY_ID']; $i++) { // Grant streaming access to each entity id echo $legacyEntityIds['data']['ENTITY_ID'][$i] . '<br />'; // Insert the product into the order items table /*$query = "INSERT INTO tblOrderItems (OrderItemID, ProductSKUID, RentalDate, OrderID) VALUES (##newID##, '".$myShoppingCartInfo['data']['PRODUCTSKUID'][$i]."', ".($myShoppingCartInfo['data']['RENTALDATE'][$i] === NULL ? 'NULL' : "'".$myShoppingCartInfo['data']['RENTALDATE'][$i]."'").", ".$newOrderID.")"; $cartItemInserted = counter_id_insert($query,'OrderItemID'); $curr_user->addNewEntityLicense($legacyEntityIds['data']['ENTITY_ID'][$i]);*/ } } When I view the source code of the output page in a browser, this is what I see: array(5) { ["row_count"]=> int(10) ["col_count"]=> int(1) ["col_names"]=> array(1) { => string(9) "entity_id" } ["col_types"]=> array(1) { => string(3) "int" } ["data"]=> array(1) { ["ENTITY_ID"]=> array(10) { => string(7) "1681799" [1]=> string(7) "1681872" [2]=> string(7) "1681871" [3]=> string(7) "1681870" [4]=> string(7) "1681869" [5]=> string(7) "1681868" [6]=> string(7) "1681867" [7]=> string(7) "1681866" [8]=> string(7) "1681865" [9]=> string(7) "1681864" } } } 1681799<br />1681872<br />1681871<br />1681870<br />1681869<br />1681868<br />1681867<br />1681866<br />1681865<br />1681864<br /><br /> My code; $sql = "SELECT SUM(IF(`submitdate` IS NULL , 1 , 0 )) as 'Survey Started But Not Completed' FROM `survey_$surveyid`"; $statement = $dbh->prepare($sql); $statement->execute(); $result = $statement->fetch(PDO::FETCH_OBJ); //pass that data to an objectIs returning; stdClass Object ( [Survey Started But Not Completed] => ) I need to set this to a vaule that I can actually print out on the screen... Like a "0" for example. At the moment it is just a NULL. How do I do this?? These don't work; $result = 0; $result = array(['Survey Started But Not Completed'] => "0"); How can I change Yes to No for the NULL field in the mysql db structure. E.g. (Table name: address and Column name : state) <?php $link = mysql_connect("localhost","db","pw"); mysql_select_db("db"); mysql_query("alter table address modify state null NO); $result = mysql_query($query); $sent = "Edit Successful."; echo ($sent); ?> I have two drop down boxes that give me the result $extract and $extract2. The user can not pick the same seat in each drop down box. I am having a problem getting my IF statement to work, well it is working but not as I would like. When the page loads both boxes are null and are therefore the the same and the 'else' statement is shown. Is there a way to say...IF button is NULL on the page load then ignore? //SUBMIT BUTTON echo "<br>"; echo "<br>"; echo "<input type='submit' name='select' value='Select Seats'>"; echo "</form>"; //IF TO SEE IF TWO SEATS ARE SAME if ($_POST['select']="") { echo "please choose seats"; } if ($_SESSION['extract']==$_SESSION['extract2']) { echo "You have choosen the same seat twice, please choose two different seats. <a href='confirm.php'> Go Back</a>"; } Thanks. =) Hi, I am trying to expand my very limited PHP by building a CMS. It's all new to me so please be courteous with your replies ? I little history of my problem. I am running xampp on a windows 10 running php 5.6.38
I have taken two video courses and on each I got stumped halfway through with a very similar problem. I am copying everything word for word and even downloaded the course file on the first one and still got the same problem so I'm wondering if there is something wrong with my setup - config?.
The problem.
This is the code: <?php error_reporting(E_ALL); ini_set('display_errors',1); include("includes/database.php"); include("includes/header.php"); if ($connection) {         echo "Great, we're connected to the database<br><br>";    }else {       echo "Bummer, it didn't connect to the database!";       }    $query = "SELECT * FROM categories";   $result_set = mysqli_query($connection, $query) ;   if (!$result_set) {        die("Query Failed".msqli_error($connection));            }   while ($row = mysqli_fetch_array($result_set)) {            echo $row['cat_title'];            }    var_dump($result_set);                   ?>
Great, we're connected to the database object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(2) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) }
Question: Â Thanks for your help. Greetings folks, I've tried searching on this but couldn't find anything which I think is odd since I'm sure I'm not the first person with this question... I have a project that is basically a big (really big) form. When the user hits submit they get a CSV file. My client will then import the CSV into their database. The CSV is made up of two lines, the first being field names and the second line being the field values. Both the names and values are pulled from $_POST. The CSV looks like this: "Name","Age","Favorite Color" "Bob","12","Purple" The problem I having is if the user skips a question, let's say Age for this example, the CSV will look like this: "Name","Age","Favorite Color" "Bob","Purple" The clients database then freaks when it sees the value for Age is Purple. So my question is, how does one handle null values from from $_POST to avoid such an issue? Thank you! Thank you! Thank you! Okay so I created a theme for my website that will also utilize a custom CMS script I developed and its not cooperating with me nicely. Here's my head of my header file for my template: Code: [Select] <!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" <?php language_attributes(); ?>> <head> <title><?php bloginfo('name') ?>: <?php bloginfo('description') ?></title> <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> <meta http-equiv="content-type" content='<?php bloginfo("html_type"); ?> charset=<?php bloginfo('charset'); ?>' /> <?php if(is_singular()){ wp_enqueue_script('comment-reply');} ?> <?php wp_head(); ?> <?php require ('efedmanager/inc/dbconfig.php'); ?> </head> Now on my index page that calls the header file I DO NOT get a error saying that the file could not be located. So that's good news. Here's my dbconfig.php file. Code: [Select] <?php /** * @author Jeff Davidson * @copyright 2010 */ // This file contains the database access information and establishes a connection to MySQL and selects the database // Set the database access information as contstants DEFINE ('DB_USER', '?'); DEFINE ('DB_PASSWORD', '?'); DEFINE ('DB_HOST', '?'); DEFINE ('DB_NAME', '?'); // Make the database connection $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (!$dbc) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } ?> Now when I go to one of my custom pages like this one it brings up the message: Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/xtremer/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 38 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/xtremer/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 39 Code: [Select] <div id="champions" class="content"> <h1 class="pageheading">KOW Champions and Contenders</h1> <?php $championsQuery = " SELECT titles.titleName, titles.shortName, champions.champID, champions.con1ID, champions.con2ID, champions.con3ID, biochamp.shortName AS championshortName, biochamp.characterName AS champion, biocon1.shortName AS con1shortName, biocon1.characterName AS con1, biocon2.shortName AS con2shortName, biocon2.characterName AS con2, biocon3.shortName AS con3shortName, biocon3.characterName AS con3 FROM champions LEFT JOIN titles AS titles ON titles.ID = champions.titleID LEFT JOIN characters AS biochamp ON champions.champID = biochamp.ID LEFT JOIN characters AS biocon1 ON champions.con1ID = biocon1.ID LEFT JOIN characters AS biocon2 ON champions.con2ID = biocon2.ID LEFT JOIN characters AS biocon3 ON champions.con3ID = biocon3.ID WHERE titles.statusID = '1' ORDER BY titles.ID"; $championsResult = mysqli_query($dbc, $championsQuery); while ( $row = mysqli_fetch_array ( $championsResult, MYSQLI_ASSOC ) ) { $fieldarray=array('titleName','shortName','championID','championshortName','champion','con1ID','con1','con1shortName','con2ID','con2','con2shortName','con3ID','con3','con3shortName'); foreach ($fieldarray as $fieldlabel) { ${$fieldlabel} = $row[$fieldlabel]; } ?> <div id="title"><span class="large">< ?php echo $titleName ?></span> < ?php if (file_exists('images/championshots/'.$titleshortName.'/'.$championshortame.'.png')) { echo "<img class=champion src=images/championshots/".$shortName."/".$champion.".png alt= />\n"; } else { echo "<img class=champion src=images/championshots/".$shortName."/".$shortName.".png alt= />\n"; } if (strlen ($champion) < 1) { echo "<span class=medium>Vacant"; } else { echo "<span class=medium><a href=/bio?shortName=".$championshortName.">".$champion."</a></span>\n"; echo "<span class=medium>(Since TBD)</span>"; } ?> <span class="contender">Contenders</span> <ul> < ?php if ( strlen ($con1) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con1shortName.">".$con1."</a></li>\n"; } if (strlen ($con2) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con2shortName.">".$con2."</a></li>\n"; } if (strlen ($con3) < 1) { echo "<li><span class=medium>TBD</span>"; } else { echo "<li><a href=/bio?shortName=".$con3shortName.">".$con3."</a></li>\n"; } ?> </ul> </div> < ?php } ?> </div> |