Jump to content

jcbones

Staff Alumni
  • Posts

    2,653
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by jcbones

  1. Change this Line: $sql_query_result = mysql_query($sql_query) or die ("Error in sql_query signatures.inc: ".mysql_error()); To $sql_query_result = mysql_query($sql_query) or die ("Error in sql_query signatures.inc: <br />Query: $sql_query <br />".mysql_error()); I suggest this, because the error looks funny.
  2. What if the 400th character breaks a word boundary? Does the 400 character limit INCLUDE HTML? Do you only want <p> and <br />?
  3. If datetime is your column name, you may have to surround it in backticks. $sql = "INSERT INTO (`datetime`) VALUES (NOW())";
  4. Instead of using $d = getdate (time()); $myDate= $d["year"]."-".$d["mon"]."-".$d["mday"]; I would use: $myDate = date('Y-m-d'); Or, if the MySQL column is of type "date", I would skip all of that and do it there. $sql_query = "INSERT INTO $table_db (name, email, assname, asslocation, asscontent, publish, id, date) VALUES ('$name', '$email', '$assname', '$asslocation', '$asscontent', 'N', '', CURDATE())"; That is on the other side of the question though. I see no obvious errors in the code as it is written, and I get no parse errors on the script. Is this script included in another?
  5. The variables inside of the () is called arguments. These will assign the values passed to the function, to these variable names INSIDE the function. <?php function some_function($var1,$var2) { //var1 and var2 will be available inside the function, and contain the data passed to the function (you must pass both of these arguments). return $var1 . ', ' . $var2; } $my_first_name = 'John'; $my_last_name = 'Smith'; $get_name = some_function($my_first_name,$my_last_name); //pass the variables you desire the function to have, and the function will automatically assign them to $var1 and $var2 inside the function. $get_name2 = some_function('Have Gun','Will Travel'); //or you can pass it hard coded strings to do the same thing. echo $get_name . '<br />' . $get_name2; //echo the function returns will return the strings separated by a comma (what the function returns). //Passing the same variables (or strings) to this function will return the same thing as the first. If you omit the second argument (or string), it will only return var1. This is because we have set a default value to the argument var2, then handled that inside of the function. function some_other_function($var1,$var2=NULL) { if($var2 == NULL) { return $var1; } return $var1 . ', ' . $var2; } Hope that was simple to follow.
  6. <?php $x = 1; // set $x for ($i=1; $i<=100; $i += 9) { $count[] = "'{$i}'";} echo implode(', ',$count); Edit: didn't notice the single quotes.
  7. You can pass the hash directly in the form action attribute: <form action="thispage.php#options"> Or, you could (recommended) populate the options via AJAX.
  8. Try this, and lets see where we stand. <?php error_reporting(-1); ini_set('display_errors',1); require('./config.php'); $conn = mysql_connect( $dbhost, $dbuser, $dbpass ); mysql_select_db($dbname,$conn); $action = $_GET['action']; //get action from the URI query string. $assname = $_POST['assname']; $asslocation = $_POST['asslocation']; $asscontent = $_POST['asscontent']; $name = $_POST['name']; $email = $_POST['email']; $form = (int)$_GET['form']; //get form from the URI query string. if($action=="post"){ if ($assname=="" || $asslocation=="" || $asscontent=="" || $name=="" || $email=="" || !isValidEmail($email)){ $msg1 = <<<ENDH <div align="center"> <center> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="373" height="30"> <tr> <td width="373" height="11" bgcolor="#0000FF"> <p align="center"><b><font color="#FFFFFF">Invalid Info</font></b></td> </tr> <tr> <td width="373" height="15" bgcolor="#FFFFFF"> <p align="center"><Font color=red>You have entered invalid information</font></td> </tr> </table> <br><p align="center">Press the back button to correct your information</p> </center> </div> ENDH; printContent($msg1); } else { $table_db = $ASS[$form]; $d = getdate (time()); $myDate= $d["year"]."-".$d["mon"]."-".$d["mday"]; $sql_query = "INSERT INTO $table_db (name, email, assname, asslocation, asscontent, publish, id, date) VALUES ('$name', '$email', '$assname', '$asslocation', '$asscontent', 'N', '', '$myDate')"; $gholi= mysql_query( $sql_query , $conn ); $msg1 = <<<ENDH <div align="center"> <center> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="373" height="30"> <tr> <td width="373" height="11" bgcolor="#0000FF"> <p align="center"><b><font color="#FFFFFF">Submission Information</font></b></td> </tr> <tr> <td width="373" height="15" bgcolor="#FFFFFF"> <p align="center"><Font color=green>Thankyou For your submission</font></td> </tr> </table> <br><p align="center">Click here <a href="http://www.ammotroops.com/">Ammotroops</a> to go to main page</p> </center> </div> ENDH; printContent($msg1); } } else if($action=="view"){ if($start=="" || $start < 0){ $start=0; } else { $start = (int)$_GET['start']; //get the start from the URI query string. } $max=$default_max; if(($start % $max) != 0){ header("Location:$home/$view?action=view&start=0&form=$form"); } if($pg==""){ $pg=1; } $num_cat = count($ASS); if($form >= $num_cat || $form < 0 || $form=="" ){ header ("Location: $home"); exit; } $table_db = $ASS[$form]; $num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table_db where publish=\"Y\"")); $remainder = ($num_rows % $max); if(($start+$max) > ($num_rows + ($max - $remainder))){ $start=0; $max = $default_max; } head($form,$Title,$formpg); $sql_select_query = "SELECT * FROM $table_db WHERE publish=\"Y\" ORDER BY date DESC LIMIT $start,$max"; //echo $sql_select_query; $select_info = mysql_query( $sql_select_query , $conn ); while( $theRow = mysql_fetch_row( $select_info )){ echo "<tr><td align=center width=\"200\" height=\"1\">$theRow[7]</td><td width=\"371\" height=\"24\" rowspan=\"4\">$theRow[4]</td></tr>"; echo "<tr><td align=center width=\"200\" height=\"1\">$theRow[2]</td></tr>"; echo "<tr><td align=center width=\"200\" height=\"1\">$theRow[3]</td></tr><tr><td height=100%> </td></tr>"; echo "</tr><tr><td width=\"555\" height=\"1\" colspan=\"2\" bgcolor=\"#E2E1D1\"> </td></tr>"; } echo "</table></div>"; $num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table_db where publish=\"Y\"")); echo "Page: "; $remainder = ($num_rows % $max); $num_pg = (int)($num_rows / $max); if($remainder > 0) $num_pg = $num_pg+1; for ($i=0; $i< $num_pg; $i++) { $startVal = $i * $max; $page = $i+1; echo "\n<a href=$view?action=view&start=$startVal&max=$max&form=$form>$page</a> "; } mysql_close ($conn); foot(); } function isValidEmail($email){ if( strstr($email,'@') ) { return true; } else{ return false; } } function foot(){ $foot = <<<ENDH </center> </body> </html> ENDH; echo $foot; } function head($form,$Title,$formpg){ $head = <<<ENDH <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="doogie"> <meta name="keywords" content="ammo, newgroups, binnews, ammo bowl, iyaayas, doogie, air force, ammo ass award, ammo dumb ass, ammo ace, ammo base"> <title>Ammo Ass www.AmmoTroops.com</title> </head> <body background="http://ass.ammotroops.com/froncoin4.jpg"> <center><a href="http://www.ammotroops.com">www.AmmoTroops.com</a> <div width="600"> <table align=center><tr><td align=center><b><font color="#FF0000"><font size="+3">$Title[$form] AWARD</font></font></b></td></tr> <tr><td align=center><a href=$formpg?form=$form>$Title[$form] Form</a></td></tr><tr><td> <br><br></td></tr></table> <table BORDER="1" COLS="2" WIDTH="577"> <tr> <td width="131" height="19" bgcolor="#E2E1D1"><center> <p><b>Date</b></p> </center></td> <td width="424" height="31" bgcolor="#E2E1D1" rowspan="3" valign="middle"> <p align="center"><b>Why</b></td> </tr> <tr> <td width="134" height="12" bgcolor="#E2E1D1"> <p align="center"><b>Name</b></td> </tr> <tr> <td width="134" height="1" bgcolor="#E2E1D1"> <p align="center"><b>Location</b></td> </tr> ENDH; echo $head; } function printContent($content){ $html = <<<ENDH <html> <head> <title>Ammo TRoops</title> </head> <body background="http://ass.ammotroops.com/froncoin4.jpg"> $content </body></html> ENDH; echo $html; } ?>
  9. Use a LEFT JOIN on table 2
  10. MySQL's timestamp is formatted YYYY-mm-dd H:I:S. You would not need to convert from UNIX_TIMESTAMP to get the month. Just use the MONTH() function.
  11. Change: </dl> <? } ?> </div> To: </dl> <?php } ?> </div> See if that works. If short tags are turned off, you should be getting a parse error for the missing }
  12. Thats funny, I get 25% with that code.
  13. Why all the database request? I'm pretty sure you can get rid of all but one of them, if you think about it. $sql = "SELECT t.* FROM ".MYSQL_PREFIX."_tickets AS t JOIN " . MYSQL_PREFIX . "_members AS m ON t.owner_mnum = m.mnum WHERE active='1' LIMIT $pcc," . MAX_RESULTS; $mysql = mysql_query($sql) or trigger_error($sql . ' has encountered an error:<br />' . mysql_error()); while ($t = mysql_fetch_array($mysql)) {
  14. Did you put in an actual lattitude? or longitude?
  15. Works fine for me as well.
  16. I have used PHPMySQLautobackup in the past, and found it very easy to set up and use. You can chose to save to the server, or send to yourself in an email, or both. *I have no affiliation with the linked site*
  17. That is a very good tutorial on how to use mod-rewrite.
  18. You are looking for mod_rewrite.
  19. Yours just takes a few more steps to complete. Nothing really wrong with doing it that way (in the coding department), it is just more coding. The good thing about PHP is that there is no ONE definitive way to do anything. For instance, I only use while loops for results returned by a function, otherwise if I need to go through an array, I use a for loop. Now saying that, when posting code snippets on here, you must realize that a lot of the people that come here for help have no idea about sanitation and validation. So always include that in your snippets. Your code doesn't have any of that shown. You must always escape string data in SQL, as well as make sure that data is of the proper type that you expect. Bad solution? No, just different.
  20. To keep it in line with the rest of the replies, my script would change: <?php $sql = "INSERT INTO Persons (FirstName,Age) VALUES($_POST['FirstName1'],$_POST['Age1']),($_POST['FirstName2'],$_POST['Age2']),($_POST['FirstName3'],$_POST['Age3'])"; ?> To: if($_SERVER['REQUEST_METHOD'] == 'POST') { //if form was submitted through post foreach($_POST['firstname'] as $i => $name) { //cycle the data, both the name and age are arrays, so treat them as such. if(!empty($name)) { $query[] = sprintf("('%s','%d')",mysql_real_escape_string($name),(int)$_POST['age'][$i]); } } if(!empty($query)) { $sql = 'INSERT INTO table (firstname,age) VALUES ' . implode(' , ', $query); } } edit: typo
  21. I would use a little javascript to make it user friendly, and then treat the inputs as arrays. <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { //if form was submitted through post foreach($_POST['firstname'] as $i => $name) { //cycle the data, both the name and age are arrays, so treat them as such. echo (empty($name) ? 'undefined' : $name) . ' is ' . (empty($_POST['age'][$i]) ? 0 : $_POST['age'][$i]) . '<br />'; } } ?> <html> <head> <script type="text/javascript"> <?php //lets use a little javascript to make it more usable. ?> function addInput() { var input = document.createElement('div'); input.innerHTML = 'Firstname: <input type="text" name="firstname[]"> Age: <input type="text" name="age[]">'; document.getElementById('div1').appendChild(input); } </script> </head> <body> <form id="form1" name ="1" action="" method="post"> <div id="div1"> <div id="element1"> Firstname:<input type="text" name="firstname[]" /> Age:<input type="text" name="age[]" /><br /> </div> </div> <a href="javascript:void(0)" onclick="addInput();">Add Another User</a><br /> <input type="submit" name="submitbutton" id="submit" value="SUBMIT"> </form> </body> </html>
  22. I would store it all in one line: item_id | low_length | high_length | measurement_unit ----------+----------------+-----------------+------------------------ 1234 | 6 | 12 | cm Then query it: SELECT * FROM table WHERE measurement_unit = 'cm' AND 8 BETWEEN low_length AND high_length or, along those lines.
  23. I always wrap the conditional in ()'s for readability. But, then again, most people think I am strange...
  24. You may want to consider using radio buttons, or a link to select users to delete.
  25. There are a couple reasons why you aren't getting results. Starting with $id is out of scope, as you have not passed it to the function. After that, you need to return the values from the function in order to use it the way you are trying to. Functions in PHP How to return values from functions in PHP Variables scope in PHP (GLOBAL = Bad)! Note: AyKay47's last post will not work because of the scope issue.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.