PHP - While Loop Shows Blank Screen
Ok, the sql seems to be working fine, but when I go into the while loop, it gives me an internal error 500 and doesn't load anything. It just shows me a blank white screen:
Code: [Select] $sql = "SELECT alertID,alertName,alertMessage,activateSubj,activateBody,deactivateSubj,deactivateBody FROM alerts ORDER BY alertName"; $result = mysqli_query($cxn, $sql) or die(mysqli_error()); while ($row = mysqli_fetch_assoc($result)) { $alertID = $row['alertID']; $alertName = stripcslashes($row['alertName']); $alertMessage = stripcslashes($row['alertMessage'])); $activateSubj = stripcslashes($row['activateSubj'])); $activateBody = stripcslashes($row['activateBody'])); $deactivateSubj = stripcslashes($row['deactivateSubj'])); $deactivateBody = stripcslashes($row['deactivateBody'])); <div class="alert" style="border:1px solid #000;border-radius:5px;padding:12px;"> echo $alertID."<br />"; echo $alertName."<br />"; echo $alertMessage."<br />"; echo $activateSubj."<br />"; echo $activateBody."<br />"; echo $deactivateSubj."<br />"; echo $deactivateBody."<br />"; </div> } Similar Tutorials
<?php Hello and ty all for helping I have located the problem its in login.php file but dont know where thats why am turning to experts of coding. My file is located here ftp.sofo.si username and password are same "guest" pls feel free to download and inspect Thank you again for any help cheers Friends, I developed a script in php & i tested the script before encoding & its working fine. After i encoded the script through ionCube PHP Encoder & uploaded in my server but the file shows only blank page. Its not executing after encoding. What is the problem ?? How to fix it ? I have quite a lengthy php code that is bringing up the blank screen of death. I've put error_reporting(E_ALL) at the top but nothing. I can't see obvious errors while looking through the code and can't print it here as it's very long and uses a few include files. How else can I see what errors are occuring? Good morning all! I'm running this function, but for some reason, it's throwing up a blank white screen. I have no idea why. The "echo $query" doesn't return anything, but those fields are all in the table I'm pulling from, so I don't understand what's going on. Any help would be appreciated! Thanks! function attacks() { $query = doquery("SELECT id, name FROM `attacks` ORDER BY name", "attacks"); echo $query; $page = "<b><u>Edit attacks</u></b><br />Click on a attack name to edit it.<br /><br /><table width=\"50%\">\n"; $count = 1; while ($row = mysql_fetch_array($query)) { if ($count == 1) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin_panel.php?do=editattack:".$row["id"]."\">".$row["name"]."</a></td></tr>\n"; $count = 2; } else { $page .= "<tr><td width=\"8%\" style=\"background-color: #ffffff;\">".$row["id"]."</td><td style=\"background-color: #ffffff;\"><a href=\"admin_panel.php?do=editattack:".$row["id"]."\">".$row["name"]."</a></td></tr>\n"; $count = 1; } } if (mysql_num_rows($query) == 0) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No attacks found.</td></tr>\n"; } $page .= "</table>"; admindisplay($page, "Edit attacks"); } so im working on building a forum and i got everything on it but when you go to add a reply to the topic and click the reply button it will just go to a blank screen Not sure why its doing this, never had this problem. heres the code with the button Code: [Select] <?php require("top.php"); if ($username && ($_GET['cid'] == "")) { header("Location: home.php"); exit(); } $cid = $_GET['cid']; $tid = $_GET['tid']; ?> <div id='homepageright'> <form action="post_reply_parse.php" method="post"> <p>Reply Comment</p> <textarea name="reply_content" rows="5" cols="75"></textarea> <br /><br /> <input type="hidden" name="cid" value="<?php echo $cid; ?>" /> <input type="hidden" name="tid" value="<?php echo $tid; ?>" /> <input type="submit" name="reply_submit" value="Reply" /> <div id='homepageleft'> </div> </div> </html> </body> and code the button goes to Code: [Select] <?php if($username){ header("Location: index.php"); } if(isset($_POST['reply_submit'])){ include_once("scripts/connect.php"); $creator = $_SESSION['uid']; $cid = $_POST['cid']; $tid = $_POST['tid']; $reply_content = $_POST['reply_content']; $sql = "INSERT INTO post (category_id, topic_id, post_creator, post_content, post_date) VALUES ('".$cid."', '".$tid."', '".$creator."', '".$reply_content."', now())"; $res = mysql_query($sql) or die(mysql_error()); $sql2 = "UPDATE categories SET last_post_date=now(). last_user_posted='".$creator."' WHERE id='".$cid."' LIMIT 1"; $res2 = mysql_query($sql2) or die(mysql_error()); $sql3 = "UPDATE topics SET topic_reply_date=now(), topic_last_user'".$creator."' WHERE id='".$tid."' LIMIT 1"; $res3 = mysql_query($sql3) or die(mysql_error()); //email sending if(($res) && ($res2) && ($res3)) { echo "Your Reply Has Been Posted"; } else{ echo "There Was A Problem Posting Your Reply"; } } ?> Okay, I can't seem to figure out why the form isn't pulling up. Here's what I'm trying to do. Administrator clicks on Add New Item to Inventory, pulling up the shops that are available to add inventory to. (This part appears to be working, because it does list those shops available). Then, the administrator will click on a shop name, opening up a form that will allow them to type in the name of the item they want to add. Instead, it goes to a blank screen, no errors even with error reporting on. adminpanel.php is the main file that houses all these functions. If you're familiar with EZRPG, it's the same basic setup, just with these additions to the list. Any help would be greatly appreciated! Thank you!! function addinv() { $query = doquery("SELECT id,name FROM shop ORDER BY name", "shop"); $page = "<b><u>Add Inventory</u></b><br />Click to add an item to a shop's inventory.<br /><br /><table width=\"50%\">\n"; $count = 1; while ($row = mysql_fetch_array($query)) { if ($count == 1) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin_panel.php?do=addshopinv:".$row["id"]."\">".$row["name"]."</a></td></tr>\n"; $count = 2; } else { $page .= "<tr><td width=\"8%\" style=\"background-color: #ffffff;\">".$row["id"]."</td><td style=\"background-color: #ffffff;\"><a href=\"admin_panel.php?do=addshopinv:".$row["id"]."\">".$row["name"]."</a></td></tr>\n"; $count = 1; } } if (mysql_num_rows($query) == 0) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No items found.</td></tr>\n"; } $page .= "</table>"; admindisplay($page, "Add Shop Inventory"); } function addshopinv($name) { if (isset($_POST["submit"])) { extract($_POST); $errors = 0; $errorlist = ""; if ($name == "") { $errors++; $errorlist .= "Name is required.<br />"; } else if ($errors == 0) { $query1 = doquery("SELECT * FROM items WHERE name=$name"); $item_id = mysql_fetch_array($query1); $query = doquery("INSERT INTO `sale` SET shop_id=".$row["id"].", item_id='$item_id',"); admindisplay("Inventory Item Added.","Add New Inventory Item"); } else { admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.", "Add New Item to Shop"); } } $name = $page = <<<END <b><u>Add New Inventory Item</u></b><br /><br /> <form action="admin_panel.php?do=addshopinv:$name" method="post"> <table width="90%"> <tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="255" value="" />*255 character max</td></tr> </table> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> END; $page = parsetemplate($page, $row); admindisplay($page, "Add New Inventory Item"); } I have a database where I have 2 departments, and I want it to not show if they are both taken, but I'm not sure how to do this? Currently I have Code: [Select] $type_sql2 = mssql_query("SELECT * FROM Database2 Where SaleID ='$salesid'"); while($RS2 = mssql_fetch_assoc($type_sql2)) { $used_dist = $RS2['DistID']; $type_sql = mssql_query("SELECT * FROM Database Where Disable = 0 AND DeptID!= '$used_dist'"); while($RS = mssql_fetch_assoc($type_sql)) { $DeptID_ID = $RS['DeptID']; $DeptID_Name = $RS['DeptDescription']; echo "<option value=\"$DeptID_ID\">$DeptID_Name</option>\n"; } }And my DeptID is SE and CM, now in another database where these are used, I want this to not show them if they are both used and only show the one not being used any other time, but I can't just do it one at a time, because I may have more departments later on, but right now, with the above, if one is used, then it works, because only one shows up, but if both are used, it shows both still because it then sees SE and puts in CM, then loops thru again and sees CM and puts in SE then the second time. I hope this makes sence. But how do I not show either if both are used, and if one is used then only show the other? Thanks Hey.
So the issue I'm having is consecutive loops on semi-large arrays, over and over. Consider this array:
$firstArray = array( 'row1' => array( 'dates' => array( '2014-01-01' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-02' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-03' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-04' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-05' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-06' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-07' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), ) ), 'row2' => array( 'dates' => array( '2014-02-01' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-02' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-03' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-04' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-05' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-06' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-07' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-08' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-09' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), ) ) );Originally the data comes from ~2-3 database tables, of course. But to ilustrate the point, this is how the main array looks like. This array usually contains anywhere between 10-50 rows, each row containing at least 10 dates, with 10 key/values each. And after setting up all the data, it needs to be processed. Currently this is how a friend of mine did it.. $placeDataHere = array(); foreach($firstArray as $key => $dates) { foreach($dates as $date => $values) { foreach($values as $key => $value) { $placeDataHere['DV_' . $date]['SM_' . $key] = 'KS_' . $value; //Followed by another ~50-70 lines of processing the 3 loop's data.. ... ... .... .... .... .... .... .... } } }Obviously this isn't good practise, but we can't seem to figure out a better way of doing it, since both the data and the loops are horribly nested. This loop and setup of $firstArray is run anywhere between 10-20 times/request, due to amount of users we wish to process. So, the result is that this code can take up to over 2-3 minutes to complete, which isn't really optimal performance. In short my question is, are there any better methods of handling this with the data setup we currently have? Below is my output on the browser: Student: Kevin Smith (u0867587) Course: INFO101 - Bsc Information Communication Technology Course Mark 70 Grade Year: 3 Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B Session: AAB Session Mark: 72 Session Weight Contribution 20% Session: AAE Session Mark: 67 Session Weight Contribution 40% Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B Session: AAD Session Mark: 61 Session Weight Contribution 50% Now where it says course mark above it says 70. This is incorrect as it should be 65 (The average between the module marks percentage should be 65 in the example above) but for some stange reason I can get the answer 65. I have a variable called $courseMark and that does the calculation. Now if the $courseMark is echo outside the where loop, then it will equal 65 but if it is put in while loop where I want the variable to be displayed, then it adds up to 70. Why does it do this. Below is the code: Code: [Select] $sessionMark = 0; $sessionWeight = 0; $courseMark = 0; $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)) { $sessionMark += round($row['Mark'] / 100 * $row['SessionWeight']); $sessionWeight += ($row['SessionWeight']); $courseMark = ($sessionMark / $sessionWeight * 100); if($studentId != $row['StudentUsername']) { //Student has changed $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n"; } if($courseId != $row['CourseId']) { //Course has changed $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong>" round($courseMark) "<strong>Grade</strong> <br><strong>Year:</strong> {$row['Year']}</p>\n"; } if($moduleId != $row['ModuleId']) { //Module has changed if(isset($sessionsAry)) //Don't run function for first record { //Get output for last module and sessions $output .= outputModule($moduleId, $moduleName, $sessionsAry); } //Reset sessions data array and Set values for new module $sessionsAry = array(); $moduleId = $row['ModuleId']; $moduleName = $row['ModuleName']; } //Add session data to array for current module $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']); } //Get output for last module $output .= outputModule($moduleId, $moduleName, $sessionsAry); //Display the output echo $output; I think the problem is that it is outputting the answer of the calculation only for the first session mark. How in the while loop can I do it so it doesn't display it for the first mark only but for all the session marks so that it ends up showing the correct answer 65 and not 72? Hi I have deleted quite lot data from mysql database however, php still shows that page but blank ie page.php?id=186 - this id and all assosiated fields with this id has been removed from mysql but id still showing on the net and google cached all of them ( 600 pages) . page.php is still in use but I was wondering if there is any way not to show these blank pages/ids from mysql db and more importantly how can I remove these blank pages from google? Thanks for your help. I'm a bit stumped here and as usual I'm sure it's something simple. I have an object that checks if a user is an admin. It works fine. But it the HTML below it is not getting displayed. Take a look. welcome.php session_start(); $user = new users(); if (!isset($_SESSION['username'], $_SESSION['imadmin']) || $user->is_admin($_SESSION['username'])==0) { header('Location: index.php'); } welcome.php is getting displayed without getting redirected to the index. But there's no HTML, just the URL to welcome.php in the bar. Anyone? Cheers! I try to adjust my date and time to ("M-d-Y h:i:s A"), but when I do, I get 0's for the both the date and time. Code: [Select] <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>Test Sign Guestbook </strong></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email" size="40" /></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td> </tr> </table> Code: [Select] <?php $mysql_host = "myhost"; $mysql_database = "guest"; $mysql_user = "myusername"; $mysql_password = "mypassword"; //$db_name="guest"; This is not needed, as db_name is $mysql_database above, so please delete this line. $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $name = $_POST['name']; $email = $_POST['email']; $comment = $_POST['comment']; $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name (name, email, comment, datetime) VALUES ('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result){ echo "Successful"; echo "<BR>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); ?> Code: [Select] <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td> </tr> </table> <br> <?php $mysql_host = "myhost"; $mysql_database = "guest"; $mysql_user = "myusername"; $mysql_password = "mypassword"; $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td>ID</td> <td>:</td> <td><? echo $rows['id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><? echo $rows['name']; ?></td> </tr> <tr> <td>Email</td> <td>:</td> <td><? echo $rows['email']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><? echo nl2br($rows['comment']); ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><? echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <? } mysql_close(); //close database ?> Hey all. I have a simple code for verifying some data. I have two echos from if statements. The first is if the text input is empty echo: HELLO. The second is if text input data is not found in database echo: NOPE. Now in the following code the second one works fine. But the problem is if I leave the field empty BOTH echos show. So if I leave the input empty instead of saying "HELLO" it says, "HELLONOPE". Yet the second one works fine and display only "NOPE" The other thing is if I switch the two echos to die instead, they work fine. Code: [Select] if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['id']) { echo "HELLO"; } // checks it against the database $check = mysql_query("SELECT * FROM emp WHERE id = '".$_POST['id']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "NOPE"; } else { //if login good then redirect them to the members area $id = $_POST['id']; header("Location: somepage.php?id=$id"); } } else { // they are not logged in } <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <input type="text" name="id" maxlength="40"> <input type="submit" name="submit" value="Login"> </form> What am I doing wrong? I set up the following code to successfully individual items based on the id number. ?id=1 etc. However, I thought it would be simple to change to show another row so I changed all the terms to 'description'. However, if I enter ?description=abcde it shows nothing. But if I type in ?description=description is bizarrely shows everything. The only thing I can only put it down to is numbers. Does $_GET react differently react differently to numbers or does it require commas surrounding the string? <?php if( isset($_GET['description'])) $_GET['description']; $query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10"; $fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>'); while($row = mysql_fetch_array($fetchdata)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image'/></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } ?> Hey guys, Got another question im hoping someone can help me with. I have a foreach loop (for use in a mysql query): foreach ($interests as $interest) { $query .= "($id, $interest), "; } problem is i do not want the comma(,) in the last loop. Is there some kinda of function i can use so it does not insert it on last loop? Or should i just use a for loop with a nested if loop? something like ; for($i=0; $i < count($interests); $i++){ $query .= "($id, '$interests[$i]')"; if($i + 1 < count($interests)) { $query .= ", "; } } Cheers guys I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners Need help with some whiles, etc., and .php page refreshes. $num; Comes from mysql_num_rows from a database table's regular 'select'. And gets the row id numbers for every row that the id numbers are listed in order. $totalrows comes from another select but is select * instead. And pulls the total rows in the whole table instead there are 49 rows in the whole table. I'm trying to get the page to show 5 table rows at a time like the following, but then when the page is still open on next page refresh to show the next 5 rows and continue that way. This following: Quote PHP Code: <?php $i=$num; if ($num == 5); {echo "The number is " . $num . "<br />";} do {$i = $i + 5; echo "The number is " . $i . "<br />"; } while ($i<$totalrows); ?> Brings up these results: The row number is 10 The row number is 15 The row number is 20 The row number is 25 The row number is 30 The row number is 35 The row number is 40 The row number is 45 The row number is 50 Shows all these on the page at the same time. I'm trying to get these to only show the 5 rows after every page refresh instead. Please let me know how to do that, and whether it can be done without any cookies. I don't know if there is a better way to show the first 5 separate like I have it. Thank you very much for your help. I know they do, because I tested with.
die($HASH_Pass);
And it returned the same password as the password stored with the username associated in the database.
<?php /* <p class="required">All fields are required</p><br/> <form method="post" action="Scripts/UserFunctions/login.php"> <label for="username">Username:</label><input type="text" name="username" id="username" size="40px"><br/> <label for="password">Password:</label> <input type="password" name="password" id="password" size="40px"><br/> <input type="submit" name="submit" value="Login"> </form> */ if(isset($_POST['submit'])){ //set default variables $msg = ""; $error = false; //set variables from user input $Username = $_POST['username']; $Password = $_POST['password']; $HASH_Pass = hash("sha512", $Password); //include connection require_once("../DB/connect.php"); //create quarries to get data $Query = $connect->prepare("SELECT * FROM Users WHERE Username = :hhh AND Password = :jjj"); $Query->bindValue(':hhh', $Username); $Query->bindValue(':jjj', $HASH_Pass); $Query->execute() or die("Not executed"); $ROWS = $Query->fetch(PDO::FETCH_NUM); if($ROWS != 0){ $_SESSION['Logged_in']=$Username; header("Location: http://www.family-line.dx.am/Community/profile.php?user=$Username"); exit(); } else { $msg .= "Username and Password do not match. Try again"; $error = true; } if($error){ $Self = $_SERVER['PHP_SELF']; echo <<<form <div style="background: #efefef;"> <h2 style="color: red; font-weight: 850;">{$msg}</h2> <p class="required">All fields are required</p><br/> <form method="post" action="{$Self}"> <label for="username">Username:</label><input type="text" name="username" id="username" size="40px"><br/> <label for="password">Password:</label> <input type="password" name="password" id="password" size="40px"><br/> <input type="submit" name="submit" value="Login"> </form> </div> form; } } ?>Spelled Queries wrong…sorry I'm using PDO (obviously), but is there anything that would cause this error? I've made a working Login script, but I never used bindValue()... I'm new here. But I'm pretty sure it's not the SQL's issue, because it never displayed the or die(...) Not sure if this helps but the script is here... http://family-line.d....php?page=login Username: Test Password: Test Edited by Masonh928, 11 January 2015 - 06:55 PM. Folks,
What is wrong with the block text with the label "Description" ? All html after or below it in the file shows-up inside the block-text box when you check the page in the browser! <form name "link_submission_form" method = "post" action="" enctype = "multipart/form-data"> <div class="form-group"> <p align="left"><label>Url:</label> <select> <option value="<?php echo "$primary_domain";?>"><?php echo "$primary_domain";?></option> </select> <input type="url" placeholder="<?php echo '/directory/page.html';?>" name="primary_website_url" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['primary_website_url'])) { echo htmlentities($_POST['primary_website_url']); }?>"> <label>; Anchor Text:</label> <input type="text" placeholder="Enter Link Text" name="anchor_text" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['anchor_text'])) { echo htmlentities($_POST['anchor_text']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Page Title:</label> <input type="text" placeholder="Enter Page Title" name="page_title" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['page_title'])) { echo htmlentities($_POST['page_title']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Page Description:</label> <textarea rows="10" cols="100" placeholder="Page Description" name="page description" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['page_description'])) { echo htmlentities($_POST['page_description']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Primary Website Email (To receive Visitor Entry Alerts):</label> <input type="text" placeholder="Email to receive Visitor Entry Notice" name="primary_website_email_for_visitor_entry_notice" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['primary_website_email_for_visitor_entry_notice'])) { echo htmlentities($_POST['primary_website_email_for_visitor_entry_notice']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Repeat Primary Website Email (To receive Visitor Entry Alerts):</label> <input type="text" placeholder="Repeat Email to receive Visitor Entry Notice" name="primary_website_email_confirmation_for_visitor_entry_notice" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['primary_website_email_confirmation_for_visitor_entry_notice'])) { echo htmlentities($_POST['primary_website_email_confirmation_for_visitor_entry_notice']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Primary Website Email (To receive Visitor Exit Alerts):</label> <input type="text" placeholder="Email to receive Visitor Exit notice" name="primary_website_email_for_visitor_exit_notice" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['primary_website_email_for_visitor_exit_notice'])) { echo htmlentities($_POST['primary_website_email_for_visitor_exit_notice']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Repeat Primary Website Email (To receive Visitor Exit Alerts):</label> <input type="text" placeholder="Repeat Email to receive Visitor Exit notice" name="primary_website_email_confirmation_for_visitor_exit_notice" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['primary_website_email_confirmation_for_visitor_exit_notice'])) { echo htmlentities($_POST['primary_website_email_confirmation_for_visitor_exit_notice']); }?>"> </p> </div> <div class="form-group"> <p align="left"><label>Agree To Our Terms & Conditions ? :</label> <input type="radio" name="fb_tos_agreement_reply" value="Yes" <?php if(isset($_POST['fb_tos_agreement_reply'])) { echo 'checked'; }?> required>Yes <input type="radio" name="fb_tos_agreement_reply" value="No" <?php if(isset($_POST['fb_tos_agreement_reply'])) { echo 'checked'; }?> required>No </p> </div> <p align="left"><input type="submit" class="btn btn-default" name="submit" value="Submit"></p> <p align="left"><input type="reset" class="btn btn-default" name="reset" value="Reset"></p> </form> Notice each input field's requirement. Have I got any wrong ? Example: <input type="text" placeholder="Enter Link Text" name="anchor_text" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['anchor_text'])) { echo htmlentities($_POST['anchor_text']); }?>"> |