PHP - Null Field
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); ?> Similar TutorialsHi
I would really appreciate some help.
I am trying to structure some php to detect if a value is null, if it is not null i want it to print the value if null print nothing.
so far all i have it doing is detecting whether it is null or not. but it is printing part of my code instead of the fields value.
here is the code I have
this is for a word press theme that I am modifying for my purpose. I have one field which is set up as a Text field in my database. What I'm wanting is if the field is blank in the form to just leave the field alone in the database. I need it to be NULL. OR...is there a way to query a database to recognize a field is blank? I see some of the fields in mysql show NULL and some are just empty, wonder what is the difference, is empty field still NULL? 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 This is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. Hi: I'm going crazy trying to do the following: I'm making a job registration process where the user registers on one php page to the website, must acknowlege and email receipt using an activate php page, then is directed to upload their C.V. (resume) based on the email address they enter in the active page output. I then run an upload page to store the resume in teh MySQL db based on the users email address in the same record. If I isolate the process of the user registering to the db, it works perfectly. If I isolate the file upload process into the db, it works perfect. I simply cannot upload teh file to the existing record based on teh email form field matching the user_email field in the db. With the processes together, teh user is activated, but teh file is not uploaded. Maybe I've simply been at this too long today, but am compeled to get through it by end day. If anyone can help sugest a better way or help me fix this, I will soo greatly appreciate it. My code is as follows for the 2 pages. ---------activate.php------- <?php session_start(); include ('reg_dbc.php'); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } $rsCode = mysql_query("SELECT activation_code from subscribers where user_email='$_GET[usr]'") or die(mysql_error()); list($acode) = mysql_fetch_array($rsCode); if ($_GET['code'] == $acode) { mysql_query("update subscribers set user_activated=1 where user_email='$_GET[usr]'") or die(mysql_error()); echo "<h3><center>Thank You! This is step 2 of 3. </h3>Your email is confirmed. Please upload your C.V. now to complete step 3.</center>"; } else { echo "ERROR: Incorrect activation code... not valid"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Job application activation</title> </head> <body> <center> <br/><br/><br/> <p align="center"> <form name="form1" method="post" action="upload.php" style="padding:5px;"> <p>Re-enter you Email : <input name="email" type="text" id="email"/></p></form> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> Upload your C.V.: <input name="userfile" type="file" id="userfile"> <input name="upload" type="submit" id="upload" value="Upload your C.V."/></form> </p> </center> </body> </html> --------upload.php---------- <?php session_start(); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $email = $_POST['email']['user_email']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include 'reg_dbc.php'; $query = "UPDATE subscribers WHERE $email = user_email (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close($dbname); } ?> <center> <br/> <br/> <br/> <br/> Thank you for uploading your <?php echo "$fileName"; ?> file, completing your registration, and providing us your C.V. for this position. <br/> <br/> <br/> We will contact you if your canditature qualifies. </center> Code: [Select] $new_array2=array_diff($my_array,$itemIds); $updatedb = mysql_query("UPDATE content_type_ads SET field_expire_value = '666' WHERE $new_array2 = field_item_id_value"); "$new_array2" has only 12 digit numbers for each item in the array, and I want to match them to the "field_item_id_value" field in the table, updating the "field_expire_value" field for the record where they match. I know I am close because the UPDATE code works before I add the WHERE statement (it of course adds '666' to EVERY field, but for a noobie it's a start!). (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. Hi, I'm developing an app using flash AS2 as the front end via PHP and a mySQL database at the backend on my server. what i'm looking to do is update/insert into a table called 'cards' and at the same time update/insert into another table called 'jingle'. There is a field called 'cardID' in jingle that should be the same as the ID number created in 'cards' thus creating a link between entries in the different tables that can be called up as i choose. hope i've been clear i just wouldn't know where to start any help would be appreciated. MySQL client version: 5.0.91 PHPmyAdmin Version information: 3.2.4 thanks in advance How should it look if I want to make a query where a field value should be lower than another field? Code: [Select] ....WHERE total_points<max_points"); 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 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. Hi... 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 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"); 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 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); 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 /> I'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'"; 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 |