PHP - I Cant Figure Out How To Use This One Function??
Ok, so there are two functions, one encrypts data, the other one must decrypt. But I do not know how to implement it to decrypt.
I need to know how to use the second function (number_decrypt). I need it so I enter the encrypted string into a text field and it outputs the decypted string. I dont need the html, I just dont understand how to implement it. Can someone look at this for me and possibly tell me how I could achieve this? Heres the code: function number_encrypt($plain) { mt_srand ((double) microtime() * 1000000); $password = ''; for ($i=0; $i<10; $i++) { $password .= rand(1,1000); } $salt = substr(md5($password), 0, 2); $password = md5($salt . $plain) . ':' . $salt; return $password; } function number_decrypt($encrypted,$plain) { $stack = explode(':', $encrypted); if (sizeof($stack) != 2) return false; if (md5($stack[1] . $plain) == $stack[0]) { return true; } return false; } Thanks! Similar TutorialsI've tried a few different methods, but I can't get this damn function to work. Can someone show me where I've gone wrong? Here's my code & form. I'm still baffled why it doesn't work! :lol: url is update-content.php?id=12 <?php include("../include/session.php"); if(!$session->logged_in) { header('Location: ../login.php'); die; } require_once('../include/functions.php'); function content($id) { $id = $_GET['id']; $connection = db_connect(); $query = sprintf("select * from content where id = '$id'", mysql_real_escape_string($id) ); $result = mysql_query($query); $number_of_posts = mysql_num_rows($result); if ($number_of_posts == 0) { return false; } $row = mysql_fetch_array($result); return $row; } function update($param) { // Get the content id from url to output into the editor $id = $_GET['id']; $connect = db_connect(); $page = mysql_real_escape_string($_POST['page']); $page_id = mysql_real_escape_string($_POST['page_id']); $title = mysql_real_escape_string($_POST['title']); $text = mysql_real_escape_string($_POST['text']); $query = ("UPDATE content SET page = '$page' page_id = '$page_id' title = '$title' text = '$text' WHERE id = '$id' "); $result = mysql_query($query); if (!$result) { return false; } else { return true; } } ?> <?php // Send form data to mysql if(isset($_POST['text'])) { $result = update($_POST); if($result === true) { echo 'Success!'; die(); } } ?> And the form.. <form form name="editor" id="editor" method="post" action="update-content.php"> <p><br /> <b>Assign to page</b><br /> <input name="page" id="page" size="60" maxlength="500" value="<?php $page = content($id); echo stripslashes($page['page']); ?>" /> <br /> <br /> <b>Page id</b> <input name="page_id" id="page_id" size="4" maxlength="4" value="<?php $page_id = content($id); echo stripslashes($page_id['page_id']); ?>" /> <br /> <br /> <b>Title</b> <span class="smalltext">(Just a short name this piece of content)</span><br /> <input name="title" id="title" size="60" maxlength="200" value="<?php $title = content($id); echo stripslashes($title['title']); ?>" /> <br /> <br /> <br /> <strong>Content</strong> <span class="smalltext">(paste html in here)</span><br /> <textarea name="text" id="text" cols="75" rows="15"><?php $text = content($id); echo stripslashes($text['text']); ?></textarea> <?php //turn the text area into CK Editor echo $ckeditor_ini; ?> <br /> <input type="image" src="../images/button_submit.gif" alt="submit" name="submit" value="submit" /> <a href="index.php"><img src="../images/button_cancel.gif" alt="Cancel" width="120" height="26" border="0" /> </form> The page that I'm working on is a quiz results page. In this section of code I am simply printing the question, then each answer choice is printed depending on a few if statements. Let's say the answer choice in this first statement was "Baseball." The four possibilities depending on the student answer I want a Baseball - You Got This Right or Baseball - Correct Answer or Baseball - Your Answer or Baseball So if the student gets a question wrong one choice should say "Correct Answer" next to it and one other would have "Your Answer" next to it. Pretty simple and straightforward. I can get the correct results from everything but the second ifelse statement (Baseball - Your Answer). No matter what i do I can't get this to work. Here is the code below and some clarifications: $StudAns = Student's answer $Choices = The particular answer choice being evaluated $CorrectAnswer = obvious Code: [Select] $StudAns = array($QChoices['Q1Choice'], $QChoices['Q2Choice'], $QChoices['Q3Choice']); $ContentsQuery = mysql_query("SELECT Question, Choice1, Choice2, Choice3, Correct_Answer FROM Module_1_Quiz") or die(mysql_error()); while ($Contents = mysql_fetch_array($ContentsQuery)) { $i =0; $Choices = array($Contents['Choice1'], $Contents['Choice2'], $Contents['Choice3']); $CorrectAnswer = $Contents['Correct_Answer']; echo "<span id='answers'><table width = '600' border='0' align='center' id='answers' bgcolor='#FFFFCC'><tr><td>"; echo $Contents['Question']; echo "</td></tr>"; echo "<tr><td><ol type = 'a'><li>"; // Checks what should be printed for the first answer option if ($Choices[$i] == $CorrectAnswer && $StudAns[$i] == $CorrectAnswer) { echo $Choices[$i]; echo " - You Got This Right!"; } elseif ($Choices[$i] == $CorrectAnswer && $StudAns[$i] != $CorrectAnswer) { echo $Choices[$i]; echo " - Correct Answer"; } elseif ($StudAns[$i] != $CorrectAnswer && $CorrectAnswer[$i] != $Choices[$i]) { echo $Choices[$i]; echo " - Your answer"; } else { echo $Choices[$i]; } echo "</li><li>"; $i++; // Checks what should be printed for the second answer option if ($Choices[$i] == $CorrectAnswer && $StudAns[$i] == $CorrectAnswer) { echo $Choices[$i]; echo " - You Got This Right!"; } elseif ($Choices[$i] == $CorrectAnswer && $StudAns[$i] != $CorrectAnswer) { echo $Choices[$i]; echo " - Correct Answer"; } elseif ($StudAns[$i] != $CorrectAnswer && $CorrectAnswer[$i] != $Choices[$i]) { echo $Choices[$i]; echo " - Your answer"; } else { echo $Choices[$i]; } echo "</li><li>"; $i++; // Checks what should be printed for the third answer option if ($Choices[$i] == $CorrectAnswer && $StudAns[$i] == $CorrectAnswer) { echo $Choices[$i]; echo " - You Got This Right!"; } elseif ($Choices[$i] == $CorrectAnswer && $StudAns[$i] != $CorrectAnswer) { echo $Choices[$i]; echo " - Correct Answer"; } elseif ($StudAns[$i] != $CorrectAnswer && $CorrectAnswer[$i] != $Choices[$i]) { echo $Choices[$i]; echo " - Your answer"; } else { echo $Choices[$i]; } echo "</li></ol></table></span>"; } Thanks everyone! hey all; i created a script that just allows a user to record an IP address and it presents them in a table.. issue: each record draws its own row and a colum for an image (for deleting).. I can't igure out how I can delete the one row when they click on image(little x) to delete... issue2: it's showing the error message when you bring up the screen telling them they didn't enter anything even prior to them hitting submit... issue3: it's allowing me to enter the same IP again code: <?php session_start(); if (!isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href='index.php'>GO BACK</a> and try again"; exit(); } else { if ($_SESSION['username']) { $username = $_SESSION['username']; $userid = $_SESSION['userid']; } } //script v1.0 ipdatabase.php - create a list of IP addresses that the user has added to their list to remember. can add or remove IPs ?> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> <table align="center" width="550" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td height="106" colspan="3" valign="top"><img src="images/myvpc.png" width="550" height="106"></td> </tr> <tr> <td width="16" height="57"> </td> <td width="516" valign="top"><div align="center" class="style1"> <p>IP DATABASE</p> <p align="left">add or remove IP address you have encountered in the game thus far for later use!</p> </div></td> <td width="18"> </td> </tr> <tr> <td height="100"> </td> <td valign="top"> <form action="ipaddressadd.php" method="POST"> <p> </p> <p><span class="style1">IP ADDRESS</span>: <input type="text" name="ipaddress" size="16"> <input type="submit" name="submit" value="submit"> </p> </form></td> <td> </td> </tr> <tr> <td height="17"></td> <td valign="top"><img src="images/filler.jpg" width="516" height="19"></td> <td></td> </tr> <tr> <td height="296"></td> <td valign="top"> <?php $submit = $_POST['submit']; if ($submit) { $ipaddress = ip2long($_POST['ipaddress']); } //script to add IP to database include('connectdb.php'); mysql_select_db('heaven_users') or die (mysql_error()); if (isset($ipaddress,$submit)) { mysql_query("INSERT INTO ipdatabase (userid,ipaddress) VALUE ('$userid','$ipaddress')") or die ("Could Not write to database, Please try again"); } else echo "<center><font color='#ff0000'>You didn't add anything mate!</font></center>"; echo "<br />"; echo "<table align='center' border='1'><tr align='center'><th><font color='#ffffff'>SAVED IPADDRESS</font></th></tr><tr>"; $query = mysql_query("SELECT * FROM ipdatabase WHERE userid = '$userid'"); while ($result = mysql_fetch_assoc($query)) { $ip = long2ip($result['ipaddress']); echo "<tr align=\"center\"><td><font color='#ffffff'>".$ip."</font></td><td><a href='deleteip.php'><img border='0' src='images/delete.png'></a></td></tr>"; } echo "</table>"; ?> </td> <td></td> </tr> </table> guys is it possible to somehow compare something like these two together and make a choice depending on the out come SystemKeyv1.0 and PasswordCrackerv2.0 PasswordCrackerv2.0 is grater than SystemKeyv1.0 can these be compared somehow? thank for advise guys; Cheers Hi, good pm masters! So i have this code Code: [Select] <td><img src="images/layout/<?php echo base64_decode($_GET['layout']); ?>" width="50%" height="50%" /></td> $_GET['layout'] is encoded that's y i have a decode there, the image name will then be combined to the src like this -> image/layout/1.jpg.. when i view the source the src is correct but it doest show the image.. cant seem to find whats wrong.. my folder structure is sandbox>images>layout>file.jpg the php file (where the code above is) inside the sandbox. sorry if am i missing something sooo eaasy.. i was doin alot of coding this morning until now so i don't know what to think anymore.. i was wondering how i would go about making a single page that would have sections on it and if you click a section the page reloads and shows the information that is within that section? i got my code to show both the section and its information at the same time but cannot figure out how to do the above. please help. thank you -Adam I'm terrible at designing websites (that's pretty much out of the question), but I would like to work on my php skills. I just can't figure out anything I can write that isn't extremely hard.. ideas? Okay, the function appears to work just fine, except it doesn't add to the database. I don't have any errors, so I'm not quite sure what is going on. I've got an echo on the $id and $item_id, and both were pulling correctly. Just not being added to the table `sale`... Anyone help? Thanks in advance! function addshopinv($id) { error_reporting(E_ALL); ini_set('display_errors', 1); if (isset($_POST["submit"])) { extract($_POST); $errors = 0; $errorlist = ""; if ($name == "") { $errors++; $errorlist .= "Name is required.<br />"; } else if ($errors == 0) { $dbh=dbconnect() or die ("Userlist read error: " . mysql_error()."<br>"); mysql_select_db("XXX"); $query = mysql_query("SELECT id FROM items WHERE name='$name'"); while ($result = mysql_fetch_array($query)){ $item_id = $result['id']; echo $id; $query1 = mysql_query("INSERT INTO sale SET shop_id='$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"); } } I am trying to redirect users depending on their coupon code input I am using the following script in the form created in dreamweaver: Code: [Select] <form action="CodeUserredirect.php" method="post" enctype="multipart/form-data" name="" id=""> <input type="hidden" name="redirect" value="CodeUserredirect.php" /> <p class="style4">Redeem your Gift Certificate Savings for Special Orders he </p> <p><span class="style78">Enter Coupon code</span> <input name="CouponCode" type="text" id="CouponCode" size="9"> <input type="submit" name="CheckCode" id="CheckCode" value="Check Code"> <br/> <br/> </p> </form> and I am using the following code in my php file: <?php$coupon_code = $_POST['couponcodenumber'];if ($coupon_code = $some_other_value) { $redirected_address = 'Location: specialordersDiscountForm.php'; header ($redirected_address); exit();} else { $redirected_address = 'Location: specialorderwrongcode.php'; header ($redirected_address); exit();}?> () Not sure where the issue is in these coding but it is not working to redirect users depending on their coupon input as intended. Can anyone supply me with a working code or explain what the issue is? thanks! i have an array called $imageArray like this Array ( [0] => 'Dashka'_Darren_Sheehan_1.jpg [1] => 'Dashka'_Darren_Sheehan_10.jpg [2] => 'Dashka'_Darren_Sheehan_2.jpg [3] => 'Dashka'_Darren_Sheehan_3.jpg [4] => 'Dashka'_Darren_Sheehan_4.jpg [5] => 'Dashka'_Darren_Sheehan_5.jpg [6] => 'Dashka'_Darren_Sheehan_6.jpg [7] => 'Dashka'_Darren_Sheehan_7.jpg [8] => 'Dashka'_Darren_Sheehan_8.jpg [9] => 'Dashka'_Darren_Sheehan_9.jpg [10] => . [11] => .. [12] => Aaron_Kidney_1.jpg [13] => Aaron_Kidney_10.jpg [14] => Aaron_Kidney_11.jpg [15] => Aaron_Kidney_12.jpg [16] => Aaron_Kidney_13.jpg [17] => Aaron_Kidney_14.jpg [18] => Aaron_Kidney_15.jpg [19] => Aaron_Kidney_16.jpg [20] => Aaron_Kidney_17.jpg [21] => Aaron_Kidney_18.jpg and i also have another array called $_names Array ( [0] => 'Dashka'_Darren_Sheehan [1] => Beefit_Gyms [2] => Aaron_Kidney [3] => Dean_Mitchell [4] => Colin_O_Neill [5] => Keith_McManus ) if a name in array $_names exists in the $imageArray i want to insert the images for that person into one column of a table like this <tr> <?php foreach ($names as $name): ?><th><?php htmlout($name); ?></th><?php endforeach; ?> </tr> <tr> <td><img src="../images/'Dashka'_Darren_Sheehan_1.jpg" width="204"/></td> <td><img src="../images/Aaron_Kidney_1.jpg" width="204"/></td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td><img src="../images/'Dashka'_Darren_Sheehan_2.jpg" width="204"/></td> <td><img src="../images/Aaron_Kidney_2.jpg" width="204"/></td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> can anyone help me write the logic for this?? I cant figure it out... Hi im still learning php and have been running through the tutorials on making a user authentication system but im getting an error on one line but ive got the same code else where and its fine... Code: [Select] // Must have at least one character if (strspn($_POST['user_name'],$span_str) == 0) { return false; } Im getting the error on the if statment but no matter what i try it still tells me theres an error... Heres the full function code: Code: [Select] function account_namevalid() { // parameter for use with strspan $span_str = "abcdefghijklmnopqrstuvwxyz" . "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; // Must have at least one character if (strspn($_POST['user_name'],$span_str) == 0) { return false; } // Must contain all legal characters if (strspn($_POST['user_name'],$span_str) != srnlen($name)) { return false; } // Min and Max length if ($strlen($_POST['user_name']) < 5) { return false; } if strlen($_POST['user_name']) > 25 { return false; } // Illegal names if (eregi("^((root)|(bin)|(deamon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)|(uucp)|(operator)|(games)|(mysql)| (httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download)))$", $_POST['user_name'])) { return false; } if (eregi("^(anoncvs_)", $_POST['user_name'])) { return false; } return true; } Any help or info would be greatfull... Cheers Chris hello all, i can't get this to work; i'm able to echo both accts entered into the form via the _get but can't pull both balances using the $from_acct and $to_acct only the first query working do I have it formated wrong <?php //check for submit $submit = $_GET['submit']; //end looking for submit //set varibles if submit is present if (!$submit) { echo "Sorry Mate I don't see you have submitted anything for me to process"; } else { //make the connecting and set some varibles from _get $from_acct = $_GET['from_acct']; $to_acct = $_GET['to_acct']; $amount = $_GET['amount']; $connect = mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db('users') or die ("no such database exisit"); $query = mysql_query("SELECT * from members WHERE bankaccount=$from_acct") or die ("Could not locate to account"); $query2 = mysql_query("SELECT * from members WHERE bankaccount=$to_acct") or die ("Could not locate to account"); while ($result = mysql_fetch_assoc($query) && $result2 = mysql_fetch_assoc($query2)) { $fromb = $result['balance']; $tob = $result2['balance']; } //make a check to see if the account that is sending has the money to send if ($fromb<$amount) { echo "Mate you don't have enough cash to transfer " .$amount. "to this account<br />"; echo "Your Current Balance available for transfer is " .$fromb; } else { $newbalancefrom = $fromb - $amount; $newbalanceto = $tob + $amount; //make the transfer $transfer = mysql_query("UPDATE 'users' . 'members' SET 'balance' = '$newblanceto' WHERE bankaccount='$to_acct'") or die ("could not write to profile"); $transfer2 = mysql_query("UPDATE 'users' . 'members' SET 'balance' = '$newblancefrom' WHERE bankaccount='$from_acct'") or die ("Could Not Write to From Account"); if ($transfer) { echo "Transfer Complete Thanks!"; } else { echo "There was a error in the transfer process please try again"; } } } echo $fromb . "<br />"; echo $tob . "<br />"; echo $from_acct . "<br />"; echo $to_acct . "<br />"; ?> <h2>Peer to Peer Transfer</h2><br><br> <form action="testtrans.php" method="get"> Amount to Transfer: <input type="text" size="8" name="amount"><br> From Account: <input type="text" size="15" name="from_acct"> To Account: <input type="text" size="15" name="to_acct" /><br /> <input type="submit" name="submit" value="transfer" /> </form> hello, newbie here. i am struggling with the way my table is displayed. as you can see if you goto http://durhamit.ca/citycore/2/tsreview.php and goto october 20th, Rui Zhang has 3 entries and im trying to make it display one at a time. here is my code if anyone can point me in the right direction. Code: [Select] <?php include 'config.php'; include 'javascript.php'; $d = date("d"); $m = date("m"); $y = date("Y"); ?> <center> <form method="POST"> Month: <select size="1" name="m"> <option selected="selected" value="<?php echo $m; ?>"><?php echo $m; ?></option> <?php $mlist = range( 1,12 ); foreach ($mlist as $v ) { echo "<option value=\"$v\">$v</option>\n"; } ?> </select> Day: <select size="1" name="d"> <option selected="selected" value="<?php echo $d; ?>"><?php echo $d; ?></option> <?php $dlist = range( 1,31 ); foreach( $dlist as $v ) { echo "<option value=\"$v\">$v</option>\n"; } ?> </select> Year: <select size="1" name="y"> <option selected="selected" value="<?php echo $y; ?>"><?php echo $y; ?></option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> </select> <input type="submit" value="View" name="view"> </form> <?php if(isset($_POST['view'])) { $y3=$_POST['y']; $m3=$_POST['m']; $d3=$_POST['d']; $pdate=$y3."-".$m3. "-".$d3; $pdate1 = date( 'D M j', strtotime($pdate) ); } else { $pdate = date('Y-m-d', strtotime("-1 day") ); $pdate1 = date( 'D M j', strtotime($pdate) ); } $pdate2 = date('Y-m-d', strtotime("-1 day, $pdate") ); $y4 = date('Y', strtotime("$pdate2") ); $m4 = date('m', strtotime("$pdate2") ); $d4 = date('d', strtotime("$pdate2") ); $pdate3 = date('Y-m-d', strtotime("+1 day, $pdate") ); $y5 = date('Y', strtotime("$pdate3") ); $m5 = date('m', strtotime("$pdate3") ); $d5 = date('d', strtotime("$pdate3") ); echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>"; echo "<tr>"; echo "<td width='100%' colspan='9' align='center'>"; ?> <table border='0' cellpadding='0' width='100%'> <tr> <td width='10%' align="center"> <form name="back" method="POST"> <input type="submit" value="<<<" name="view"> <input type="hidden" name="y" value="<?php echo "$y4"; ?>"> <input type="hidden" name="m" value="<?php echo "$m4"; ?>"> <input type="hidden" name="d" value="<?php echo "$d4"; ?>"> </form> </td> <td align="center"><b>Timesheets For <?php echo "$pdate1"; ?></b></td> <td width='10%' align="center"> <form name="forward" method="POST"> <input type="hidden" name="y" value="<?php echo "$y5"; ?>"> <input type="hidden" name="m" value="<?php echo "$m5"; ?>"> <input type="hidden" name="d" value="<?php echo "$d5"; ?>"> <input type="submit" value=">>>" name="view"> </form> </td> </tr> </table> <?php echo "</td>"; echo "</tr>"; $result5 = mysql_query("SELECT * FROM staff ORDER BY name"); while($row = mysql_fetch_array($result5)) { $eid=$row['eid']; $mname=$row['name']; $result3 = mysql_query("SELECT * FROM timesheet WHERE date = '$pdate' AND eid = '$eid'"); $talltime = 0; while($row3 = mysql_fetch_array($result3)) { $tid=$row3['id']; $tdate=$row3['date']; $tjobnumber=$row3['jobnumber']; $teid=$row3['eid']; $tdescription=$row3['description']; $tsignin=$row3['start']; $tfinish=$row3['finish']; $tlunch=$row3['lunch']; $tkms=$row3['kms']; $tschednum=$row3['schednum']; $tapproval=$row3['approval']; if("$tapproval" == "1") { $tapproval1="<font color='#00FF00'>In Progress</font>"; } if("$tapproval" == "2") { $tapproval1="<a target='_blank' href='approve.php?id=$tid'><font color='#FF0000'>Approve</font></a><br /> <a href='edittimesheet.php?id=" . $tschednum . "'>Edit</a>"; } if("$tapproval" == "3") { $tapproval1="Approved"; } $tdate1 = date( 'M j, Y', strtotime($tdate) ); $tsignin1 = date( 'g:i a', strtotime($tsignin) ); $tfinish1 = date( 'g:i a', strtotime($tfinish) ); if( empty($tfinish) ) { $tfinish2="<i>In Progress"; } else { $tfinish2="$tfinish1"; } $shortid=substr($tjobnumber, 5, -1); //remove the first 5 characters and minus the last character $result = mysql_query("SELECT * FROM jobs WHERE id = '$shortid'"); while($row = mysql_fetch_array($result)) { $jstatus=$row['status']; } $result4 = mysql_query("SELECT * FROM schedule WHERE id = '$tschednum'"); while($row4 = mysql_fetch_array($result4)) { $sid=$row4['id']; $sdate=$row4['date']; $seid=$row4['eid']; $sjobnumber=$row4['jobnumber']; $sstarttime=$row4['starttime']; $sstatus=$row4['status']; $setime=$row4['etime']; } $log_in_time_string = strtotime($tsignin); $log_out_time_string = strtotime($tfinish); $difference_in_seconds = ($log_out_time_string - $log_in_time_string); $tbilled = ($difference_in_seconds / 3600); if($tbilled < 0) { $tbilled1 = $tbilled + 24; } else { $tbilled1=$tbilled; } $tbilled2 = number_format(round($tbilled1*4)/4,2); $tbilled3 = $tbilled2 - $tlunch ; $talltime += $tbilled3; if ($talltime == '0' ) { echo "nothing"; } else { echo "<tr>"; echo "<td align='left' colspan='10'><b> " . $mname . "</b></td>"; echo "</tr>"; echo "<tr> <th align='center'>Date</th> <th align='center'>Job Number</th> <th align='center' width='30%'>Service Report</th> <th align='center'>Sign In Time</th> <th align='center'>Sign Out Time</th> <th align='center'>Lunch</th> <th align='center'>Time Billed</th> <th align='center'>Estimated</th> <th align='center'>Status</th> </tr>"; echo "<tr>"; echo "<td align='center'>" . $tdate1 . "</td>"; echo "<td align='center'>" . $tjobnumber . "</td>"; echo "<td align='center'>" . $tdescription . "</td>"; echo "<td align='center'>" . $tsignin1 . "</td>"; echo "<td align='center'>" . $tfinish2 . "</td>"; echo "<td align='center'>" . $tlunch . " hour</td>"; echo "<td align='center'>"; if ($tbilled3 > $setime ) { echo "<font color='red'><b>*** " . $tbilled3 . " hours ***</b></font>"; } else { echo "" . $tbilled3 . " hours"; } echo "</td>"; echo "<td align='center'>" . $setime . " hours</td>"; echo "<td align='center' nowrap>" . $tapproval1 . "</td>"; echo "</tr>"; } echo "<tr>"; echo "<td colspan='6' align='right'><b>Totals :</td>"; echo "<td align='center' colspan='3'>"; if ($talltime > "8" ) { echo "<font color='red'><b>*** " . $talltime . " hours ***</b></font>"; } elseif ($talltime < "0" ) { echo "<font color='red'><b>Still signed into a job</b></font>"; } else { echo "" . $talltime . " hours"; } echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='10' bgcolor='#D9FFD9'> </td>"; echo "</tr>"; } } echo "</table>"; include 'close.php'; ?> I get this 2 errors everytime i hit "Sign Up" in my registration form i'm creating for my new website: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in [php file location] on line 64 Deprecated: Function eregi() is deprecated in [php file location] on line 87 I have created a database in, MySQL with phpMyAdmin, named "membership" and a table named "users" with these fields: Field Type Collation Attributes Null Default Extra username varchar(20) latin1_swedish_ci No None first_name varchar(30) latin1_swedish_ci No None last_name varchar(30) latin1_swedish_ci No None password varchar(30) latin1_swedish_ci No None email varchar(50) latin1_swedish_ci No None gender text latin1_swedish_ci No None birth_day date No None This is the 2 parts of the php code where i get the 2 errors: public function user_exists() { mysql_connect("localhost","root","101Dalmatiner") or die(mysql_error()); mysql_select_db("membership") or die (mysql_error()); $data = mysql_query("SELECT ID FROM users WHERE username = '{$this->username}'"); return mysql_num_rows($data) > 0 ? 1 : 0; <---- the line where the first error appears } if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email)) $this->errors[] = 'Invalid Email'; There is all the neccesary informationg you'll need if your willing to look through it all and help my i think! I'm kinda new to php and MySQL so don't blame me if the code is messed up or something look really wrong, i'd appreciate any help i can get on this! So I'm sitting at my desk scratching my head on how to do a task where I pull information form a database (that i know how to do) but then i need to see if two variables equal a string and if they do count out how many times that two variables equal there two string checks and out put the counted number ? this is what I have thought of but dose not to work because I cant figure out a way to code it? $dbPull = mysql_fetch_array($result) if( $dbPull['Foo'] == 'string1' && $bdPull['Bar'] == 'string2') this is were I get lost I'm looking for (how many times in the DB dose String2 show up in the array were the above, IF statement is true ) any ideas would be most appreciated 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"); } I have a link echo '<p>View All Items listed for <a href="item.php?mem-items='.$mem_id.'">"'.$name.'"</a></p>'; That goes to a file http://localhost/folder/item.php?mem-items=26 with 26 being an actual member id number I use the GET function like this if (isset($_GET['mem-items']) && is_numeric($_GET['$mem-items'])) { $mem_items = $_GET['mem-items']; } My problem is $mem_items isn't assigned a variable, but when I take the "is_numeric($_GET['$mem-items'])" out, it works like a charm. I use this same format on the same file for "if (isset($_GET['item']) && is_numeric($_GET['item']))" AND it works great. Can anyone see what's wrong. Thanks I have a website that I have curled some data from and gotten the data I want. It is one large array. The variable is called $ten_pireps. For clarity I am only posting the first 8 keys=>value pairs. The array repeats the info every 8 keys. ending with key [79]. Array ( => ET20029 [1] => EAL391 [2] => ESKN [3] => EETN [4] => E35 [5] => 0.8 [6] => 284 [7] => 01/02/2011 I need to iterate through this 79 key array and place keys thru [7] into another variable array called $flightinfo1, keys [8] thru [15] into $flightinfo2, etc..... finish with the final array $flightinfo10. Secondly, I am trying to name the keys of the new 10 smaller seperate arrays with key names [Flight_Num] [Call_Sign] [Dep_Icao] [Arr_Icao] [Equip] [Flt_Time] [Flt_Distance] [Date] being the same for each array. Ultimately I will be inserting this into a db. I suck with arrays, and have tried to modify code snippets and have had no success. Here is something I was trying but just could echo anything out that made sense. foreach ($ten_pireps as $key=>$value) { } for ($i=0,$j=1;$i<count($ten_pireps); $i+=8,$j++) { $flight="flightinfo"; $flightsql="$flight$j"; // create new variable name array as it iterates $flightsql[Flight_Num] = $ten_pireps[$i]; $flightsql[Call_Sign] = $ten_pireps[$i+1]; $flightsql[Dep_Icao] = $ten_pireps[$i+2]; $flightsql[Arr_Icao] = $ten_pireps[$i+3]; $flightsql[Equip] = $ten_pireps[$i+4]; $flightsql[Flt_Time] = $ten_pireps[$i+5]; $flightsql[Flt_Distance] = $ten_pireps[$i+6]; $flightsql[Date] = $ten_pireps[$i+7]; // unfinished cause it is wrong!!!! } Thanks for the read - Nacman Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or T_NUM_STRING... I'm getting this error for this line: if ((int)$row['loyalty']<20) Thanks in advanced. // Nav Tabs $query = "select DISTINCT YEAR(sold_date) FROM Sold"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $year = substr($row['sold_date'], 0, -6); $navTab .= '<a class="miniTabOn" href="index.php?date='.$year.'">'.$year.'</a>'; } I am trying to create a link for each year of items in my database, yet the text is not showing up... The "nav tab" is, because I can see the background image from the class="miniTabOn". Can anyone spot an error? |