PHP - Problem With Else If Inside While Statement
I have the following code which gets staff working on a selected day and their start and finish times.
The code then lists out the day for every 15min of time for each staff member. During the loop of each staff member I then check an appointment table to see if a user has any appointments, and lists the booked time slots, if no appointments lists user as available for all the time slots. My problem is when a user has appointments it only shows the booked times and not the available times. I know the problem lies here else if ($inc<$resSTART && $inc>$resEND) { and the complete code that is from is here // convet to US format $input="$month/$day/$year"; // readable date $readDATE="$day/$month/$year"; // convert for mysql date $sqlDATE="$year-$month-$day"; // get day of the week $weekday=date(l, strtotime($input)); echo $weekday."<br/>"; // get working staff from staff table $staffSQL=mysql_query("SELECT * FROM staff WHERE ".$weekday." != 'off' AND onLEAVE='no' AND ACTIVE='yes' ORDER BY staffID ASC"); // return results putenv("TZ=Australia/Adelaide"); while ($staff=mysql_fetch_array($staffSQL)) { $name=$staff['staffNAME']; $avail=$staff[$weekday]; $staffID=$staff['staffID']; list($first, $last)=explode(" ", $name); list($in, $out)=explode("-", $avail); $firstTIME="$sqlDATE $in:00"; $lastTIME="$sqlDATE $out:00"; echo "$first is available between $avail on $weekday<br/>"; $in2=strtotime($firstTIME); $out2=strtotime($lastTIME); $stop=$out2-900; echo $in2." - time start - $firstTIME<br/>"; echo $out2." - time finish - $lastTIME<br/>"; for ($inc=$in2;$inc<=$stop;$inc+=900) { $existSQL=mysql_query("SELECT * FROM appointment WHERE date='$sqlDATE' AND staffID='$staffID'"); if (mysql_num_rows($existSQL)>=1) { while ($appointV=mysql_fetch_array($existSQL)) { $resSTART=$appointV['dateTIME']; $length=$appointV['totalTIME']; $resEND=$resSTART+($length*60); if ($inc>=$resSTART && $inc<=$resEND) { echo "Appointment time is ".date("g.i a", $inc)." <font color='red'><< $first BOOKED</font><br/>"; } else if ($inc<$resSTART && $inc>$resEND) { echo "Appointment time is ".date("g.i a", $inc)." <font color='green'><< $first AVAILABLE</font><br/>"; } } } if (mysql_num_rows($existSQL)==0) { echo "Appointment time is ".date("g.i a", $inc)." <font color='green'><< $first AVAILABLE</font><br/>"; } } } any ideas how to restructure that if statement to work properly would be very much appreciated Similar TutorialsI'm having issues with the following: Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; if($_SESSION['username']=="username" && $_SESSION['password']=="password"){ if($_GET['product']=="add"){ $content.=' <p><label>Product Name:</label> <input type="text" name="product_name" size="30" /> <label>Product Price:</label> <input type="text" name="product_price" size="5" /> </p> <p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p> <p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p> <p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p> <p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p> <p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p> <p><label>Product Features:</label><br /> <textarea name="product_features" rows="10" cols="60"></textarea> </p> <p><label>Product Pros:</label><br /> <textarea name="product_pros" rows="5" cols="30"></textarea> </p> <p><label>Product Cons:</label><br /> <textarea name="product_cons" rows="5" cols="30"></textarea> </p> <p><label>Product Description:</label><br /> <textarea name="product_description" rows="10" cols="60"></textarea> </p> <p><label>Product Notes:</label><br /> <textarea name="product_notes" rows="5" cols="30"></textarea> </p> '; $logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>'; } elseif($_GET['product']=="view"){ } else{ $content.=' <a href="./admincp.php?product=add">Add New Product</a> <br /> <a href="./admincp.php?product=view">View Products</a> '; } } elseif(isset($_GET['log-out'])){ session_start(); session_unset(); session_destroy(); header("Location: ./admincp.php"); } else{ $content=' <form action="./admincp.php" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" />'; $content.='</p> <p><label>Password:</label> <input type="password" name="password" /></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <base href="http://ghosthuntersportal.com/" /> <title>Ghost Hunter's Portal - Admin Control Panel</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="verify-v1" content="" /> <meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" /> <meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." /> <meta name="author" content="Andrew McCarrick" /> <meta name="robots" content="index, follow" <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" /> <br /> <div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div> <?php echo $logout; echo $content; ?> </body> </html> I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop. It's doing this: Log-In --> Page with links ---> Log-In page again Should be doing this: Log-In --> Page with links --> Add Product page or View Products page I can never get into the the actual sub page. Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page. After it goes through the while loop its supposed to take the ID of the first one in the loop and find out its awardType and then with the awardType variable go through the the if statement. After it displays it the code that fits the awardType variable then it gets the second item in the while loop and then with the ID of the second item takes it back to get the awardType and then goes back through the if statement again. I'm not sure what I'm doing wrong. As of right now all its doing is displaying its awardName and a blank dropdown. Code: [Select] <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php');l $userID = $_SESSION['userID']; $statusQuery = " SELECT * FROM statuses"; $statusResult = mysqli_query ( $dbc, $statusQuery ); // Run The Query $awardQuery = " SELECT awards.ID, awards.awardName, awards.awardType FROM awards"; $awardResult = mysqli_query ( $dbc, $awardQuery ); // Run The Query $row = mysqli_fetch_array ( $awardResult, MYSQL_ASSOC ); $awardType = $row[ 'awardType' ]; $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query $matchQuery = " SELECT eventSegments.ID, eventSegments.segmentTitle FROM eventSegments INNER JOIN events ON eventSegments.eventID = events.ID WHERE DATE_FORMAT(events.bookingDate,'%Y') = DATE_FORMAT(curdate(),'%Y')"; $matchResult = mysqli_query ( $dbc, $matchQuery ); // Run The Query ?> Code: [Select] <fieldset> <legend>Nominees</legend> <?php mysqli_data_seek( $awardResult, 0 ); while ( $row = mysqli_fetch_array ( $awardResult, MYSQL_ASSOC ) ) { ?> <?php if ($awardType == 'Singular') { ?> <div class="field required"> <label for="charactersDrop"><?php echo $row['awardName']; ?></label> <select class="dropdown" name="charactersDrop" id="charactersDrop" title="Characters Drop"> <option value="">- Select -</option> <?php while ( $row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r"; } ?> </select> <input type="button" value="Add Character" class="" onclick="HandlerCharacters()"/> <ul id="characterList"> </ul> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <? } else { ?> <div class="field required"> <label for="events"><?php echo $row['awardName']; ?></label> <select class="dropdown" name="events" id="events" title="Events for <?php echo date("Y") ?>"> <option value="">- Select -</option> <?php while ( $row = mysqli_fetch_array ( $matchResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['segmentTitle']."</option>\r"; } ?> </select> <input type="button" value="Add Match" class="" onclick="AddMatch()"/> <ul id="matchList"> </ul> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <?php } ?> <?php } ?> I am trying to create a daily event listing. The list will have Day & Date as the heading. Then it will list the events ORDERED BY the time. First thing I'd like to do is skip or not show the days that do not have an event. Ex. Monday, January 23, 2012 7am event 8am event 6pm event since Tuesday has no events, I'd like tuesday to not be in the list, but if the next tuesday has an event It'll need be visible. Tuesday, January 24, 2012 (No events) Wednesday, January 25, 2012 9am event 12 pm event 8pm event The 2nd thing I'd like to do is If a particular day and time has more than one event, I'd like the time to show once and then list the events. ex. Monday, January 23, 2012 7am event event event 8am event 6pm event Here's the code: since the listing is for a range of 7 days I've only included 3 days worth of code. I've include the mysql_statements for pulling the information as well as the php code to show how it's being rendered and placed. HTML excluded. Code: [Select] <?php //TODAY $today2 = date('l, F j, Y');//php to format date $today_rehearsals = mysql_query(" SELECT Id, date, time, title, campus, room, ministry, category FROM events LEFT JOIN dates on events.dateId=dates.dateId LEFT JOIN time ON events.timeId=time.timeId LEFT JOIN campus ON events.campusId=campus.campusId LEFT JOIN rooms ON events.roomId=rooms.roomIdLEFT JOIN ministries on events.ministryId=ministries.ministryId LEFT JOIN category on events.categoryId=category.categoryIdWHERE ministry='music' AND date='$today' OR category='music' AND date='$today' ORDER By date, time") //////DAY ONE $day1= mktime(0,0,0, date("m"), date("d")+1, date("Y")); //php to get current date and add 1 day $day_1 = date("l, F j, Y", $day1); //php to format date $day1_rehearsal = mysql_query("SELECT Id, date, time, title, campus, room, ministry, category FROM events LEFT JOIN dates ON events.dateId=dates.dateIdLEFT JOIN time ON events.timeId=time.timeId LEFT JOIN campus ON events.campusId=campus.campusId LEFT JOIN rooms ON events.roomId=rooms.roomId LEFT JOIN ministries ON events.ministryId=ministries.ministryId LEFT JOIN category ON events.categoryId=category.categoryId WHERE ministry='music' AND date=CURDATE()+1 OR category='music' AND date=CURDATE()+1 ORDER BY time" ) or die(mysql_error()); /////DAY 2 $day2= mktime(0,0,0, date("m"), date("d")+2, date("Y")); //php to get current date and add 2 days $day_2 = date("l, F j, Y", $day2); //php to format date $day2_rehearsal = mysql_query("SELECT Id, date, time, title, campus, room, ministry, category FROM events LEFT JOIN dates ON events.dateId=dates.dateIdLEFT JOIN time ON events.timeId=time.timeId LEFT JOIN campus ON events.campusId=campus.campusId LEFT JOIN rooms ON events.roomId=rooms.roomId LEFT JOIN ministries ON events.ministryId=ministries.ministryId LEFT JOIN category ON events.categoryId=category.categoryId WHERE ministry='music' AND date=CURDATE()+2 OR category='music' AND date=CURDATE()+2 ORDER By time")or die(mysql_error()); ////TODAY echo "$today2"; //renders Today's date while($row = mysql_fetch_array( $today_rehearsals )){ $time=date_create($row['time']);//grab time for db $for_time=date_format($time, 'g:i a');//format time for viewing on page echo "$for_time"; echo $row['title']; echo $row['campus'] . " " . $row['room']; } ////day1 echo "$day_1"; //renders day_1's (tomorrow's) date while($row = mysql_fetch_array( $day1_rehearsal )){ $time=date_create($row['time']);//grab time for db $for_time=date_format($time, 'g:i a');//format time for viewing on page echo "$for_time"; echo $row['title']; echo $row['campus'] . " " . $row['room']; } ////day2 echo "$day_2"; //renders day_2's (day after tommorrow) date while($row = mysql_fetch_array( $day2_rehearsal )){ $time=date_create($row['time']);//grab time for db $for_time=date_format($time, 'g:i a');//format time for viewing on page echo "$for_time"; echo $row['title']; echo $row['campus'] . " " . $row['room']; } MOD EDIT: code tags fixed . . . Hi everyone. i'm trying to write an if statement for several scenerios 1. if the date entered in '$DateDue' is overdue, meaning greater than todays date, then display the word 'Late'. 2. if the date entered in '$DateDue' is not yet past, meaning its greater than todays date, then display the word 'ok'. 3. if the date entered in '$DateDue' is within a week of todays date, then display the word 'warning' the code snippet below is my partial script. it runs perfectly without embedding the 'php if statement' on the first td row. So my problems a 1. how to embed a php if statement in table results and 2. have OK, LATE or WARNING to be displayed based on if $DateDue expires or not. there are no errors in the code below, it just echos the line '<?php if ($DataDue > CURDATE()) {echo "OK";} elseif ($DateDue < CURDATE()) {echo "LATE";} else {echo "Warning";}?>' instead of displaying OK, LATE or Warning. I'd appreciate any assistance you could provide. thanks. Code: [Select] // echo out the contents of each row into a table echo "<tr>"; echo '<td nowrap><?php if ($DataDue > CURDATE()) {echo "OK";} elseif ($DateDue < CURDATE()) {echo "LATE";} else {echo "Warning";}?>' . mysql_result($result, $i, 'DateDue') . '</td>'; echo '<td nowrap>' . mysql_result($result, $i, 'Description') . '</td>'; echo '<td nowrap>' . mysql_result($result, $i, 'CompanyName') . '</td>'; echo "</tr>"; Hello guys im new to php i been coding for like a week now, i need some help here i have been stuck for like 6 hours XD,is it possible to write an IF Statement inside an echo? //this is what i want to do // echo a table and a delete button // and if you click on the delete button it echoes out "DELETED" echo " <table width='528px'> <tr> <td> </td> <td> <center><font size='5'>$tittle</font></center><br> </td> </tr> <tr> <td> </td> <td> $message </td> </tr> <tr> <td> </td> <td> <font size='1'>Posted By:<font color='green'>$author</font> on <font color='gray'>$date</font> at <font color='gray'>$time</font></font> <input id='delete' name='delete' type='submit' value='Delete' > if ($_POST['delete']) { echo "DELETED"; } <td> </td> </tr><br><br> </table> "; I am wondering if it is possible to create 2 queries, and use 1 while statement? Something like: Code: [Select] while (($row = mysql_fetch_array($rs_getevent)) && ($row = mysql_fetch_array($rs_getevent2))) { Is something like this possible? I have a bunch of checkboxes I am pulling from a database, like so. Code: [Select] <?$true_query = mssql_query("SELECT * FROM checkbox_datbase ORDER BY ID ASC"); while ($true_row = mssql_fetch_assoc($true_query)) { $eth_id = $true_row['ID']; $eth_name = $true_row['Value']; echo "<input type=\"checkbox\" name=\"eth_$eth_id\" value=\"1\" class=\"input\" id=\"Ethnic_01\"/>$eth_name <br />"; } ?>How do I put these into a database that I have settup where it needs to match up with a userid. I am trying to do this, and can get it to look correctly by echoing out the various parts, but I can't put while loops into a variable, right? So how would I get all of this into one line in my $sql variable? Code: [Select] echo "INSERT INTO new_database (UserId,"; $true_query = mssql_query("SELECT * FROM checkbox_datbase ORDER BY ID ASC"); while ($true_row = mssql_fetch_assoc($true_query)) { $eth_id = $true_row['ID']; $eth_eth_id = $_POST['eth_' . $eth_id . '']; echo " $eth_id, "; } echo "DateUpdated) VALUES ('$user_ID', "; $true_query = mssql_query("SELECT * FROM checkbox_datbase ORDER BY ID ASC"); while ($true_row = mssql_fetch_assoc($true_query)) { $eth_id = $true_row['ID']; $eth_eth_id = $_POST['eth_' . $eth_id . '']; echo "'$eth_eth_id', "; } echo "'$currenttime')"; This echoes something that looks like this INSERT INTO user_ethnicity (UserId, 1, 2, 3, 4, 5, 6, 7, 8, DateUpdated) VALUES ('', '', '', '', '', '', '', '', '', '2012-01-23 13:24:18 PM') , which I need the actual statement to be $sql = "INSERT INTO user_ethnicity (UserId, 1, 2, 3, 4, 5, 6, 7, 8, DateUpdated) VALUES ('259', '', '', '1', '', '1', '', '', '', '2012-01-23 13:24:18 PM')"; Can anyone help me with this? Hey guys! Im trying to setup an IF statement on my home page. Its purpose is to show EITHER a login form and state your not logged in if it cannot find a stored cookie OR if it does find a stored cookie it will NOT show the HTML form and state you are logged in. I have it mostly working apart from the fact Im not sure how to insert a HTML form into PHP IF statement and make it work. Since I dont want the user to see the login form when they are already logged in. Here is a link to the php script: http://pastebin.com/aenq4gbE Here is link to the live page: http://jfbsystems.co.uk/secure Any help or ideas would be much appreciated! JellyFishBoy Hi I am new to PHP and this is my first post one here so appologies is this questions seems a bit dumb! I have an if clause such that if a button is pressed on my web page then i want to reload the page and include a new form on it. I am having a problem getting the $_SERVER['PHP_SELF'] command to work from iside a echo command. I must not be escaping the code correctly with back slashes: I currently have the line : echo"<form method=\"POST\" action=\"\<?$_SERVER['PHP_SELF']?\>\">"; However this doesnt seem to work as my page just doesnt display in the browser. Any advice is much appreciated. Thanks for taking the time to read. Is it possible to have a loop inside a mysql select statement? If yes, can someone please give me an idea. Well I guess I'll jump right into the code.. The function: function isIpaddr ($ipaddr) { if (ereg("^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$", $ipaddr, $digit)) { if (($digit[1] <= 255) && ($digit[2] <= 255) && ($digit[3] <= 255) && ($digit[4] <= 255)) { return TRUE; } } return FALSE; } The loop and IF statement: if($_POST['submit_multiple']) { $SubmittedIPs = split("[\n|\r|,|-]", $_POST['IPAddresses']); foreach($SubmittedIPs as $IP) { trim($IP); if(isIpaddr($IP)) { echo $IP." = ".gethostbyaddr($IP)."<br />"; } else { echo "Invalid IP Address<br />"; } } } There's my relevant code.. Now the only problem so far is that I am getting this: Quote 12.34.56.78 = 12-34-56-78.test.hostname.com Invalid IP Address 12.34.56.78 = 12-34-56-78.test.hostname.com Invalid IP Address 12.34.56.78 = 12-34-56-78.test.hostname.com (The IPs and Hostnames are obviously fake..) The problem is that they are valid IP addresses and I've done a few checks to see what's wrong. I've checked the array and it is working fine by splitting up a textbox into an array of IPs and the IPs are fine inside the array. I then tested the script by echoing the output of just the function with each IP, I got all "1"s (TRUE). I just can't figure out why it's displaying both parts of the if statement.. Thanks for any help! Hi im new to this site so i hope this is in the right place,my table goes green when i try to say less than 14 but when i use greater the code looks ok ,its works by itself but im using five similar else if statements for different ages(teacher doesnt want functions used yet) can anyone please help ??? Code: [Select] else if($myAge >9 || $myage <14) { echo"<table width='500' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>"; echo"<tr>"; echo"<td>"; echo"<table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>"; echo"<tr>"; echo"<td colspan='3'><h3><strong>Sports Catagory</h3></strong></td>"; echo"</tr>"; echo"<tr>"; echo"<td><hr></td>"; echo"</tr>"; echo"<tr>"; echo"<td> ".$username." a-zA-z</td>"; echo"</tr>"; echo"<tr>"; echo"<td> ".$password." 0-9</td>"; echo"</tr>"; echo"<tr>"; echo"<td>Invalid data entered, please re-enter the data correctly</td>"; echo"</tr>"; echo"<tr>"; echo"</tr>"; echo "<tr>"; echo "<td><a href = '".$self."'> Back to Form </a></td>"; echo "</tr>"; echo "</table>"; echo"</td>"; echo"</tr>"; echo"</table>"; } I have a series of PHP files that are referenced in index.php like this: <?php include("credentials.inc"); $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); include('header.php'); include('menu.php'); include('contact.php'); include('home.php'); ?> One of my files, menu.php, brings up a JavaScript menu that was coded in Dreamweaver (yes, I cheated). However, it seems to get to the first "for" statement and stops. I can't work out what I've done wrong. <?php $h1 = mysqli_query($cxn, "SELECT areaID, area FROM area ORDER BY areaID"); echo("<ul id='MenuBar1' class='MenuBarHorizontal'>"); echo("<li><a href='index.php'>HOME</a></li>"); echo("<li><a href='#' class='MenuBarItemSubmenu'>PRODUCTS</a><ul>"); for ($a=0;$a<=count($h1);$a++) { echo("<li><a href='#' class='MenuBarItemSubmenu'>".$h1[$a]['area']."</a><ul>"); $h2 = mysqli_query($cxn, "SELECT catID, category, areaID, link FROM category WHERE areaID = '".$h1[$a]['areaID']."' ORDER BY catID"); for ($b=0;$b<count($h2);$b++) { echo("<li><a href='".$h2[$b]['link']."'>".$h2[$b]['category']."</a></li>"); } echo("</ul></li>"); } echo("</ul></li>"); echo("<li><a href='services.php'>SERVICES</a></li>"); echo("<li><a href='aboutus.php'>ABOUT US</a></li>"); echo("<li><a href='contact.php'>CONTACT</a></li></ul>"); ?> Hopefully someone has an idea of where the problem is. Thanks so much in advance! So basically I've been experimenting with setting cookies and sessions. The code in my header file will display a login if there is no $_SESSION['username']. However, the else statement verifies that there is, and echo's "hello." My problem lies in the else statement, when the login form disappears, but nothing in the else statement appears. Here's the code, I feel like I am missing something obvious. Code: [Select] <?php if (!isset($_SESSION['username'])){ echo "<li><a href='register.php'>Register</a></li>"; echo "</ul>"; echo " <table> <tr> <form name='login' method='post' action='login.php'> <tr><td>Username</td> <td><input type='text' name='username'></td></tr> <tr><td>Password</td> <td><input type='password' name='password'></td></tr> <tr><td><input type='submit' name='submit' value='Login'></td></tr> <tr><td><input type='checkbox' name='rememberme' value='remember'> Remember</td></tr> </form> </table> "; }else{ echo "hello"; } ?> Thanks in advance I am creating a class alumni web and ask a question tha requires selecting one of 3 radio buttons. If the user selects the 3rd button, I want to display an additional field. Here is the lines of code: <label>Are you or your spouse a Taft Class of 1965 alumni?</label> <input type="radio" id="alumni" value=1 checked><label>yes</label> <input type="radio" id="alumni" value=2><label>no</label> <br> <label>Are you a graduate of Taft Union High School?</label> <input type="radio" id="alumni" value=3><label>yes</label> Error ---> <?php // If alumni is equal to 3 display the input field If ($ans == 3);{ Echo "<input type='int' id='gradClass' size='4' maxlenght='4' placeholder='1977'>" } ?> <br> <hr> <br> <span class="subheader">PRIVACY</span> <br> And I didn't forget a ' this time. Could someone please assist. Thanks in advance. My code is as follows <?php // Include the Sessions options require_once('inc/session_admin.inc.php'); ?> <!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" xml:lang="en" lang="en"> <head> <title>Change Record form</title> <style type="text/css"> td {font-family: tahoma, arial, verdana; font-size: 10pt } </style> </head> <body bgcolor="#64b1ff"> <div align="center"> <?php echo '<p>Hello <b>' .($_SESSION['username']) .'</b> <a href="logging_out.php">Logout</a></p>'; $Username=$_POST['Username']; if ($Username = $Username) { // Include connecting to the database require_once('inc/connect_to_users_db.inc.php'); $query=" SELECT * FROM userinfo WHERE Username='$Username'"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $FirstName=mysql_result($result,$i,"FirstName"); $LastName=mysql_result($result,$i,"LastName"); $Address1=mysql_result($result,$i,"Address1"); $Address2=mysql_result($result,$i,"Address2"); $Address2=mysql_result($result,$i,"Address2"); $Address3=mysql_result($result,$i,"Address3"); $Gender=mysql_result($result,$i,"Gender"); $Country=mysql_result($result,$i,"Country"); $MobileNumber=mysql_result($result,$i,"MobileNumber"); $EmailAddress=mysql_result($result,$i,"EmailAddress"); ?> <table width="300" cellpadding="5" cellspacing="0" border="1"> <tr align="center" valign="top"> <td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff"> <h3>Edit and Submit</h3> <form method="post" action="update_a_user_script.php"> <input type="hidden" name="update_a_user_script" value="<?php echo "$Username" ?>" /> <table cellpadding="0" cellspacing="0" border="0"> <tr align="center" valign="top"> <td>Username:</td> <td><input type="text" name="Username" readonly="readonly" value="<?php echo "$Username" ?>" /></td> </tr> <tr align="center" valign="top"> <td>First Name:</td> <td><input type="text" name="FirstName" value="<?php echo "$FirstName" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Last Name:</td> <td><input type="text" name="LastName" value="<?php echo "$LastName" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Address:</td> <td><input type="text" name="Address1" value="<?php echo "$Address1" ?>" /></td> </tr> <tr align="center" valign="top"> <td> </td> <td><input type="text" name="Address2" value="<?php echo "$Address2" ?>" /></td> </tr> <tr align="center" valign="top"> <td> </td> <td><input type="text" name="Address3" value="<?php echo "$Address3" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Gender:</td> <td><input type="text" name="Gender" value="<?php echo "$Gender" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Country:</td> <td><input type="text" name="Country" value="<?php echo "$Country" ?>" /></td> </tr> <tr align="center" valign="top"> <td>MobileNumber:</td> <td><input type="text" name="MobileNumber" value="<?php echo "$MobileNumber" ?>" /></td> </tr> <tr align="center" valign="top"> <td>Email Address:</td> <td><input type="text" name="EmailAddress" value="<?php echo "$EmailAddress" ?>" /></td> </tr> </table> <input type="submit" value="Update" /> </form> <form method="post" action="update_a_user_form.php"> <input type="submit" value="Update a Different Record" /> </form> <form method="post" action="display_users.php"> <input type="submit" value="List all users" /> </form> <form method="post" action="index.php"> <input type="submit" value="Administrator Interface" /> </form> </td></tr></table> <?php ++$i; } ?> <?php } else { echo 'Username not found!. Please try again'; ?> <table width="300" cellpadding="5" cellspacing="0" border="2"> <tr align="center" valign="top"> <td align="left" colspan="1" rowspan="1" bgcolor="#64b1ff"> <h3>Insert Username</h3> <form method="post" action="update_a_user_form2.php"> Enter Username: <input type="text" name="Username" size="30" /><br /> <br /> <input type="submit" value="Submit" /><input type="reset" /> </form> <form method="post" action="index.php"> <input type="submit" value="Administrator Interface" /> </form> </td> </tr> </table> <?php } ?> </div> </body> </html> It will display what it's meant to display if I have a username that is in the database, however if the username doesn't exist in the database, it's meant to say "Username not found!. Please try again" and show the search box again. However if I put in a Username that doesn't exist. I get a blank page (well at the top of the page the page I do get Hello Howlin1 Logout) What am I doing wrong? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=350701.0 How do I fix this For Each statement when used with preg match? //Cat_ID & Category Name preg_match_all('%<a[^href=]*href=\"\/cats\.asp\?cat_id=(.*?)\" title="(.*?)">%',$data,$matches1,PREG_SET_ORDER); // works fine preg_match_all('%/60/(.*?).jpg"%s',$data,$matches2,PREG_SET_ORDER); // works fine preg_match_all('%h3><p>(.*?)<\/p>%s',$data,$matches3,PREG_SET_ORDER); // works fine foreach ($matches1 as $val) { //need help here $subcat_id=$val[0][1]; $subcat=$val[0][2]; $cat_image=$val[1][1]; $cat_desc=$val[2][1]; Thanks for your help!!! I have got a set of data for a country for each week of the year, but want to display the data a quarter at a time, using a form which posts a value into LIMIT, which was OK for the 1st quarter, but for subsequent quarters I needed to use LIMIT in the form LIMIT start, rows.
I found by experiment that this had to be the last statement in the query.
when I added the start I got an error:
Parse error: syntax error, unexpected ',' in /homepages/43/d344817611/htdocs/Admin/Visitdata.php on line 10
Here is the SQL part of my code:
$Visit_data="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country=Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.Country = '".$_POST["Country"]."' ORDER BY ctryvisits.WNo LIMIT '".$_POST["QUARTER"]."'" - 13, '".$_POST["QUARTER"]."'";Is this the best way of doing what I require or is there an easier way of achieving what I want? Hi everybody i am beginnet with working with sql in php..so i confused.....i made one scripte and i am making the secound and now i am facing a problem....i hope u could help!! i have a dat=abse of my chatroom....this is the code i typed...please have a look at it! Code: [Select] $usern=$_SESSION['etchat_'.$this->_prefix.'username']; $con1 = mysql_connect("localhost","manosir_main","********"); if (!$con1) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manosir_manoshos_main", $con1); $users= mysql_query(" select etchat_user_online_user_sex from db1_etchat_useronline where etchat_user_online_user_name = $usern "); in my database, i ahve a table called db1_etchat_useronline that keeps record of online users in chatroom. as u usee i qant to to get the user sex ( etchat_user_online_user_sex) of th current user!!! as u see i conected to database correctly but now i dont know how to echo the $users . before this i echo my sql results with mysql_fetch_array ..but now i cant.......i got nothing!!!! can someone help me!!!!! |