PHP - If (isset($row[image_zero]))
Hi i am connecting to my database and i need the script to print something if the field is not empty, I am using the following, but its not working any ideas where i am going wrong?
if (isset($row[image_zero])) { Similar TutorialsHello all, i am hoping someone can help me. i have some code i have been working on and i am trying to add a 404 page if it cant find the page, i know it will be some sort of if statment, but with me been pretty much a noob at php i am stuck. heres the code that the page calls. Code: [Select] function get_content() { //Get page name from browser if none call it home $page = (isset($_GET['page'])) ? $_GET['page'] : 'home'; //Get The Page Content $sql = "SELECT * FROM content WHERE page = '$page'"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ //Show The Page Content echo '<h1>' . $row['title'] . '</h1>'; echo $row['body']; } } thanks all. Hi all I need to do a multiple if isset to get three variables from the URL. Here is my code for just one: if(isset($_GET['category'])) { $fetchproducts = mysql_query(" SELECT * FROM `products` WHERE category = '".$_GET['category']."'"); while($returnedProduct = mysql_fetch_array($fetchproducts)) { include('product-cell.php'); } How do I combine this to check what is the 'type' and 'colour' from the URL and fetch from the SQL accordingly? Many thanks for you help Pete I want to get the COUNT of the fields (ArrayM11 - ArrayM19), which has the word "YES". The code isn't working. Appreciate any help. $Array1 = array(); for($j=0;$j<count($ArrayM1);++$j) { $result = array_count_values($ArrayM1[$j]); if (isset($result['YES'])) { $points1 = $result['YES']; } } i Have two page login.php and verify.php In login.php user is entering Username and Password and in the action of the form i am writing verify.php. If verification is a success then i will start a session() Code: [Select] session_start(); $_SESSION['ls']="loggedin"; // ls stands for login status $_SESSION['id']=$row['id']; $_SESSION['user_name']=$row['user_name']; $_SESSION['email']=$row['email']; header('location : members.php'); die (" "); and will redirect them to members.php .... Everything is working fine... But in login.php i have written a code on the top... Code: [Select] <?php if(isset($_SESSION['ls']) && isset($_SESSION['id']) && isset($_SESSION['user_name']) && isset($_SESSION['email']) ) { header('location:members.php'); die(" "); } ?> I want if a session is started and if user will access login.php they will automatically go to members.php But this script is not working... Iam not getting whats the problem... also i m not getting any error login.php or anything CODE WRITTEN ON THE TOP OF members.php IS : Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) // Checks if the person has done stage one (Registration.php) { header('Location: login.php'); //If they haven't done it, it sends them back. die (" "); } ?> why dose this not work <?php if(isset($_SESSION['SESS_ADMIN'])) $loc = ../admin/admin.php; else $loc= ../head/head.php"; ?> <form><INPUT TYPE="button" value="Main Menu" onClick="parent.location='<?php echo $loc; ?>'"></form> </body> </HTML> Isn't this code redundant... if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == TRUE){ After all, if $SESSION['logged_in'] == TRUE then it is *obviously* set... Debbie guys this thing called isset() is bugging me.What is the difference in when you say Code: [Select] if(isset($_POST['name'])) and Code: [Select] if($_POST['name']) and Code: [Select] if(!$_POST['name']) and why would someone require a code such as Code: [Select] if($_POST['submit']=='Submit') And what is that code which tells you the user has entered something into the form Thanks People This is blowing my mind. I have this function and all I want it to do is check to make sure that the var $race is set and = '0'. The default value from the form is '0'. I also want it to check the value of race and if it is anything but the two listed , submit error. Yes I've tried to replace the || with &&.. Nothing works(Meaning that it will error when its not suppose to or it wont error when its suppose to).. Any ideas? Code: [Select] function check_Race ($race,$display_name,$member_id,$description,$ip) { //echo "This is the race". $race; //exit; if (isset($race) && $race ='0' && $race !== 'White' && $race !== 'Black'){ echo "This is an errror.!"; $t_error="19"; $member_id = $member_id; notify_Admin($t_error,$member_id,$ip); // logOut ($t_error); exit; } Hi there, I'm inserting data into a mysql database. My submissions works fine, however when a part of the form is not filled out the php scripit crashes. How can I submit all data that is set and skip pieces that aren't filled out? For example I have a plant database which has an option to insert different types of common names for the plant. It's ok if they aren't all filled out. My code is as follows: Code: [Select] <?php //insert general plant data into db $queryplant="INSERT INTO actualplanttable (id, scientific, common1, common2, common3, family, genus, description, planting, growing, care, duration, reference) VALUES ('NULL', '$_POST[scientific]', '$_POST[common1]', '$_POST[common2]', '$_POST[common3]', '$_POST[family]', '$_POST[genus]', '$_POST[description]', '$_POST[planting]', '$_POST[growing]', '$_POST[care]','$_POST[duration]','$_POST[reference]')"; mysql_query($queryplant) or die ('Error updating actualplanttable'); //insert maintenance data into db $querymaintenance="INSERT INTO plantmaintenancelinktable (plant_id, maintenance_id) VALUES ('$inserted_id', '$_POST[maintenance]')"; mysql_query($querymaintenance) or die ('Error updating plantdurationtable'); ?> Should I be trying to work an isset function into this code? Any help would be greatly appreciated. Thanks! Bill... I believe that my problem is with the isset on line 7 and 39, but I do not know of anyway around it. Can someone enlighten me. <?php session_start(); if (isset($_GET['logout'])){ unset($_SESSION['logged_in']); } ?> <html> <head> <title>Add a New Car!</title> <?php if (isset($_POST['submit'])) { //print_r($_POST); $password = md5($_POST['password']); //echo'<p>'.$password.'</p>'; $username = ($_POST['username']); //echo'<p>'.$username.'</p>'; } $db = new PDO('sqlite:login.sqlite'); $login = 'SELECT * FROM login WHERE userid="'.$username.'" AND password="'.$password.'";'; //echo'<p>'.$login.'</p>'; $attempt = $db->query($login); foreach ($attempt as $row) { //print_r($row); $_SESSION['logged_in'] = $username; } ?> </head> <body> <?php if (!isset($_SESSION['logged_in'])){ ?> <form method="post" action="Db_login.php"> <p>Username:<br /><input type="text" name="username" /> </p> <p>Password:<br /><input type="password" name="password" /></p> <p><input type="submit" name="submit" value="Log In!" /></p> </form> <?php } else { ?> <?php if(isset($_POST['submit'])) { print_r($_POST); $make = ($_POST['make']); $model = ($_POST['model']); $year = ($_POST['year']); $fuel = ($_POST['fuel_type']); $vin = ($_POST['vin_number']); $reg = ($_POST['reg_number']); } $db = new PDO('sqlite:cars.sqlite'); $sqlCars = 'INSERT INTO cars ( ) VALUES("'.$make.'","'.$model.'","'.$year.'","'.$fuel.'","'.$vin.'","'.$reg.'");'; echo'<p>'.$sqlCars.'</p.>'; ?> <form method="post" action="Db_new_Cars.php" enctype="multipart/form-data"> <p>Make:<br /><input type="text" name="make" /> </p> <p>Model:<br /><input type="text" name="model" /></p> <p>Year:<br /><input type="text" name="year" /></p> <p>Fuel Type:<br /><input type="text" name="fuel_type" /></p> <p>Vin Number:<br /><input type="text" name="vin_number" /></p> <p>Reg Number:<br /><input type="text" name="reg_number" /></p> <p>Choose a image to upload:<br /> <input type="file" name="myfile"></input></p> <p><input type="submit" name="submit" value="Submit!" /></p> </form> <h1> Protected Content!</h1> <p>You are logged in as <em><?php echo $_SESSION['logged_in']; ?> </em></p> <p><a href="Db_login.php?logout=true">Log out!</a></p> <p><a href="New_Cars.php">Add a new car</a></p> <p><a href="Book_Out_Cars.php">Book out a car</a></p> <?php } ?> </body> </html> Hey, I've got a site and I need to query a database to check if there is a result. If there isnt then I need a default result... //Check the database and get a result $skinName = strtolower(get_post_meta($post_id, $key, $single)); if (isset($skinName)) { //If there is a result, then use it $skinName = strtolower(get_post_meta($post_id, $key, $single)); } else { //If NO result then use RED $skinName = 'red'; } //Build up the var to show REDsite $skinName = $skinName . 'site'; For some reason the above doesnt work. If there is a result then it uses it, however if there is no result then it simply shows "site" - not "redsite" like it should do. Any ideas what I missed? Code: [Select] if (isset($_COOKIE['hide_div']['0']) && isset($_COOKIE['hide_div']['2'])){ $cookie1 = $_COOKIE['hide_div']['0']; $cookie2 = $_COOKIE['hide_div']['2']; } if ($cookie1 == $cat_id OR $cookie2 == $cat_id) { foreach ($this->forums as $forum_id => $forum_data) { if ($forum_data['category'] == $cat_id) { //----------------------------------- // We store the HTML in a temp var so // we can make sure we have cats for // this forum, or hidden forums with a // cat will show the cat strip - we don't // want that, no - we don't. //----------------------------------- $temp_html .= $this->process_forum($forum_id, $forum_data); } } if ($temp_html != "") { $this->output .= $this->html->CatHeader_Expandedhidden($cat_data); $this->output .= $this->html->end_this_cat(); } unset($temp_html); }else{ $cookie1 = ''; $cookie2 = ''; why in the world is it displaying Undefined variable: cookie1 and cookie2 as errors? When I declared both of them even AFTER my if statement, this is bogus dude, lol this isset stuff is really confusing or am i just not doing it right? Hi, just began working with the isset function, and having a few problems with the following code. As you can see I'm trying to assign some variables using the explode function. This is the string that is taken from the form on my index page http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/refresh_stat_manual?user_id=100000898907997&auth_key=e5f4a2308d13346b4bf6e8228e9f50636240bf9f&nocache=1290001265332& $RawHeader = str_replace(' ', '', $_POST['RawHeader']); if (isset($RawHeader)) { $UserID = explode('user_id=', $RawHeader); $UserID = explode('&', $UserID[1]); $UserID = $UserID[0]; $AuthKey = explode('auth_key=', $RawHeader); $AuthKey = explode('&nocache=', $AuthKey[1]); $AuthKey = $AuthKey[0]; } I am new to the isset function so I don't really know if there is anything wrong with it, but if I try echo out both $UserID and $AuthKey it returns nothing. Any suggestions or solutions? Thanks Im trying to use an if isset to stop my error messages displaying before they submit the form it worked on another part of my website but wont work for this, It just wond submit the form at all when i click submit here is the code: <html> <head> </head> <body> <form action="contact.php" method="post"> <fieldset> <legend>Contact Us</legend> Your Email:*<br> <input type="text" name="email"><br> Subject:*<br> <select name="subject"> <option value=""></option> <option value="1">Recruitment</option> <option value="2">Absense</option> <option value="3">Enquiry</option> </select> <br> Message:*<br> <textarea name="message" cols="50" rows="5"></textarea><br> <?php require_once('recaptchalib.php'); $publickey = "6LeB8LwSAAAAAKwvC3HWJNwWw9vYiSEkvFEvDduD"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <br> <input type="submit" value="Send Email"> </form> Required fields are marked with a *<br><br> <?php if(isset($_POST['Submit'])){ $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = "nathan_k_boothby_1994@hotmail.co.uk"; //checcking that all relevent information is entered and correct if(!$message || !$email) { $errmessage ="Please fill in all required data."; } require_once('recaptchalib.php'); $privatekey = "6LeB8LwSAAAAAA_0IIEnAxL5uOau0TBm83Iog7Ey"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $errmessage ="The text you wrote did not match the image."; } //Sending the email if nothing is wrong if(!$errmessage) { header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message.""); }else{ echo $errmessage; } } ?> </fieldset> <br><br><br> </body> </html> And here is a link to the page: http://valiantflight.comlu.com/emailer/contact.php Any help will be greatly appriciated, Thanks, Blink359 Running into some problems with my code. I am having the user search the Database with either a UAID or the user's full name. It works fine when you input both the UAID and name; however, I want it to work if only one is give (i.e. just the name or just the UAID). I decided to use the isset($_POST) function of php but I am not getting it to work correctly. PHP believe it is set even though it is empty. Here is my html form. <?php @include 'accesscontrol.php'; 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\">" ."<title> Hello </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td align=\"center\">" ."<form method=\"post\" action=\"user.php\">" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"500\" height=\"400\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<td colspan=3 width=40% align=center>" ."UAID:<br> <input type=\"text\" size=\"8\" name=\"UAID\" /></td>" ."<td colspan=3 width=60% align=center>" ."Name (Last, First):<br><input type=\"text\" size=\"8\" name=\"last\"/>, <input type=\"text\" size=\"8\" name=\"first\" />" ."</tr>" ."<tr>" ."<td colspan=6 align=\"center\"><input type=\"submit\" value=\"submit\" />" ."</td>" ."</tr>" ."</tr>" ."</table>" ."<tr>" ."</tr>" ."</td>" ."</tr>" ."</table>" ."</body>" ."</html>"; ?> Here is the PHP: <?php @include 'accesscontrol.php'; //include 'common.php'; include 'db.php'; $fname = $_POST['first']; $lname = $_POST['last']; $sql = "SELECT * FROM `user` WHERE UAID='$_POST[UAID]'"; $result = mysql_query($sql); $rows = mysql_fetch_array($result); if(isset($fname) && isset($lname)) { echo "Post first $fname <br>" ."Post last $lname"; $firstname = $rows['firstname']; $lastname = $rows['lastname']; if($fname != $firstname OR $lname != $lastname) { ?> <html> <head> <script language="JavaScript"> alert(" Hello this is crap" ); history.back(); </script>"; </head> </html> <? exit; } else { echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"URL\">" ."<html xmlns=URL>" ."<title> Hi </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td align=\"center\">" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"600\" height=\"400\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<form method=\"Post\" action=\"userview.php\">" ."<td colspan=3 width=40%>" ."UAID: <input type=\"text\" size=\"8\" name=\"UAID\" value= ".$_POST['UAID']." /></td>" ."<td colspan=3 width=60%>" ."Name (LAST, FIRST):<input type=\"text\" size=\"8\" name=\"last\" value= ".$_POST['last']." />, <input type=\"text\" size=\"8\" name=\"first\" value= ".$_POST['first']." />" ."</td>" ."</tr>" ."<tr>" ."<td colspan=3 width=40%>" ."Department:<input type=\"text\" size=\"8\" name=\"department\" value=" .$rows['BOG'].">" ."</td>" ."<td colspan=3 width=60%>" ."Employee ID:<input type=\"text\" size=\"8\" name=\"empID\" value=" .$rows['employeeID'].">" ."</td>" ."</tr>" ."<tr>" ."<td colspan=3 align=\"center\"><input type=\"submit\" value=\"View\">" ."</form>" ."</td>" ."<form method=\"Post\" action=\"homepage.php\">" ."<td colspan=3 align=\"center\"><input type=\"submit\" value=\"Back\">" ."</td>" ."</tr>" ."</tr>" ."</table>" ."<tr></tr></td></tr></table></body></html>"; }} mysql_free_result($result); ?> Hi guys I am trying to create a page where if a selection has not been made then a jump menu is displayed listing all of the fixtures for a season, if a selection has been made then at present I want it to show Enter match info, however when a match is selectd it goes to a yahoo search page, as if the page cannot be found, the code I have used is below, any ideas what I have done wrong? The page can be seen at www.yardleyheroes.co.uk/admin/edit_result.php Code: [Select] <h1>Submit Results</h1> <?php if (isset ($_GET['match_id'])) { echo('Enter match info'); } else { $con = mysql_connect('localhost', 'user', 'password', true); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('dbname', $con); echo('<form name="form" id="form">'); echo('<select name="jumpMenu" id="jumpMenu" onChange="MM_jumpMenu(\'parent\',this,0)">'); $fixtures=mysql_query('SELECT * FROM `fixtures` where current=1 ORDER BY `match_date`'); if(mysql_num_rows($fixtures)==0) echo('<option>there is no data in table..</option>'); else echo('<option selected="selected">Please select the match</option>'); { while($matchrow=mysql_fetch_assoc($fixtures)) { echo ('<option value="edit.php?match_id='.$matchrow['match_id'].'">'.date("d-M-Y", strtotime($matchrow['match_date'])).'|'.$matchrow['Opposition']."</option>"); } } echo('</select>'); echo('</form>'); } ?> [/cod] Hey all, I am fairly new in the php world and have set myself a challenge to create a display of a database. I have the database displaying what I want but now am trying to have a 'complete' field where if ticked it will delete that field from the db. The row ['complete'] line 30 is saved in the db as '0' when ticked I want this to change to a '1' and delete that line from the db. I have tried a few things but am getting a little bit lost. Any help would be much appreciate <?php $con = mysql_connect("Host","USER","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("TABLE", $con); $result = mysql_query("SELECT * FROM Priority"); echo "<table border='1' width='100%'> <tr> <td width='5%'>Ticket Number</td> <td width='5%'>Order #</td> <td width='65%'>Ticket Info</td> <td width='15%'>Assigned by</td> <td width='5%'>Priority</td> <td width='10%'>Complete</td> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>#" . $row['ID'] . "</td>"; echo "<td>" . $row['OrderNumber'] . "</td>"; echo "<td>" . $row['TicketInfo'] . "</td>"; echo "<td>" . $row['Assignedby'] . "</td>"; echo "<td>" . $row['Priority'] . "</td>"; echo "<td><input type='checkbox' name='Check' value='Check' /></td>"; //the last row, where the checkbox is is actually a row called ['complete'] } if(isset($Check) && $Check != "") { mysql_query("UPDATE Priority SET Complete = '1' WHERE $row = 'ID'"); } echo "</table>"; mysql_close($con); ?> <?php $con = mysql_connect("HOST","USER","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_query("DELETE FROM Priority WHERE Complete='1'"); mysql_close($con); ?> Hi Everyone, I am a great fan of the 'isset' function, which I use alot when submitting forms, but not wanting to navigate away from the page. Normally I just use a form with a submit button with a name, for example: Code: [Select] <input type='submit' name='updatetable' value='Go!'/> and then use the following: <?php if (isset ($_POST['updatetable'])) { do this stuff... } ?> But I want to start to use images as submit buttons, so when you click on them, you are able to submit the underlying data. Is there a way to do this using the isset function? Because effectively, the image, which would submit using javascript, wont have a name. Any ideas appreciated Many Thanks Matt What I remember from my college days is that isset check whether the variable has a value set or not and return true or false value.
However I encountered a code in wordpress -
// Set up the content width value based on the theme's design and stylesheet. i know theres a way but i just forget. i want to do a switch function. Code: [Select] switch ($_GET['page']) { case 0: include 'page'; break; case 1: include 'page1'; break; case 2: include 'page2'; break; default: include 'page'; } ?> just like that but if there is no $_GET page i just want it to do the default. instead of doing if isset GET page do switch else default page. i just want it to be simpler by doing something like switch(isset$_GET etc. |