
New Coder
Members-
Posts
146 -
Joined
-
Last visited
Never
Everything posted by New Coder
-
I kinda see where you are going but I'm getting error: PHP Notice: Undefined variable: ref in C:\inetpub\wwwroot\test.php on line 5 on page 1 this is how page 1 looks at the moment: <?php session_start(); $a = rand(1,1000); for ($i = rand(1,10); $i < rand(11,20); $i++) $a += rand(1,rand(35,1000)); // KINDA ensures a random number $ref &= $_SESSION['tabs'][$a]; $ref = array(); // use $ref for the rest of STEP 1 $list = "<table>"; $list .= "<tr>"; $list .= "<th colspan=\"4\">Search for a Customer</th>"; $list .= "</tr>"; $list .= "<tr>"; $list .= "<td></td><form action=\"test2.php\" method=\"post\">"; $list .= "<td>Forename (Leave blank for all)</td>"; $list .= "<td>Surname (Leave blank for all)</td>"; $list .= "<td></td>"; $list .= "</tr>"; $list .= "<tr>"; $list .= "<td>Name Search</td><form action=\"search_name.php\" method=\"post\">"; $list .= "<td><input type=\"text\" name=\"forename\" size=\"25\"></td>"; $list .= "<td><input type=\"text\" name=\"surname\" size=\"25\"><input type=\"text\" name=\"tab\" value=\"$a\"></td>"; $list .= "<td class=submit><input type=\"submit\" class=\"submit\" value=\"Search\"></form></td>"; $list .= "</tr>"; $list .= "</table>"; echo $list ?>
-
Hello all, I hope someone can shed some light/point me in the right direction. I have a site that allows you to search for a customer then view and change their detail. page 1 has a search box for name entry. page 2 displays all the matches retrieved from a db table that match. The user selects which customer is the correct 1 and sets a cookie containing the selected customers unique id. page 3 allows changing of the customers details. now the problem I have: If a user navigates to page 3 and has a customers details on page for viewing all is well. If they open a new tab (leaving page 3 open on first tab) and go to page 1, search for another customer, page 2 select another customer (which overwrites cookie) then to page 3. They now have two tabs open on page 3 both displaying different customer details. If they return to the first tab and change some detail, when they save it actually updates the users details that corrispond to the second tab. I know this is because the cookie has been changed that holds the unique id that is required for the update query. How can I prevent this? I've looked at sessions but it would seem the same issue would excist. Am I wrong? Many Thanks I hope I made sense.
-
Hello All, On my form I have 8 radio buttons one of which the value is "other" I have a text box next to "other" so that we can capture what the other might be. (Standard stuff I'm sure you've seen) I have got it so that the text box is enabled if they select the "other" radio button, but it's not being disabled again if they decide to pick a different option and my limited javascript knowledge,I'm stuck. Heres what I have so far: <script type="text/javascript"> var currentEnabled = null; function enableElement(elem) { if (currentEnabled) { currentEnabled.disabled = true; } elem.disabled = false; currentEnabled = elem; } </script> list .= "<tr>"; $list .= "<td class=table width=\"50%\"><input type=\"radio\" class=\"radio_button\" name=\"destination\" value=\"1\">Spain</td>"; $list .= "<td class=table width=\"50%\"><input type=\"radio\" class=\"radio_button\" name=\"destination\" value=\"2\">France</td>"; $list .= "</tr>"; $list .= "<tr>"; $list .= "<td class=table width=\"50%\"><input type=\"radio\" class=\"radio_button\" name=\"destination\" onclick=\"enableElement(this.form.elements['other_desc'])\" value=\"99\">Other</td>"; $list .= "<td class=table width=\"50%\"><input type=\"text\" class=\"textdesc\" style=\"color:lightgrey\" size=\"50\" name=\"other_desc\" value=\"If other enter detail here\" disabled=\"disabled\" onfocus=\"if (this.className=='textdesc') { this.className = ''; this.value = '';this.style.color = 'black';}\" onblur=\"if (this.value == '') { this.className = 'textdesc'; this.value = 'If other enter detail here'; this.style.color = 'lightgrey'; }\" ></td>"; $list .= "</tr>"; Above is only a snipit :-) Any help much appreciated. Many Thanks
-
Ill build a quotes table and do some test for you too and get back with what I come up with
-
<?php $con = mysql_connect("localhost","quotesuser","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } $date = date("Y/m/d - H:i:s"); $ip = $_SERVER['REMOTE_ADDR']; mysql_select_db("quotes", $con); $qd = mysql_real_escape_string($_POST['Quote_Data']); $qb = mysql_real_escape_string($_POST['Quoted_By']); $sql1 = "select * from Quotes where ip='$ip' and Date_Time = '$date'"; $rs = mysql_query( $sql1, $con ) or die( "Err: Query 1"); if(mysql_num_rows($rs)!=1) { $sql2="INSERT INTO Quotes (Quote_Data, Quoted_By , Date_Time, ip) VALUES ('$qd','$qb','$date','$ip')"; $rs = mysql_query( $sql2, $con ) or die( "Err: Query 2"); header("Location: select.php"); echo "Quote Added to Database."; } else { echo ("Sorry you have already made 1 quote today"); } mysql_close($con) ?>
-
Ah right this is a page you've built linked from your IPB. I'm no expert on IPB's but if you can pass the logged on user you could then insert that into your table. If not I don't see why ip wouldn't work as a check. How ever you need an extra field in your quotes table for my suggested method to work. <?php $con = mysql_connect("localhost","quotesuser","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } $date = date("Y/m/d - H:i:s"); mysql_select_db("quotes", $con); $qd = mysql_real_escape_string($_POST['Quote_Data']); $qb = mysql_real_escape_string($_POST['Quoted_By']); $sql1 = "select * from Quotes where ip=$_SERVER['REMOTE_ADDR'] and Date_Time = $date"; $rs = mysql_query( $sql1, $con ) or die( "Err: Query 1"); if(mysql_num_rows($rs)!=1) { $sql2="INSERT INTO Quotes (Quote_Data, Quoted_By , Date_Time, ip) VALUES ('$qd','$qb','$date',$_SERVER['REMOTE_ADDR'])"; $rs = mysql_query( $sql2, $con ) or die( "Err: Query 2"); header("Location: select.php"); echo "Quote Added to Database."; } else { echo ("Sorry you have already made 1 quote today"); } mysql_close($con) ?> You can then change the query count slightly if you wanted to up the quotes allowed limit p.s code not tested as I dont have a quotes table
-
Is the user logged in or anything? Because you could store who entered the quote and the date entered. You could then check if they have already entered a quote on that day. and if so say sorry already made a quote today. or check for a limit of x amount of quotes allowed on a day. Or like you say you could store the ip and use this to check too.
-
I couldn't seem to get what I wanted so I used Javascript On the index page I added: <script type="text/javascript"> var WinNetwork = new ActiveXObject("WScript.Network"); var User_Name = WinNetwork.userName; window.location.href = "mainpage.php" + "?User_Name=" + encodeURIComponent(User_Name); </script> Then on mainpage I added: if($_GET['User_Name'] == "GenericAccName") { header("Location:genaccmain.php"); exit(); } Bit quick and dirty but until i find a better solution it's working to my needs. Many Thanks
-
Yes, correct. I looked into that but could only find the ip which I can't use. $_SERVER['REMOTE_HOST'] Is there one for computer name? Many Thanks
-
Hello all, This has probably been asked before but I couldn't find through search. And I'm pretty sure is not possible, but... Is there a way of displaying the windows logged on user? or get the name of the compter? as I know I can get the ip address. The reason I ask. Each user has their own network account but on occasion we need to log on a user as a generic account we have. And I want to check if it's this user accessing the page so different options etc can be displayed. I could use the computer name to check this as we log all activity. I could then query the log using the comp name to find logged on user. Unfortunately the log does not hold ip, which would seem obvious but it doesn't Many Thanks
-
a few tweaks to PHP/MySQL form I would like to make
New Coder replied to webguync's topic in PHP Coding Help
to get round you duplicate key issue: $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { #do insert sql } else { #go here via header or display own message etc } hope that helps -
You need to put the text in the value too: <option value="10 1/1/1/0/shdsl">1/1/1/0/shdsl</option> <option value="12 1/1/2/0/shdsl">1/1/2/0/shdsl</option> etc etc Or you could create a lookup table that references the value. That way you can produce two variables, one with the value eg. 10 and one with the text item eg: 1/1/1/0/shdsl
-
Php confirmation email to two different email addresses?
New Coder replied to vikas's topic in PHP Coding Help
You could try $second_email = "[email protected]"; $send_to = $em. ", ". $second_email; $this->email->to($send_to); -
Php confirmation email to two different email addresses?
New Coder replied to vikas's topic in PHP Coding Help
I dont use this type of email script but for mine I just seperate the addresses via a , so in your case i'd try: $second_email = "[email protected]"; $this->email->to($em, $second_email); -
You need to put the echo detail within the while loop otherwise I'm assuming it's only echoing the last record found or rarther than build the table every time you could just add to it like: <? $show = mysql_query("SELECT * FROM video_comments WHERE pageid='$vidid'"); $numrows = mysql_num_rows($show); if ($numrows > 0) { $list = "<table style='background-color:#FFF; border:#999 1px solid; border-top:none;' cellpadding='5' width='100%'>"; while($row = mysql_fetch_array($show)) { $userid = $row["userid"]; $username = $row["username"]; $comment = $row["comment"]; $date = $row["date"]; $date = strftime("%b %d, %Y", strtotime($date)); $list .= "<tr>"; $list .= "<td width='90%' valign='top' style='line-height:1.5em;'><span class='greenColor textsize10'>$date<a href='profile.php?id=$userid'> $username </a> said:</span><br /> $comment</td>"; $list .= "</tr>"; } $list .= "<table>"; echo ( $list ); } else { echo"<center><font face='arial' size='2'><p>This video has no comments.</font></center>"; } ?> Code not tested but should give you an idea
-
I have found the problem is with the mssql query. As mssql does not support or really have an equivlient to the LIMIT function I had to re-write the query. I have found a quick and dirty solution till I can re-write the query to perform better and correctly. I substituted: // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>[Next]></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>[Last]>></a> "; } // end if /****** end build pagination links ******/ // get the info from the db $sqlnum = "SELECT * FROM ( SELECT TOP $rowsperpage * FROM ( SELECT TOP $offset * FROM members order by member_id ASC) AS newtbl ORDER BY member_id DESC ) AS newtbl2 ORDER BY member_id ASC"; with // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>[Next]></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>[Last]>></a> "; // get the info from the db $sqlnum = "SELECT * FROM ( SELECT TOP $rowsperpage * FROM ( SELECT TOP $offset * FROM members order by member_id ASC) AS newtbl ORDER BY member_id DESC ) AS newtbl2 ORDER BY member_id ASC"; } else { // get the info from the db $remainder = $numrows - (($totalpages - 1) * $rowsperpage) ; $sqlnum = "SELECT * FROM ( SELECT TOP $rowsperpage * FROM ( SELECT TOP $offset * FROM members order by member_id ASC) AS newtbl ORDER BY member_id DESC ) AS newtbl2 ORDER BY member_id ASC"; }// end if and it works for now. Thanks
-
As pikachu says we are using mssql not mysql. The other item was a typo that just prevented a part of the row from displaying, thats sorted now. The code works...ish. Or at least in a fashion I wasn't expecting. The problem is it will always show 15 results on each page. So for 25 rows returned, page 1 will display records 1 to 15 and page 2 will display records 11 to 25. I would have thought page 2 should display 16 to 25. Should this be the case? Thanks
-
Hello All, I followed the very good tutorial from this site to allow me to paginate my pages. I have managed to get it working but not as I imagined so I think something is slightly wrong with my interperation. I have the number of items to show set to 15. If the number of items retrned is 16 i expected the first page to display the first 15 rows and the second page to display the last and only single row. At the moment it displays the first 15 on page 1 and the last 15 on page 2. Is this how it should work or have I coded incorrectly. $sql = "SELECT COUNT(*) FROM members"; $result = mssql_query( $sql, $conn ) or die( "Err: EXE" ); $r = mssql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 15; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage) * $rowsperpage; /****** build the pagination links (repeated below so displayed top and bottom of page)******/ $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<[First]</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><[Prev]</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>[Next]></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>[Last]>></a> "; } // end if /****** end build pagination links ******/ // get the info from the db $sqlnum = "SELECT * FROM ( SELECT TOP $rowsperpage * FROM ( SELECT TOP $offset * FROM members order by member_id ASC) AS newtbl ORDER BY member_id DESC ) AS newtbl2 ORDER BY member_id ASC"; $result = mssql_query( $sqlnum, $conn ) or die( "ERR: EXE" ); $num = mssql_num_rows ($result); if ($num !=0) { while ($row = mssql_fetch_assoc($result)) { $student_name = rtrim($row["forename"])." ".rtrim($row["surname"]); $member_id = $row["member_id"]; $profile = nl2br($row["profile"]); $list .= "<tr>"; $list .= "<th class=table colspan=2>".$member_name." (".$memebr_id.")</th>"; $list .= "</tr><tr>"; if ($row["profile"] == NULL) { $list .= "<td class=table><font color=\"red\">A profile has not been saved for this member</font></td>"; } else { $list .= "<td class=tblleft>$profile</td>"; } $list .= "<td class=table><form action=\"personal_details.php\" method=\"post\"><input type=\"hidden\" name=\"member_id\" value=\"$member_id\"><input type=\"submit\" value=\"View Detail\" class=\"submit\"></form></td>"; $list .= "</tr><tr>"; } $list .= "</table>"; echo( $list ); /****** build the pagination links ******/ // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<[First]</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><[Prev]</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>[Next]></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>[Last]>></a> "; } // end if /****** end build pagination links ******/ } else { echo ("You do not have any Members"); } Many Thanks
-
$sql = "SELECT * FROM tbl_announcements"; $rs = mysql_query( $sql, $conn ) or die( "Error Query"); $list = "<table border=\"1\" cellpadding=\"2\" align=\"center\" width=\"98%\">"; $list .= "<tr>"; $list .= "<td colspan=\"3\"><h1>Announcements</h1></td>"; $list .= "</tr>"; $list .= "<tr>"; while($row = mysql_fetch_array( $rs )) { $list .= "<td width=\"33%\">". rtrim(nl2br($row['announc'])) ."<br><br>Submitted by: ". rtrim($row['username']) ."</td>"; } $list .= "</tr>"; $list .= "</table><br>"; $list .= "<table border=\"0\" cellpadding=\"2\" align=\"center\" width=\"98%\">"; $list .= "<tr>"; $list .= "<td><h1>Submit your \"Announcement???\" *</h1></td>"; $list .= "</tr>"; if ( $auth != 'ok' ) { $list .= "<tr>"; $list .= "<td width=\"50%\">Sorry, you need to <a href=\"../login_form.php\">LOGIN</a> to submit an announcement???</td>"; $list .= "</tr>"; } else { $list .= "<tr>"; $list .= "<td>My \"Anouncement\":<br><textarea rows=\"5\" cols=\"40\" id=\"announc\" name=\"announc\"></textarea></td>"; $list .= "<td rowspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Submit\" class=\"submit\"></form>"; $list .= "</tr>"; } $list .= "</table>"; echo( $list ); quickly knocked up so syntax and layout may be a bit off
-
You could create a login form that will check your db for user then creates an auth cookie. You then can check the cookie exists as to whether or not to display certain parts of pages. eg: $sql = "select * from tbl_users where username=\"$username\" and password=\"$password\""; $rs = mysql_query( $sql, $conn )or die( "Error Query" ); #search for matches $num = mysql_num_rows ($rs); if ($num !=0) { setcookie("auth", "ok"); header("Location:index.php"); } else { echo("Invalid Login"); } Then check for it to display: $auth = $_COOKIE['auth']; if ( $auth == 'ok' ) { #form code } else { echo ("You need to be logged in to submit"); } obviously this is simple terms but may get you started.
-
win2k8 r2 is 64 bit if you are using the 32 bit sql then the odbc are different as the registry paths change to syswow(or similar) I know this isn't a solution but an area to look into
-
do you mean an input form with free text boxes where a user can fill in and save then it displays on the submitted items page?
-
Need Prevent Inserting Duplicate Record in Datbase when Refresh form
New Coder replied to Faks's topic in PHP Coding Help
Looking at your video it would appear you are using mysql as on one of your tabs you have php myadmin open so I'm assuming you need ]# http://www.tutorialspoint.com/mysql/mysql-handling-duplicates.htm INSERT IGNORE INTO tbl_name (column1, column2) VALUES( 'val1', 'val2'); if the same items are then submitted for a second time the insert will not happen. I'm not a pro at mysql and these were actually suggested to me in another thread. but it did work for me. If you have trouble re-wrritting your actual insert query to use the insert ignore post it here and i'll help if I can. -
Need Prevent Inserting Duplicate Record in Datbase when Refresh form
New Coder replied to Faks's topic in PHP Coding Help
I had a similar problem and I used an IF NOT EXISTS Query for mssql, the equivilent for mysql is INSERT IGNORE INTO Look these up they may help you -
Personally for neatness I always structure a table like: <?php include("lib/config.php"); $query = "SELECT * FROM staff_member"; $result = mysql_query($query); ?> <html> <style type="text/css"> <!-- @import url(style/style.css); --> </style> <head> </head> <body> <h2 align="center"> Full Staff list with Dependants</font></h2> <?php $list = "<table align=\"center\" border=\"0\" width=\"99%\">"; $list .= "<tr>"; $list .= "<th>Title</th>"; $list .= "<th>First Name</th>"; $list .= "<th>Initial</th>"; $list .= "<th>Last</th>"; $list .= "<th>Agency</th>"; $list .= "<th>Street</th>"; $list .= "<th>Address</th>"; $list .= "<th>Parish</th>"; $list .= "<th>Country</th>"; $list .= "<th>Office Tel#</th>"; $list .= "<th>Home Tel#</th>"; $list .= "<th>Office Mobile#</th>"; $list .= "<th>Personal Mobile#</th>"; $list .= "<th>Zone</th>"; $list .= "<th>Status</th>"; $list .= "<th>Location</th>"; $list .= "<th>Updated by</th>"; $list .= "</tr>"; while($row = mysql_fetch_object($result)) { $list .= "<tr>"; $list .= "<td>" .$row->title ."</td>"; $list .= "<td>" .$row->first ."</td>"; $list .= "<td>" .$row->initial ."</td>"; $list .= "<td>" .$row->last ."</td>"; $list .= "<td>" .$row->agency ."</td>"; $list .= "<td>" .$row->street ."</td>"; $list .= "<td>" .$row->adress ."</td>"; $list .= "<td>" .$row->parish ."</td>"; $list .= "<td>" .$row->country ."</td>"; $list .= "<td>" .$row->officetel ."</td>"; $list .= "<td>" .$row->hometel ."</td>"; $list .= "<td>" .$row->officemobile ."</td>"; $list .= "<td>" .$row->personalmobile ."</td>"; $list .= "<td>" .$row->zone ."</td>"; $list .= "<td>" .$row->status ."</td>"; $list .= "<td>" .$row->location ."</td>"; $list .= "<td>" .$row->updater ."</td>"; $list .= "</tr>"; } $list .= "</table>"; echo $list; ?> </body> </html> You can then also uses classes in your css to format specific items: th.table{ text-align:center; font-size:75%; background-color:#00000; } and call like: $list .= "<th class=table>Title</th>"; not sure this is best practice but you can force the size of columns like: $list .= "<th class=table width=35%>Title</th>";