PHP - Mysql_num_rows Not Working With Die Statment Or If Statment
So im trying to figure out if a user is already in the table so im checking for the number of rows where the user id shows up on a record and if its greater then one redirect them. My problem is the if statment does not work and I know there is more then one row. Also die ($row2); wont output data but it will in a sentence (see code below for example)
Code: [Select] $sql2 = "SELECT * FROM purchases WHERE nid = '$id' AND uid = '$user_id'"; $res2 =mysql_query($sql2) or die (mysql_error()); $row2 = mysql_num_rows($res2); die($row2);//no output die("There are a total of ".$row2." rows");//outputs There are a total of 20 rows if ($row2 > 0){//if statment doesnt work. //already bought the note header("Location: view.php?error=2"); } Similar Tutorialsim having a few problems with if and endif see line of code below what have i done wrong <? if($forum_user['g_id'] <= USER_MOD):?><th class="tcr"><?php echo $lang_online['IP'] ?></th><?php echo "\n";endif ?> keeps kicking up error: Parse error: syntax error, unexpected T_ENDIF thanks Hi guys, hopfully you can help me write out an if Statment; basically i want to make an "IF" statment to check if the user has purchased a "ticket" within the last 24 hours, if so echo YES if not echo NO the 'ticket' database is setup as follows: auctionID promoID username charID ticketNumber ticketPrice purchaseDate - Example:" 20101228 11:59:25" it will include the WHERE clause of "username =$username" can someone help me please, im not good with time based stuff.. hey guys i have a car dealer script and i want to make the interface look better.. so i want to put icons(door locks-ac-auto-manu-4 door..) my issue is the if.. so im guessing <? if ( $row3['Door_locks'] == 1 ) { echo "<img src="icons/Doors.png" width="32" height="32" border="0">";} ?> Hey there fellow PHP coders I am sorta a newbie with php but i am having a heck of a time with this If Else statement and i know someone with experience will be able to tell me why the else if is not working What this is here is on our company intranet our agent love to send out flyers without picture and makes us look bad... so this is an IF Else if there is a picture display the eFlyer options else dont display the flyer options If doesnt seem to do the else can anyone see something that i am not seeing i have been staring at it for 2 hours now trying different little things and havent been able to get it to work PLEASE PLEASE help me thanks for everyone who reads this <?php if( $mlsInfo['PhotoURL'] != "") echo "<a href='emailListing.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 0)' onMouseOut='hideTip()' ><img src='images/buttons/fb_eListing.gif' width='106' height='20' border='0'></a> <a href='emailPostcard.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 2)' onMouseOut='hideTip()' ><img src='images/buttons/fb_ePostcards.gif' width='106' height='20' border='0'></a> <a href='emailFlyer.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 3)' onMouseOut='hideTip()' ><img src='images/buttons/fb_Flyer.gif' width='110' height='20' border='0'></a> <a href='../print_rs.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 5)' onMouseOut='hideTip()' ><img src='images/buttons/fb_printFlyer.gif' width='106' height='20' border='0'></a> <a href='fb_propertyRS_print.php?type=rs&mlsn=".$propInfo['MLSNumber']."' target='_blank' onMouseOver='doTooltip(event, 4)' onMouseOut='hideTip()' ><img src='images/buttons/fb_printListing.gif' width='106' height='20' border='0'></a> "; else echo "You Dont have any photos please add some"; ?> I am inplanting a bonus system to a game i have. I want to say at first that i am not good at php am reading alot and go by learn by doing. But after a few hours i kinda gave up. Here is the code. The page end up blank. And i tested so my syntax work $cost and $points with only the db stuff and this code <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> <div class="yellow_12_bold"><? print (number_format($cost)); ?> </div> And it does. Anyway here is the code Code: [Select] <? $dbq = $db->execute("select * from Bonus where username='$username'"); $points = $dbq->fields['points']; $allpoints = $dbq->fields['points_total']; $dbq->close(); if ($cost == "5" && $amount == "3000") { if ($points == "5" || $points > "5") { $sqlb = "update UserData set turns=turns+'3000' WHERE turns < 50000 and location != '9' and frozen = '0'"; $result1 = mysql_query($sqlb); $sqlc = "update Bonus set points=points-'5' WHERE username = '$username'; $result2 = mysql_query($sqlb); $points2 = ($points - 5); <p align="center" class="black">Thank you! 3000 turns have been added to everyone. You have <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> bonus points left. </p> } else { <p align="center" class="black">Sorry you dont have $cost points. You have <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> bonus points left.</p> } } ?> this code works fine if the conditions are absolute ( pass, fail or empty). im trying to make the fail work if its part of the query. ive tried %fail% but didnt work. $choice = strtoupper($rows['comments']); if($choice == "PASS"){ $bgc = "#ff25f0" ; } elseif($choice == "FAIL"){ $bgc = "#666666" ; }else{ $bgc = "#FF6600" ; } Hiya peeps, I was wondering if anyone could help. I have a search page that returns and array, if there are no results. It will either not exist or it will be empty. I was wondering how I would check this and if its not empty how I would count how many other arrays are inside it, as it will be array(array(1=>'1', 2=>'2')); if it is not empty, for instance. if(empty($searchObj->compResult) OR !isset($searchObj->compResult)) { echo 'its empty'; } else { $count = count($searchObj->compResult); } Many thanks, James. i can't seem to get the statment to work Code: [Select] $filename = $f; $name = $n; if ($n == $n){ include_once('test2.php'); mysql_query ("INSERT INTO images (filename) VALUES ('$n')"); }else{ include_once('test2.php'); mysql_query ("INSERT INTO images (filename) VALUES ('$f')"); }when i execute the code it seems only to upload to the database to when the $n values or false.. any ides what i can do.... before the question is asked there is no error code... This if statment is coming up true when its suppose to be false Only reason I can think of is there is a ton of rows with id matching $_session['user_id'] which doesnt make any sense to me Code: [Select] <?php $check3 = "SELECT id FROM pm WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $check2 = mysql_query($check3) or die(mysql_error()); $check1 = mysql_num_rows($check2); if(empty($check1['id'])){ echo "Your Inbox is Empty"; } ?> <?php //include the connect script include "../../connect.php"; //Post variables from flash $username = $_POST['username']; $friend= $_POST['friend']; $status = $_POST['status']; $username = stripslashes($username); $status = stripslashes($status); $friend = stripslashes($friend); $username = mysql_real_escape_string($username); $status = mysql_real_escape_string($status); $friend = mysql_real_escape_string($friend); $sql = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username'"); $rows = mysql_num_rows($sql); $your_username=$rows['username']; if($rows > 0) { $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } else { echo "&msgTextfriendship= REQUESTED NEW FRIEND SUCCESSFULLY!"; $insertnewfriend = mysql_query("INSERT INTO user_friends_list (username,friend,status) VALUES ('$friend','$username','0')") or die(mysql_error()); //$updateuserfriend = mysql_query("UPDATE user_friends_list SET status = '1' WHERE username = '$username' and friend = '$friend' and status ='0'"); return; } return; } else { echo "WiiStream Error!"; return; } ?> This right here I haven't tested it yet but I wanted to ask if this would work.. $sql1 = mysql_query("SELECT * FROM user_friends_list WHERE username = '$username' and friend = '$friend' and status ='$status'"); $rows = mysql_num_rows($sql1); if($username && $friend && $status == "0" || $username && $friend && $status == "1") { echo "&msgTextfriendship= REQUESTED REJECTED ALREADY FRIENDS OR STATUS IS PENDING!"; return; } I have a while loop that works fine but when I add an if condition within the loop it does not echo the if condition. I'm trying to echo an extra row in the table if the number of clubs returned is > 2 <?php for($i = 0; ($ClubDetails1 = mysql_fetch_assoc($ClubDetails)) && $i < 2; $i++){ ?> <tr> <th scope="col"></th> <th scope="col"><?php echo $ClubDetails1['name']; ?></th> <?php if ($i > 2) { echo "<th scope=\"col\"><a href=\"club_page.php\"> More </a> </th>"; } ?> </tr> <?php } ?> hi i am trying to count the number of clicks to an external link this is what i have come up with but it doesnt redirect but the if statment doesnt work properly because every time i click a link it always echos hello saying $add is not numeric when it is???? please help <html> <a href="index.php?add=1">Gamerforums</a><br> <a href="index.php?add=2">Google</a><br> <a href="index.php?add=3">Ebay</a><br> <a href="index.php?add=4">Paypal</a><br> <?php $add = $_GET['add']; include 'connect.inc'; if (is_numeric($add)) { mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$add'"); $result = mysql_query("SELECT * FROM count WHERE id='$add'"); $row = mysql_fetch_assoc($result); $url= $row[url]; header ("Location: $url"); } else { echo "hello"; } ?> </html> im having problems with the count in the if statment. its only counting the last value _posted. im missing something really simple but i can not see it. help please. Code: [Select] <?php $count= $_GET['seatco']; for ($i=1; $i<=$count; $i++) { $ticket = $_POST['tick_com'.$i]; echo "tickets: ".$ticket; echo "<br>"; $adult= "0"; $child= "0"; $concession = "0"; if ($ticket =="adult") { $adult++; } elseif($ticket == "child"){ $child++; } elseif($ticket =="concession"){ $conc++; } else{ echo "no";} } } echo "Adult".$adult; echo "Child".$child; echo "Concession".$conc; ?> I can not get the below to work: if(time() < strtotime("11/21/2011 3:30AM EST") && time() > strtotime("11/21/2011 2:30PM EST")) It should be evaluating to true between 3:30 AM and 2:30 PM EST for today. Now that it's past 2:30PM it should be evaluating to false, but it's coming up as true. Edit: Nevermind. Cache/Cookies Issue. hello. im having trouble putting an if statment in my loop this is my loop. Code: [Select] <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> i what to add an if $pageName = '$topNavs->title'; then <li class = selected> any ideas thanks rick Hi all..
My head just isn't working correctly today I can write this in english but can't think how to put this or even search for the code I'm looking for..
so I have a table such as this..
id - lineno - hitcount 1 - 2 - 0 2 - 2 - 0 3 - 3 - 0 4 - 3 - 1 5 - 4 - 0 6 - 4 - 0 7 - 4 - 0 And want to echo only if the hitcount is 0 for everything with a lineno of x So in this case I should return lines 1,2,5,6 & 7 but not 3. Any help appreciated Andy. I have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. Code: [Select] <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> I have a foreach loop in a webpage that displays some fields ($c), it looks like this: foreach($this->fDisplay[5] as $field) { $c = $this->field->showFieldValue($this->content,$field); if(($c !== "")&&($c !== null)) { $title = $this->field->showFieldTitle(@$this->content->catid,$field); echo "<span class='f".$field->name."'>"; if ($title != "") echo "<b>".htmlspecialchars($title)."</b>: "; echo "$c<br/>"; echo "</span>"; }
I'm not fluent in php, but I think this should be an easy fix for someone who is. Basically, I have a Wordpress theme that auto generates the images from posts in each slide of the feature slider on the homepage. Goal: for php to remove the css border around the image if it is a .png file Purpose: I want borders on photos in the feature slider, but no borders on images with transparent backgrounds... like free floating logos. So I figured I could use an if/else statement to determine if the file has a .png extension... if it does then it inserts the html style to remove the border. Here is the original code from the theme where it gets the image Code: [Select] <a href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>"> <?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?> </a> Here is what I was trying to get to work.. I tried taking the variable for $file from the code I assumed was populating the image path Code: [Select] <?php $file = `print_thumbnail($arr[$i]["thumb"]`; $ext = `pathinfo($file, PATHINFO_EXTENSION)`; ?> <a <?php if($ext == ".png") echo ?>style="border:none 0px !important;" <?php ; else null; ?> href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>"> <?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?> </a> Any help would be appreciated. Thanks. HI, I have a user form on a modal. The user can be updated from this modal but on the second tab is where the users password can be updated. The update button commits all changes including the password update. If the New Password field is blank i do not want it to be updated. I am using a prepared statement and am not sure how to ommit a field if it is blank. In actual fact there is a new password and a confirm password field which must be the same before the password field is updated. if ($_SERVER['REQUEST_METHOD']=='POST'){ $uid = $_POST['UM-uid']; $fname = $_POST['UM-firstName']; $lname = $_POST['UM-lastName']; $email = $_POST['UM-emailAddress']; $accountlevel = $_POST['UM-accountLevelId']; $mobile = $_POST['UM-mobileNumber']; $roleid = $_POST['UM-roleId']; $newpass = password_hash($_POST['UM-pass'], PASSWORD_DEFAULT); if(!empty($_POST['UM-firstName'])){ // prepare stmt $stmt = $conn->prepare(" UPDATE ssm_user SET user_password=?, user_email=?, user_firstname=?, user_lastname=?, user_account_level_id=?, user_mobile=?, user_role_id=? WHERE user_id = ? "); $stmt->bind_param('sssssssi', $newpass, $email, $fname, $lname, $accountlevel, $mobile, $roleid, $uid); $stmt->execute(); $_SESSION['user']=$fname." ".$lname; $_SESSION['updateUser']="has been successfully updated"; $_SESSION['actionstatus']="success"; I am sure i will be able to work out the password confirmation part, its just the omitting password from being part of the update if blank. |