jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
My foreach statement is not finding the array. Can anyone see why?
jcbones replied to djkirstyjay's topic in PHP Coding Help
Try removing part of the conditional in the for loop. //From for($i = $c; $i >= ($c - 10); $i--) //To for($i = $c; $i > ($c - 10); $i--) //changed "greater than or equal to" into "greater than"; -
My foreach statement is not finding the array. Can anyone see why?
jcbones replied to djkirstyjay's topic in PHP Coding Help
This is just a suggestion: Remove: krsort($files); Then change: foreach($files as $file) { if($colCtr %$cols == 0) echo "</tr><tr>"; echo "<td><img src=\"" . $images . $file . "/01.jpg\" width=\"140px\" alt=\"\" /></td>"; $colCtr++; } To $c = count($files) - 1; //$c = the number of files in the array, minus 1 = highest index in the array. for($i = $c; $i >= ($c - 10); $i--) //$i = $c, $i is greater or equal to the array count minus 10, $i de-increments on each loop. This will give us a 10 countdown. { if($colCtr %$cols == 0) echo "</tr><tr>"; echo "<td><img src=\"" . $images . $files[$i] . "/01.jpg\" width=\"140px\" alt=\"\" /></td>"; //echo'ing out the $file[$i] on the loop, will give us the last 10 files in the file array. $colCtr++; } That should work. Although I have been known to have blonde moments. -
The reason the images fail to show through, is because they don't exist. For instance. /scrollingimages/97.jpg Does NOT exist, although the script is outputting a call for it.
-
can't get image resizer to work properly - it's almost there!
jcbones replied to scmeeker's topic in PHP Coding Help
You need to pass the $_FILES['Image1']['name'] into the database. $source_path = $_FILES[ 'Image1' ][ 'tmp_name' ]; $real_name = $_FILES['Image1']['name']; $sql="UPDATE thumbnail SET Image1='$real_name' WHERE username = '$username'"; I don't know why you are getting the warning from imagejpeg(). It is the last function in this script. The contents of $_FILES['Image1']['name'] doesn't look right. Throw some de-bugging lines in there to make sure you are getting desired data. At the top of the page, I would add this for de-bugging purposes. echo 'Dumping Data for Files Array: <pre>'; print_r($_FILES); echo '</pre>'; But, that is just me. -
Yep, I didn't code it to do that, but `tis an easy fix. Try replacing the following files with the ones posted. ajax.js var xmlHttp function getNames() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } from = document.getElementById('from').value; to = document.getElementById('to').value; sql = 'from=' + from + '&to=' + to; url="select.list.php"; url=url+"?"+sql; xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState==4) { document.getElementById('selectbox').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET",url,true); xmlHttp.send(null); } function getResults(name) { xmlHttp=GetXmlHttpObject(); if(xmlHttp==null) { alert("Your browser does not support AJAX!"); return; } from = document.getElementById('from').value; to = document.getElementById('to').value; if(from != '') { name = name+'&from='+from; } if(to != '') { name = name+'&to='+to; } url='table.list.php'; url=url+'?lastname='+name; xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState==4) { document.getElementById('tableBody').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET",url,true); xmlHttp.send(null); } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } table.list.php <?php include('config.php'); //database connection. if(!isset($_GET['lastname'])) { //if the proper get parameter is not there, redirect to google. header('Location: http://google.com'); exit(); } $lastname = preg_replace('~[^A-Za-z]+~','',$_GET['lastname']); //strip out anything but alpha for the name. $lastname = trim($lastname); //trim the name from all whitespace. if($lastname != '') { //check against an empty string. could have just used "empty()". $where = ' WHERE lastname = \'' . $lastname . '\''; //write the where clause. } else { //if lastname is empty, the where clause will be to, and it will return all names. $where = NULL; } $from = (isset($_GET['from'])) ? (int)preg_replace('~[^0-9]+~','',$_GET['from']) : NULL; $to = (isset($_GET['to'])) ? (int)preg_replace('~[^0-9]+~','',$_GET['to']) : NULL; if($from != NULL) { if($lastname == '') { $where = ' WHERE '; } else { $where .= ' AND '; } $where .= ' age >= ' . $from; } if($to != NULL) { if($from == NULL && $lastname == '') { $where = ' WHERE '; } else { $where .= ' AND '; } $where .= ' age <= ' . $to; } $query = "SELECT * FROM user $where"; $result = mysql_query($query); //get the database result. while($row=mysql_fetch_assoc($result)){ //loop and display data. ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> Filtering on Birthdate would depend on how you output that birthdate. Post up the output, and I'll look at it.
-
can't get image resizer to work properly - it's almost there!
jcbones replied to scmeeker's topic in PHP Coding Help
Try changing the source file to: $source_path = $_FILES[ 'Image1' ][ 'tmp_name' ]; -
Then use the or comparison operator (||). || is equal to OR, it is just higher on the precedence table.
-
Simple answer. $rs = mysql_query($query, $conn); while($row = mysql_fetch_array ($rs)) { //loop through the data, $array[] = $row; //and collect the rows. }
-
You are looking to put the posted data into the form on the "customize_search.php" page? You could pass them onto that page in one of two ways. 1. Set them to session variables. 2. pass them as Get parameters inside the Location url.
-
I was bored, so I whipped you something up. A couple of different files, the names MUST be exact, or you will have to change the scripts. Fully commented what was added. ALL FILES RESIDE IN THE SAME DIRECTORY! index.php <?php include('config.php'); //Include the database connections in it's own file, for easy integration in multiple pages. $lastname_result = mysql_query("SELECT lastname FROM user GROUP BY lastname"); $result = mysql_query("SELECT * FROM user"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../themes/style.css" rel="stylesheet" type="text/css" media="print, projection, screen" /></link> <link href="../common.css" rel="stylesheet" type="text/css"></link> <script type="text/javascript" src="ajax.js"></script> <?php //link to ajax.js ?> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td width="160" valign="top"></td> <td width="732" valign="top"> <table width="90%" border="0" align="center"> <form action="test3.php" method="post"> <label for="startage">From</label> <input type="text" id="from" name="from" onkeyup="getNames();" /> <?php //added javascript function call to function located in "ajax.js" ?> <label for="endage">to</label> <input type="text" id="to" name="to" onkeyup="getNames();" /> <?php //added javascript function call to function located in "ajax.js" ?> <select id="selectbox" name="area" onchange="getResults(this.value);"> <?php //added javascript function call to function located in "ajax.js", and changed the id for content change via javascript. ?> <option value="">Select an lastname</option> <option value=""></option> <?php while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> </select> </form> </table> <table id="tablesorter" class="tablesorter" border="0" cellpadding="0" cellspacing="1"> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Hometown</th> <th>Job</th> </tr> </thead> <tbody id="tableBody"> <?php //added id to the tbody so we could change the content via javascript ?> <?php while($row=mysql_fetch_assoc($result)){ ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> </tbody> </table> <p> </p> <p> </p> <p align="right"> </p> </td> <td width="196" valign="top"> </td> </tr> </table> </body> </html> table.list.php <?php include('config.php'); //database connection. if(!isset($_GET['lastname'])) { //if the proper get parameter is not there, redirect to google. header('Location: http://google.com'); exit(); } $lastname = preg_replace('~[^A-Za-z]+~','',$_GET['lastname']); //strip out anything but alpha for the name. $lastname = trim($lastname); //trim the name from all whitespace. if($lastname != '') { //check against an empty string. could have just used "empty()". $where = ' WHERE lastname = \'' . $lastname . '\''; //write the where clause. } else { //if lastname is empty, the where clause will be to, and it will return all names. $where = NULL; } $result = mysql_query("SELECT * FROM user $where"); //get the database result. while($row=mysql_fetch_assoc($result)){ //loop and display data. ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> select.list.php <?php include('config.php'); //database connections. if(!isset($_GET['to']) && !isset($_GET['from'])) { //if the uri parameters are not there send em to google. header('Location: http://google.com'); exit(); } $sql = array(); //start an array. $to = (isset($_GET['to'])) ? (int)$_GET['to'] : NULL; //if to is not set, then make it null, otherwise force it to an integer. $from = (isset($_GET['from'])) ? (int)$_GET['from'] : NULL; //if from is not set, then make it null, otherwise force it to an integer. if($to !== NULL && $to != 0 ) { //if to is not null, or is not equal to 0, then set it up for the query. $sql['to'] = ' age <= ' . $to; } if($from !== NULL && $from != 0) { //same goes for "from". $sql['from'] = ' age >= ' . $from; } if(!empty($sql)) { //if the sql array is not empty, set the where query. $where = ' WHERE ' . implode(' AND ' , $sql); } $query = "SELECT lastname FROM user $where GROUP BY lastname"; //write the query. //echo $query; $lastname_result = mysql_query($query) or die($query . ' ' . mysql_error()); //execute the query, or die trying. echo '<option value="">Select an lastname</option> <option value=""></option> '; while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> config.php <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); ?> ajax.js var xmlHttp function getNames() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } from = document.getElementById('from').value; to = document.getElementById('to').value; sql = 'from=' + from + '&to=' + to; url="select.list.php"; url=url+"?"+sql; xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState==4) { document.getElementById('selectbox').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET",url,true); xmlHttp.send(null); } function getResults(name) { xmlHttp=GetXmlHttpObject(); if(xmlHttp==null) { alert("Your browser does not support AJAX!"); return; } url='table.list.php'; url=url+'?lastname='+name; xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState==4) { document.getElementById('tableBody').innerHTML=xmlHttp.responseText; } } xmlHttp.open("GET",url,true); xmlHttp.send(null); } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } Tested in Firefox Only.
-
Using mod-rewrite, you may have to provide full URL's to your images, as they pass through the re-writer also, (as data calls from the client's browser). However, to get it to show with only "mysite.com/vote" you need to change your rule. RewriteRule ^vote/(.*)$ wp-content/blogs.dir/2/vote/$1 [L] The above code is checking for the word "vote" then a slash(/) then any more characters before the end of the string. This would return valid for "mysite.com/vote/index.html", but not valid for "mysite.com/vote". RewriteRule ^vote$ wp-content/blogs.dir/2/vote/index.html [L] The code above will evaluate true for "mysite.com/vote", but not true for "mysite.com/vote/index.html". You could get it to work both ways with more complex regex patterns, but I'll leave that for the Apache or Regex forums. As I am no regex guru.
-
1. Yes. 2. return the posted data to the page. NOTE, the first code section you posted, says that the form is posting to it's own page. Putting the mail function at the top of that page with a few data checks is all you need to easily post the data back to the form. If you post your entire script, then we can get it sorted for you fairly quickly.
-
There is surely an easier way to do the patterns, but I'm no regex guru. It is a bit sloppy, but it does work. <?php $str = file_get_contents('http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/support'); //get the page. $refPatt = '~<h3>Arena Referees</h3><table class="list">.*<tbody>(<tr>.*?</tr>)+</tbody>~'; $adminPatt = '~<h3>Arena Administrators</h3><table class="list">.*<tbody>(<tr>.*?</tr>)+</tbody>~'; preg_match_all($refPatt,$str,$ref); //match the table content. preg_match_all('~(<tr>)+~',$ref[0][0],$refTr); //count the table rows; $refCount = count($refTr[1]) - 1; //subtract 1 for the table header row. preg_match_all($adminPatt,$str,$admin); //match the table, gets both table's. preg_match_all('~(<tr>)+~',$admin[0][0],$adminTr); //counts the rows, gets both tables rows. $adminCount = (count($adminTr[1]) - $refCount) - 2; //subtract the last tables rows from the first table, and then subtract both table header rows. echo 'Admin\'s: ' . $adminCount . '<br />Referee\'s: ' . $refCount; //echo out the counts, I think you will find they are limiting these tables to 50 rows each. ?> Of course you could just say 50 ref's and 50 admins, because that is what the page has. I'm suspecting it is limited to show only that amount.
-
HOW TO RANDOMIZE a featured calandar event in the list mode
jcbones replied to realredd's topic in PHP Coding Help
v9egra has already offered help, and since he is a member of the "easyPHPcalendar" support team, he would be able to figure it out much faster, and more efficient that any of us. -
Try: mysql_query($query) or die(mysql_error()); echo "<script type=\"text/javascript\"> alert('You have successfully deleted a record'); window.location = 'view_client.php'; </script>";
-
Try it this way: UN-TESTED <?php include 'config.php'; //database config include 'opendb.php'; //connect database $search = (isset($_GET['q'])) ? mysql_real_escape_string($_GET['q']) : NULL ; //getting a name from a form if($search == NULL) { echo 'You have not defined a search parameter.'; exit(); } $sql = "SELECT a.*,b.* FROM kb3_pilots as a, kb3_corps as b WHERE a.plt_crp_id = b.crp_id AND a.plt_name = '$search'"; $result = mysql_query($sql)or die(mysql_error()); //here i choose to check in the kb3_pilots table, the plt_name column for the name written in the form earlier. if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { $pilotcorpid = $row['plt_crp_id']; $pilotcorpname = $row['crp_name']; echo "TEST: Pilot Id: $pilotcorpid and corp name: $pilotcorpname<br/>\n"; } } else { echo 'There was no results returned from your search.'; } include 'closedb.php'; ?> Resources: PHP Manual MySQL Manual PS. I added some checks in there for added functionality.
-
The part I think is the problem is: // The username is unique, so insert the data into the database $hash = md5( rand(0,1000) ); $query = "INSERT INTO"; mysqli_query($dbc, $query); More specifically, $query = "INSERT INTO"; mysqli_query($dbc, $query); I think you need to add more to your query than "INSERT INTO". MySQL is like a woman, it wants you to spell it out word for word.
-
complete noob needs a guidance on very basic contact form
jcbones replied to johnnyc82's topic in PHP Coding Help
I noticed some things in your comments, and being that the error you gets states: "We are sorry, but there appears to be a problem with the form you submitted." Then there is one possible reason that you are getting that. You are failing the expected data exists section of your script. // validation expected data exists if(!isset($_POST['first_name']) || //Make sure first_name is sent. !isset($_POST['last_name']) || //Make sure last_name is sent. !isset($_POST['email']) || //Make sure email is sent. !isset($_POST['telephone']) || //Make sure telephone is sent. !isset($_POST['email_subject']) || //Make sure subject is sent. !isset($_POST['comments'])) { //Make sure comments are sent. died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required You have written the comment that telephone is NOT required, but in the block above, it is required. $telephone = $_POST['email_subject']; // required $comments = $_POST['comments']; // required You should probably remove the: !isset($_POST['telephone']) || In the first block of code. As this is what requires that value to be set. -
Second query is wrong. $get_sold = mysql_query("SELECT SUM(ROUND(price,2)) AS total, SUM(ROUND(sold,2)) AS sales, date, username FROM product WHERE (sold = '1' AND username = '$item_username') AND MONTH(date) = MONTH(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)))
-
Ken is correct. facebox is a javascript function that works like lightbox.
-
Because this is an interesting proposal, I added a little code to the example above. It isn't perfect, as you can see if you un-comment the for loop, it kinda works. As was stated, getting $x is the big issue. <?php $items[] = 1234567890; $items[] = 234567890; $items[] = 34567890; $items[] = 4567890; $items[] = 567890; // for($i = 0; $i < 100; $i++) { // $items[] = mt_rand(); // } // rsort($items); $red = 255; $green = 0; $blue = 0; $middleNum = round((count($items) / 2) - 1); //Gets the middle index of the array. $x = floor(255 / $middleNum); foreach($items as $index => $item){ if($index > 0 && $index <= $middleNum){ $red -= $x; $green += $x; }elseif($index > $middleNum) { $green -= $x; $blue += $x; } echo number_format($item) . " is rgb($red,$green,$blue);<br />"; } ?>
-
Try this, and report back, ... Please. <?php $javascript = NULL; if(isset($_POST['sbrlink'])) { if(mail("contact@ctt.net","report broken link","Game notified:MarioBros")) { header('Status: 200'); header('Location: ' . $_SERVER['PHP_SELF'] . '?pass=true'); exit(); } else { $message = 'There was an error, when trying to contact us. Please try again.'; } } elseif(isset($_GET['pass'])) { $message = 'Thanks for the notification, we will address it shortly. Sorry for your inconvienence.'; $javascript = '<script type="text/javascript" >document.getElementById(\'sbrlink\').disabled = true;</script>'; } else { $message = NULL; } ?> <!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"> <head> </head> <body id="index" class="standard" > <form id="fbrlink" action="" method="post" onsubmit="return confirm('Click OK to notify us.');"> <p> <?php echo $message; ?> <input id="sbrlink" name="sbrlink" type="submit" value="Broken Link?" style="border:none; background-color:#FFFFFF; font-family:Trebuchet MS; font-size:15px; font-weight:bold; color:#1A4877; cursor:pointer; display:block; text-decoration:underline;" /> <?php echo $javascript; ?> </p> </form> </body> </html>
-
Or, you could use cURL to send your info to another script, this would process your function in the background.
-
1. This confirm box. echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>'; Will not keep this code from running. mail("contact@ctt.net","report broken link","Game notified:MarioBros"); If you would post the entire script, then I would fix it for you. My lessons don't seem to be helping.
-
I'm the Stalker