Jump to content

aeafisme23

Members
  • Posts

    121
  • Joined

  • Last visited

    Never

Everything posted by aeafisme23

  1. Database Structure: tables: areacode, dealer, dealerinfo (areacode is primary id as it's unique) test link: http://thegreatestsave.org/ut/search.php (574 and 765 are the only working ones i put for test purposes) Search input box used to find all records in areacode put in. I added delete and edit (both not working, but focusing on delete unless you are so leet you want to throw a forum thread my way) I am unsure of how to pass the variables to the delete_record.php to successfully delete that individual record so i will paste the code for the 2 pages. search.php partial code (referencing the part i dont know how to pass the variable correctly in bold) //table background color = row_color variable......... echo "<td width=\"65\" valign=\"top\"><a href=\"#\">Edit</a></td><td width=\"65\" valign=\"top\"> [b]<a href=\"delete_record.php?keywords='$keywords'\">Delete</a></td></tr>";[/b] echo "</table></center>"; search.php Complete Code <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); //search variable = data in search box or url if(isset($_GET['search'])) { $search = $_GET['search']; } //trim whitespace from variable $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result $keywords = array_diff($keywords, array("")); //Set the MySQL query if ($search == NULL or $search == '%'){ } else { for ($i=0; $i<count($keywords); $i++) { $query = "SELECT * FROM dealer WHERE areacode = '$keywords[$i]'"; } //Store the results in a variable or die if query fails $result = mysql_query($query) or die(mysql_error()); } if ($search == NULL or $search == '%'){ } else { //Count the rows retrived $count = mysql_num_rows($result); } echo "<html>"; echo "<head>"; echo "<title>search</title>"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<center>"; echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">"; echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" />"; echo "</form>"; //If search variable is null do nothing, else print it. if ($search == NULL) { } else { echo "You searched for <b><FONT COLOR=\"blue\">"; foreach($keywords as $value) { print "$value "; } echo "</font></b>"; } echo "<p> </p><br />"; echo "</center>"; //If users doesn't enter anything into search box tell them to. if ($search == NULL){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; } elseif ($search == '%'){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; //If no results are returned print it } elseif ($count <= 0){ echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; //ELSE print the data in a table } else { //Table header echo "<center><table width=\"680\" id=\"search\" bgcolor=\"#AAAAAA\">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\"><b>Area Code</b></td>"; echo "<td width=\"150\" valign=\"top\"><b>Dealer</b></td>"; echo "<td width=\"300\" valign=\"top\"><b>Dealer Info</b></td>"; echo "<td width=\"65\" valign=\"top\"> </td><td width=\"65\" valign=\"top\"> </td><tr>"; echo "</table></center>"; //Colors for alternation of row color on results table $color1 = "#d5d5d5"; $color2 = "#e5e5e5"; //While there are rows, print it. while($row = mysql_fetch_array($result)) { //Row color alternates for each row $row_color = ($row_count % 2) ? $color1 : $color2; //table background color = row_color variable echo "<center><table width=\"680\" bgcolor=".$row_color.">"; echo "<tr>"; echo "<td width=\"100\" valign=\"top\">".$row['areacode']."</td>"; echo "<td width=\"150\" valign=\"top\">".$row['dealer']."</td>"; echo "<td width=\"300\" valign=\"top\">".$row['dealerinfo']."</td>"; echo "<td width=\"65\" valign=\"top\"><a href=\"#\">Edit</a></td><td width=\"65\" valign=\"top\"><a href=\"delete_record.php?keywords='$keywords'\">Delete</a></td></tr>"; echo "</table></center>"; $row_count++; //end while } //end if } echo "</body>"; echo "</html>"; if ($search == NULL or $search == '%') { } else { //clear memory mysql_free_result($result); } ?> delete_record.php (all kinds of messed up) <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>United Truck Parts - Delete Results</title> </head> <body> <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); $keywords = $_GET['keywords']; // Delete a row from a table mysql_query("DELETE FROM dealer WHERE areacode = '$keywords'") or die(mysql_error()); ?> you deleted results <?php echo $search ; ?> </body> </html>
  2. I am helping Quischen on this project and I do not think he is being quite clear so let me show you the few main pages involved with code. http://www.thegreatestsave.org/media_videos/retrieve.php?state=CA&city=Los%20Angeles WORKS http://www.thegreatestsave.org/media_videos/retrieve.php?state=kindi&city=tv (DOES NOT WORK, error) HEADER INCLUDE FILE - Basically pulls the correct header for the page. ob_start(); is present, also ob_start(); in testing we put in all files just to test to make sure it wasnt the most common error. Remember this code works perfectly well on a different server. <?php $state = $_GET['state']; $city = $_GET['city']; ?> <?php $copyright = "KinderVision® 2006-2007"; if (($state == "VA" && $city =="Richmond-Petersburg") || ($state == "ID" && $city =="Boise") || ($state == "UT" && $city =="Salt Lake City") || ($state == "NC" && $city =="Charlotte") || ($state == "kindi" && $city =="tv") || ($state == "FL" && $city =="Tampa-St. Petersburg-Sarasota") || ($state == "FL" && $city =="Jacksonville") || ($state == "ID" && $city =="Twin Falls") || ($state == "PA" && $city =="Wilkes Barre")) { ob_start(); include("header_dma.php"); } elseif ($state == "CA" && $city =="San Diego") { ob_start(); include("header_kfmb.php"); } else { ob_start(); include("http://www.thegreatestsave.org/header.php");} ?> Page 2 Retrieve.php - passes code along to Video Include Page 3, where videos and content are <?php include("../headerinclude.php"); $state = $_GET['state']; $city = $_GET['city']; $chapter1 = $_GET['chapter']; ?> <?php echo "<table width=\"798\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\" bgcolor=\"ffffcc\"> <tr><td width=\"570\" valign=\"top\" bgcolor=\"ffffcc\">"; /* Error Checking, if state or city does not exist, then exit */ if ($state == "" || $city =="") { $URL="http://www.kindervision.org"; header("Location: $URL"); } /* Chapters 1-4 WTVR */ /* RICHMOND, VIRGINIA: WTVR AND MATTRESS WAREHOUSE CHAPTER 1 */ elseif ($state == "VA" && $city =="Richmond-Petersburg" ){ include("videoinclude.php"); echo "</td>"; } // LEFT OUT other results to shorten, but the next 3 error out, the rest works <<<<<<<< /* Chapters 1-4 WBRE, PA - Wilkes Barre */ /* WBRE, PA - Wilkes Barre */ elseif ($state == "PA" && $city =="Wilkes Barre" && $chapter =="1"){ include("videoinclude.php"); echo "</td>"; } /* Chapters 1-4 KindiTV */ /* Kindi TV CHAPTER 1 */ elseif ($state == "kindi" && $city =="tv" && $chapter =="1"){ include("videoinclude.php"); echo "</td>"; } /* Chapters 1-4 Spanish TV */ /* Spanish TV CHAPTER 1 */ elseif ($state == "spanish" && $city =="tv" && $chapter =="1"){ include("videoinclude.php"); echo "</td>"; } else { $URL="http://www.kindervision.org"; header("Location: $URL"); } ?> <?php echo"</tr>"; include("../footerinclude.php"); ?> and finally..... results... Video Include.php page 3 I skipped all the other if and else if statements and showing example of assigned variables if city state requirements are met then show html etc. /* Spanish TV, Chapters 1-4 */ elseif ($state == "spanish" && $city =="tv") { $kindiclubquizlink = "http://www.kindervision.org/kindiclub/retrieve_espanol.php?state=spanish&city=tv"; $wolftrapsquizlink = "http://www.kindervision.org/wt/wt_retrieve_espanol.php?state=spanish&city=tv"; $parentsquizlink = "#"; $flashcode = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"552\" height=\"400\" id=\"spanishnocustom\" align=\"middle\"> <param name=\"allowScriptAccess\" value=\"sameDomain\" /> <param name=\"movie\" value=\"spanishnocustom.swf\" /> <param name=\"quality\" value=\"high\" /> <param name=\"scale\" value=\"exactfit\" /> <param name=\"bgcolor\" value=\"#000000\" /> <param name=\"wmode\" value=\"opaque\"> <embed src=\"spanishnocustom.swf\" quality=\"high\" scale=\"exactfit\" bgcolor=\"#000000\" width=\"552\" height=\"400\" name=\"spanishnocustom\" wmode=\"opaque\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /> </object>"; } else { $URL="http://www.kindervision.org"; header ("Location: $URL"); } ?> <table width="794" bgcolor="#7FB497" cellpadding="0" cellspacing="0" border="0"> HTML CODE ETC ETC blah blah We're going crazy, is there a better logic to this possibly?
  3. Thank You Everyone!!!!! Thanks to Crayon Violent and chronister , you guys make PHPFreaks a excellent place to learn!
  4. I guess I am just confusing myself more than anything right now as i run in circles. First Page: Session1.php [code]<?php session_start(); session_register("state", "city"); ob_start(); include("header.php"); ?> <table width="798" border="1" cellpadding="0" cellspacing="0"> <tr> <td> <p>Your Choice was: <?php echo $state; echo ", "; echo $city; ?> <br><br> <a href="session1.php">Page 1</a> | <a href="session2.php">Destroy Session But Still Show on Page 2 for last time!</a></p> <p>You are at Session page 2.</p> </td> </tr> </table> </body> </html>[/code] I put the logic behind the include file for the header, as i want to use the header as the session through out the whole site, kinda like a customizeable header for every page of a site: header.php [code]<SCRIPT language=JavaScript src="dropdown.js" type=text/javascript></SCRIPT> <SCRIPT language=JavaScript type=text/javascript> var states = new Array( new Array("dropdown","state","city"), new Array(true,"IN|Indiana","Evansville"), new Array(true,"IN|Indiana","Fort Wayne"), new Array(true,"IN|Indiana","Indianapolis"), new Array(true,"IN|Indiana","Kokomo"), new Array(true,"IN|Indiana","Lafayette"), new Array(true,"KY|Kentucky","Bowling Green"), new Array(true,"KY|Kentucky","Charleston-Huntington"), new Array(true,"KY|Kentucky","Lexington"), new Array(true,"KY|Kentucky","Louisville"), new Array(true,"WY|Wyoming","Casper-Riverton"), new Array(true,"WY|Wyoming","Cheyenne-Scottsbluff") ); </SCRIPT> <body onload="dropdown(1,states);"> <?php echo "<form name=\"dropdown\" action='".$_SERVER['php_self']."' method=\"post\">"; ?> <table width="798" border="1" cellpadding="0" cellspacing="0"> <tr> <td rowspan="3" width="400"> <?php if ($state == "IN" && $city =="Kokomo") { echo"KOKOMO, INDIANA<br><img src=\"x.jpg\" width=\"20\" height=\"20\">"; } else { echo "A different Selection that isn't IN and Kokomo<br><img src=\"x.jpg\" width=\"20\" height=\"20\">"; } ?> </td> </tr> <tr> <td valign="top"><p>State:</p></td> <td><select style="width:180px;" onchange="update(this,states)" size="1" name="state"> <option selected name="formstate"><b>Select State</b></option></select><br><br> </td> </tr> <tr> <td><p>City:</p></td> <td><select onchange="update(this,city);" size="1" name="city"> <option selected><b>Select City</b></option></select></td> </tr> <tr> <td colspan="2"><center><p>Select a city that best represents where you live</p></center></td> <td><input type="submit" value="submit"/></td> </tr> </table> </form>[/code] Second Page: Session2.php (used to destroy session along with unregistering) Note: act like there are 100's of pages in between here, i just have this so i can try to destroy the session. [code]<?php session_start(); session_unset(); session_destroy(); ob_start(); include("header.php"); ?> <table width="798" border="1" cellpadding="0" cellspacing="0"> <tr> <td> <p>Your Choice was: <?php echo $state; echo ", "; echo $city; ?> <br><br> <a href="session1.php">Page 1</a> | <a href="session2.php">Destroy Session But Still Show on Page 2 for last time!</a></p> <p>You are at Session page 2.</p> </td> </tr> </table> </body> </html> [/code] I guess heres my logic..... Declare Session Start in all pages Register variables.... ( do i register only in header or every page) When closing session am i doing it right. This is driving me insane, if you dont want to write code to help me out thats fine, but i just need help with logic as well, becuase i wont learn with out knowing, much appreicated to everyone who looks. Randy
  5. Thank You for the first step. That works correctly but offers no "validation", do i need to make another hidden input box and make a 2nd process, or can i validate with in the email since its saying if valid redirect to thankyou.php. code up to now with above implementation: [code]<?PHP     $message    = "";     $csserrorfont = "basictext";     $username  = "";     if ($_POST['process'] == 1) {         $pattern = '/.*@.*\..*/';         $email  = $_POST['email'];         $urlname = urlencode($$_POST['username']);         if (preg_match($pattern, $_POST['email']) > 0) {             // Here's where you would store             // the data in a database...             header(               "location: thankyouemail.php?&username=$urlname");         }         $message    = "Please enter a valid email address.";         $username  = $_POST['name'];         $csserrorfont = "errortext";     } ?> <html> <style>     .basictext {         font-family: Arial, Helvetica, sans-serif;         font-size: 14px; color:#000066;     }     .errortext {         font-family: Arial, Helvetica, sans-serif;         font-size: 14px; color:#000066; font-weight: bold;     } </style> <body> <form action="emailtest.php" method="post"> <table width="520" cellpadding="2" cellspacing="0" border="1" bordercolor="#000000"> <tr> <td width="100" valign="top"><p><span class="<?php print $csserrorfont; ?>">Email:</span></p></td> <td width="200" valign="top"><input name="email" type="text" maxlength="50" size="25" class="<? print $csserrorfont; ?>"></td> <td width="220" valign="top"><?php if ($message != "") { print '<span class=\"errortext\">'.$message."</span>";} ?> <span class="<?php print $csserrorfont; ?>"> </td> </tr> <tr> <td width="100" valign="top"><p><span class="basictext">First Name:</span></p></td>     <td width="200" valign="top"><input name="username" type="text" class="basictext" value="<?php print $username; ?>"></td> <td width="220"> <?php if(empty($_POST['username'])) { echo "error"; } if(!empty($_POST['username'])) // note the ! { echo ""; } ?></td>     </tr> <tr> <td colspan="3" valign="top"> <input type="hidden" name="process" value="1">     <input type="submit" name="Button1" value="submit"></td> </tr> </table> </form> </body></html>[/code]
  6. Everything is working 100% full functional. I have not seen many PHP scripts like this because for some reason everyone keeps using stupid Client Side JS and you have the annoying pop ups. So I have ripped some code and manipulated this a little, but for some reason I cant figure out how to do the same to the USERNAME field to validate that its not null, can anyone help. Heres the code below: [code]<?PHP     $message    = "";     $csserrorfont = "basictext";     $username  = "";     if ($_POST['process'] == 1) {         $pattern = '/.*@.*\..*/';         $email  = $_POST['email'];         $urlname = urlencode($$_POST['username']);         if (preg_match($pattern, $_POST['email']) > 0) {             // Here's where you would store             // the data in a database...             header(               "location: thankyouemail.php?&username=$urlname");         }         $message    = "Please enter a valid email address.";         $username  = $_POST['name'];         $csserrorfont = "errortext";     } ?> <html> <style>     .basictext {         font-family: Arial, Helvetica, sans-serif;         font-size: 14px; color:#000066;     }     .errortext {         font-family: Arial, Helvetica, sans-serif;         font-size: 14px; color:#000066; font-weight: bold;     } </style> <body> <form action="emailtest.php" method="post"> <table width="520" cellpadding="2" cellspacing="0" border="1" bordercolor="#000000"> <tr> <td width="100" valign="top"><p><span class="<?php print $csserrorfont; ?>">Email:</span></p></td> <td width="200" valign="top"><input name="email" type="text" maxlength="50" size="25" class="<? print $csserrorfont; ?>"></td> <td width="220" valign="top"><?php if ($message != "") { print '<span class=\"errortext\">'.$message."</span>";} ?> <span class="<?php print $csserrorfont; ?>"> </td> </tr> <tr> <td width="100" valign="top"><p><span class="basictext">First Name:</span></p></td>     <td width="200" valign="top"><input name="username" type="text" class="basictext" value="<?php print $username; ?>"></td> <td width="220">validation</td>     </tr> <tr> <td colspan="3" valign="top"> <input type="hidden" name="process" value="1">     <input type="submit" name="Button1" value="submit"></td> </tr> </table> </form> </body></html>[/code]
  7. First of all I have researched on phpfreaks and to no avail there was nothing as "BASIC" as i needed. I just want SIMPLE error handling messages to go to the corresponding column, i do not want it above, below, i want it in specific columns where i stated i need below. NO JAVASCRIPT. Keep it noobish for me, meaning no db interaction just simple :)  THANKS :) Contactform.php [code] <form name="cform" method="post" action="formdisplay.php"> <table><tr> <td><p>First Name:</p></td> <td><input type="text" maxlength="25" name="firstname"></td> <td>if error i want it to go here on submit, I DO not want javascript at all, and i do not want it to go to display results, i wanted it validated here using php</td> </tr> <tr> <td><p>Last Name:</p></td> <td><input type="text" maxlength="25" name="lastname"></td> <td>error handling</td> </tr> </table> </form> [/code] Formdisplay.php [code] <p>Display Results</p> <?php echo "<p>Name: " . $firstname . " " . $lastname . "</p>"; ?> [/code] http://www.phpfreaks.com/forums/index.php/topic,36973.0.html  I thought the main posting was goign to help me but only found out that it was very very advanced for a noob such as myself. Much help is appreciated.
  8. I am just refreshing this item, I will make sure this is the last so others have a chance as well, just seeing if anyone has any input today it would be much appreciated :)
  9. [b]SQL DUMP: [/b][url=http://www.kindervision.org/anthonydwayne/sql.txt]http://www.kindervision.org/anthonydwayne/sql.txt[/url] [font=Verdana][color=red]Any advice would rock!!! Thanks all that read![/color][/font] [b]Error Message:[/b] [code]Fatal error: Allowed memory size of 18388608 bytes exhausted (tried to allocate 11520 bytes) in /home2/admin/etc-www/etc/etc.php on line 12[/code] [b]Problem:[/b] When clicking submit I add infinite enteries to the database. I need to find a way to insert from my form to how my database is setup so that it adds correct enteries and id's. Note the form has 3 sql queries because each input updates to a different table in the database. Once populated the chained select will show all enteries. I have provided a picture of the database tables, the first few enteries were manually entered in mySQL and works, but if i do it through a form it loops. I will produce codes to both the form and the chained select.  I understand that the DB structure is jank and need a know how to setup correctly. I believe that the default 0 should go but i know it wont solve problem completely in its entirety. [img]http://loonar.net/table.jpg[/img] [b]Code:[/b] (ADD.php) This is the form [code]<?php if ($submit) {   // process form $db = mysql_connect("www.domain.org", "user", "pass"); mysql_select_db("database_org",$db); // Write the queries $sql = "INSERT INTO make (make_id, make) VALUES ('$make_id','$make')"; $sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')"; $sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')"; // Execute the queries mysql_query($sql) or die(mysql_error()); mysql_query($sql2) or die(mysql_error()); mysql_query($sql3) or die(mysql_error());     $result = mysql_query($sql);   $result = mysql_query($sql2);   $result = mysql_query($sql3);   require("add.php");   echo('thank you for your add'); } else{   ?>   <table width="720" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">   <tr>     <td valign="top" bgcolor="ffffff"> <FORM NAME=submit method="post" action="<?php echo $PHP_SELF?>"> <TABLE>   <tr> <td width="140"><LABEL><b>Make:</b></LABEL></td> <td width="550"><INPUT TYPE=text NAME="make" ID="make" SIZE="35" MAXLENGTH="60"></td> <td width="10">&nbsp;</td>   </tr> </TABLE> <TABLE>   <tr> <td width="140"><LABEL><b>Model:</b></LABEL></td> <td width="550"><INPUT TYPE=text NAME="model" ID="model" SIZE="35" MAXLENGTH="60"></td> <td width="10">&nbsp;</td>   </tr> </TABLE> <TABLE>   <tr> <td width="140"><LABEL><b>Sub-Model:</b></LABEL></td> <td width="550"><INPUT TYPE=text NAME="submodel" ID="submodel" SIZE="35" MAXLENGTH="60"></td> <td width="10">&nbsp;</td>   </tr> </TABLE> <TABLE>   <tr> <td width="140">&nbsp;</td> <td width="550"><INPUT TYPE="Submit" NAME="submit" VALUE="Submit"></td> <td width="10">&nbsp;</td>   </tr> </TABLE> </form> <?php } // end if ?>[/code] [b]Chained Select[/b] [code]<?php $dbservertype='mysql'; $servername='localhost'; // username and password to log onto db server $dbusername='user'; $dbpassword='pass'; // name of database $dbname='domain_org'; ////// DONOT EDIT BELOW  ///////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } ?> <html> <head> <title>Year/Make/Model Multiple DD - Populated from  Form</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.make.options[form.make.options.selectedIndex].value; self.location='dd3.php?make=' + val ; } function reload3(form) { var val=form.make.options[form.make.options.selectedIndex].value; var val2=form.model.options[form.model.options.selectedIndex].value; self.location='dd3.php?make=' + val + '&submodel=' + val2 ; } </script> </head> <body> <? ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT make,make_id FROM make order by make"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// $cat=$HTTP_GET_VARS['make']; // This line is added to take care if your global variable is off if(isset($make) and strlen($make) > 0){ $quer=mysql_query("SELECT DISTINCT model,model_id FROM model where make_id=$make order by model"); }else{$quer=mysql_query("SELECT DISTINCT model,model_id FROM model order by model"); } ////////// end of query for second subcategory drop down list box /////////////////////////// /////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// $cat3=$HTTP_GET_VARS['submodel']; // This line is added to take care if your global variable is off if(isset($submodel) and strlen($submodel) > 0){ $quer3=mysql_query("SELECT DISTINCT submodel FROM submodel where model_id=$submodel order by submodel"); }else{$quer3=mysql_query("SELECT DISTINCT submodel FROM submodel order by submodel"); } ////////// end of query for third subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='retrieve.php'>"; //////////        Starting of first drop downlist ///////// echo "<select name='make' onchange=\"reload(this.form)\"><option value=''>Select Make</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['make_id']==@$make){echo "<option selected value='$noticia2[make_id]'>$noticia2[make]</option>"."<br>";} else{echo  "<option value='$noticia2[make_id]'>$noticia2[make]</option>";} } echo "</select><br><br>"; //////////////////  This will end the first drop down list /////////// //////////        Starting of second drop downlist ///////// echo "<select name='model' onchange=\"reload3(this.form)\"><option value=''>Select Model</option>"; while($noticia = mysql_fetch_array($quer)) { if($noticia['model_id']==@$submodel){echo "<option selected value='$noticia[model_id]'>$noticia[model]</option>"."<br>";} else{echo  "<option value='$noticia[model_id]'>$noticia[model]</option>";} } echo "</select><br><br>"; //////////////////  This will end the second drop down list /////////// //////////        Starting of third drop downlist ///////// echo "<select name='submodel' ><option value=''>Select Submodel</option>"; while($noticia = mysql_fetch_array($quer3)) { echo  "<option value='$noticia[submodel]'>$noticia[submodel]</option>"; } echo "</select><br><br>"; //////////////////  This will end the third drop down list /////////// echo "<input type=submit value=Submit>"; echo "</form>"; ?>[/code]
  10. Fatal error: Allowed memory size of 18388608 bytes exhausted (tried to allocate 12 bytes) in /home2/admin/kindervision-www/anthonydwayne/add.php on line 15 I just got this message when i inserted data into the input fields, i looked at my database and it's filled up by the same input thousands of times!!!!! woah! heres mysql connection crap: <?php if ($submit) {   // process form $db = mysql_connect("www.afdsfdfdasf.org", "asdf", "afdasdfasdfas"); mysql_select_db("fasdfadfaf_org",$db); // Write the queries $sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')"; $sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')"; $sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')"; // Execute the queries mysql_query($sql) or die(mysql_error()); mysql_query($sql2) or die(mysql_error()); mysql_query($sql3) or die(mysql_error());     $result = mysql_query($sql); //could this be my problem because i dont have $sql2 and 3? wehres my exit too?   require("add.php");   echo('thank you for your add'); } else{   ?>
  11. After thinking about this and comparing it to other forms that update databases to one table, wouldnt it just work regardless without defining anything other than // Write the queries $sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')"; $sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')"; $sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')"; // Execute the queries mysql_query($sql) or die(mysql_error()); mysql_query($sql2) or die(mysql_error()); mysql_query($sql3) or die(mysql_error()); because the value/name/id will match the SQL values so it will just update to the database? Is this logic correct.
  12. Hey its very good helping code i might add, it was just a pain to have to scroll that far. I do not have the values, this will be completely backend where a user will input all data into the form text boxes and will update somewhere else on the site (not relevant where). So as of right now the boxes have no value but a particular name of the text box that populates information to the appropriate tables in the database. Does this make more sense? Thank you again!
  13. I am wanting to know how you assign the input text boxes below the particular SQL query since they are populating different tables in a database. I am assuming the code i need to insert is into the name? like name=[?php sql yadda yadda]. I have no clue :) [code]// Write the queries $sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')"; $sql2 = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')"; $sql3 = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodel')"; // Execute the queries mysql_query($sql) or die(mysql_error()); mysql_query($sql2) or die(mysql_error()); mysql_query($sql3) or die(mysql_error());[/code] and i have 3 input boxes: <INPUT TYPE=text NAME="make" ID="make" SIZE="25" MAXLENGTH="60"> <INPUT TYPE=text NAME="model" ID="model" SIZE="45" MAXLENGTH="60"> <INPUT TYPE=text NAME="submodel" ID="submodel" SIZE="60" MAXLENGTH="60"> THANKS
  14. How do I assign the certain textboxes such as  Make to be assigned to $SQL and Model to be assigned to query $SQL2 etc...? This has to be an elementary procedure but for the life of me I can not find in my reference book PHP and MySQL -Web development. This would be very helpful if someone responds again, thanks again for the reply, it was very appreciated and a great answer to my question!!!!
  15. I suppose too much code below deters people so heres my short question. Is there a way to populate a database from one php page using a form with many textboxes to "many tables" in the "same database" such as $sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";  and   $sql = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')"; and   $sql = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodell')"; all on the same page? Is there a logic behind this? Thanks all!!!
  16. To better understand my issue, I will include all code and small screenshots of precisely what needs to be done. Hence, I am only stuck one part of the code, which is populating add.php's form to populate my database. Only problem is the mysql insert part that screws me up because usually when you insert, it asks you to insert into what table and not individually assign text boxes to populate certain tables in created database. First here is the database code: [url=http://www.kindervision.org/anthonydwayne/sql.txt]http://www.kindervision.org/anthonydwayne/sql.txt[/url] Here is a relational view of my database: [url=http://www.kindervision.org/anthonydwayne/relationship.jpg]http://www.kindervision.org/anthonydwayne/relationship.jpg[/url] Now that you understand the database structure we can move on. --- Dropdown multi-chain select, pulls from database IF manually entered in to mySQL (dd3.php) below [code]<?php $dbservertype='mysql'; $servername='localhost'; // username and password to log onto db server $dbusername='THISWOULDBEUSER'; $dbpassword='THISWOULDBEPASS'; // name of database $dbname='THISWOULDBEDBName'; ////// DONOT EDIT BELOW  ///////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } ?> <html> <head> <title>Year/Make/Model Multiple DD - Populated from  Form</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.make.options[form.make.options.selectedIndex].value; self.location='dd3.php?make=' + val ; } function reload3(form) { var val=form.make.options[form.make.options.selectedIndex].value; var val2=form.model.options[form.model.options.selectedIndex].value; self.location='dd3.php?make=' + val + '&submodel=' + val2 ; } </script> </head> <body> <? ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT make,make_id FROM make order by make"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// $cat=$HTTP_GET_VARS['make']; // This line is added to take care if your global variable is off if(isset($make) and strlen($make) > 0){ $quer=mysql_query("SELECT DISTINCT model,model_id FROM model where make_id=$make order by model"); }else{$quer=mysql_query("SELECT DISTINCT model,model_id FROM model order by model"); } ////////// end of query for second subcategory drop down list box /////////////////////////// /////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// $cat3=$HTTP_GET_VARS['submodel']; // This line is added to take care if your global variable is off if(isset($submodel) and strlen($submodel) > 0){ $quer3=mysql_query("SELECT DISTINCT submodel FROM submodel where model_id=$submodel order by submodel"); }else{$quer3=mysql_query("SELECT DISTINCT submodel FROM submodel order by submodel"); } ////////// end of query for third subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='retrieve.php'>"; //////////        Starting of first drop downlist ///////// echo "<select name='make' onchange=\"reload(this.form)\"><option value=''>Select Make</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['make_id']==@$make){echo "<option selected value='$noticia2[make_id]'>$noticia2[make]</option>"."<br>";} else{echo  "<option value='$noticia2[make_id]'>$noticia2[make]</option>";} } echo "</select><br><br>"; //////////////////  This will end the first drop down list /////////// //////////        Starting of second drop downlist ///////// echo "<select name='model' onchange=\"reload3(this.form)\"><option value=''>Select Model</option>"; while($noticia = mysql_fetch_array($quer)) { if($noticia['model_id']==@$submodel){echo "<option selected value='$noticia[model_id]'>$noticia[model]</option>"."<br>";} else{echo  "<option value='$noticia[model_id]'>$noticia[model]</option>";} } echo "</select><br><br>"; //////////////////  This will end the second drop down list /////////// //////////        Starting of third drop downlist ///////// echo "<select name='submodel' ><option value=''>Select Submodel</option>"; while($noticia = mysql_fetch_array($quer3)) { echo  "<option value='$noticia[submodel]'>$noticia[submodel]</option>"; } echo "</select><br><br>"; //////////////////  This will end the third drop down list /////////// echo "<input type=submit value=Submit>"; echo "</form>"; ?> </body> </html>[/code] This works beautifully, no problems at all, i can populate via mySQL and retrieve all information to retrieve.php. But who in their right mind would enter EVERY single car make, model, and submodel (along with products not in this thread)? No one, so I want to create a form so he can update the make, model, and submodel when he has a product for that exact match. --- Form that needs to populate Database ---  ****this part is the only bad part*** (add.php) below In this code i took the OO approach with no prevail, by no means is this the only way I want to do it, I just need to figure out how to populate the dd3.php from add.php. [code]<?php //test.php if (isset($_POST['submit'])) { echo "submitting <br>"; include_once("conn.php"); // new Car MAKE:;  replaced title with submodel here $newmake = new make; $newmake->submodel = ($_POST['submodel']); $newmake->PersistNew(); // new Car MODEL replaced fname and firstname with model might have to put in a newmodel to put in make as link $newmodel = new model; $newmodel ->model = ($_POST['model']); // $newmodel ->make = ($_POST['make']); $newmodel->PersistNew(); // new Car SUBMODEL $newsubmodel = new submodel; $newsubmodel ->make = $newmake->id; $newsubmodel ->model = $newmodel->id; $newsubmodel->PersistNew(); echo "done, check out the database"; } else { ?> <html> <form method="POST" action="add.php"> <table width="720" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">  <tr>     <td>Car Make:</td>     <td><input name="make" /></td>   </tr>   <tr>     <td>Car Model:</td>     <td><input name="model" /></td>   </tr>   <tr>     <td>Car Submodel:</td>     <td><input name="submodel" /></td>   </tr>   <tr>     <td><input type="submit" name="submit" value="submit" /></td>     <td><input type="reset" /></td>   </tr> </table> </form> </html> <?php } ?> </body> </html> [/code] This is the next part that makes it tick: [code]<?php // conn.php // A database persitable object, pretty useless unless you extend it.  class Persistable {       // Unique database identifier.       var $id;       // Table name that is used in the database       var $table;       // Map of column labels in the database to object variables       var $columns = array();       // Persist a new object in the database.       function PersistNew() {         mysql_connect('localhost', 'username', 'password')                   or die("Could not connect: " . mysql_error());         mysql_select_db('databasename')               or die ("Unable to select database");                 $sql = "INSERT INTO `".$this->table."` ";         $labels = "(`id` ";         $values = ") VALUES ('' ";         foreach ($this->columns as $column) {           $labels .= ", `".$column[0]."` ";           $temp = '$this->'.$column[1];           $values .= ", '"."$temp"."' ";              unset($temp);         }         $sql .= $labels.$values.")";         eval ("\$sql = \"$sql\";");         $result = mysql_query($sql);         $this->id = mysql_insert_id();       } }// End Class Persistable class make extends Persistable {       var $make;//String of submodel title.       function make() { //Constructor for make.         $this->table = 'make';         $this->columns = array( array('make','make')                               );       } } // End Class make class model extends Persistable {         var $model; // String of Cars model.        // var $model;  String of Cars Model.           function model() { //Constructor for model.         $this->table = 'model';         $this->columns = array( array('model','model') //,        array('lastname','lname')                               );       } } // End Class model class submodel extends Persistable {         var $submodel; // integer model unique id.        // NOTHING should be here? var $author; //  integer author unique id.           function submodel() { //Constructor for submodel.         $this->table = 'submodel';         $this->columns = array( array('submodel','submodel') //,array('author','author')                               );       } } // End Class submodel ?> [/code] I am SO lost when it comes to getting this to work, although i see no error message (peachy) I am sure i have one of my classes messed up, but I would perfer to do this a non OO way and just hardcode in php. So my final thoughts are, is there a way to :   $sql = "INSERT INTO make(make_id, make) VALUES ('$make_id','$make')";  and   $sql = "INSERT INTO model (model_id, model) VALUES ('$model_id','$model')"; and   $sql = "INSERT INTO submodel(model_id, submodel) VALUES ('$model_id','$submodell')"; in the same page without having to use Object Oriented programming using something called Persisting data? I am not asking for code on how to do this, however it would be very much appreciated, i am however looking for LOGIC, i am getting caught up on one small thing and that is just populating a form to many tables.  Thank you all. Extra info: To see a demo of what i want here are some images of the process it would look like. 1)submit user/pass > [url=http://www.kindervision.org/anthonydwayne/login.jpg]http://www.kindervision.org/anthonydwayne/login.jpg[/url]  2)go to add form > [url=http://www.kindervision.org/anthonydwayne/userselect.jpg]http://www.kindervision.org/anthonydwayne/userselect.jpg[/url] 3)submit the make/model/submodel[url=http://www.kindervision.org/anthonydwayne/add.jpg]http://www.kindervision.org/anthonydwayne/add.jpg[/url] 4)see results in the dropdown at [url=http://www.kindervision.org/anthonydwayne/dd3.jpg]http://www.kindervision.org/anthonydwayne/dd3.jpg[/url]
  17. Heres how i did mine: (not using your code but something similar) [code] <table width="798" cellpadding="0" cellspacing="0" border="1" bordercolor="black" align="center">     <tr>         <td valign="top" bgcolor="#ffffcc">           <table class="events" cellpadding="2" cellspacing="0" align="center" bgcolor="#ffffcc">               <tr>                 <td colspan="7>                 <p>events<br></p></td>             </tr>             <tr>                 <td class="date"><p class="header">Date</p></td>                 <td class="citystate"><p class="header">City/State</p></td>                 <td class="event"><p class="header">Event</p></td>                 <td class="address"><p class="header">Address</p></td>                 <td class="sponsor"><p class="header">Sponsor</p></td>                 <td class="mediaco"><p class="header">Media Co. </p></td>                 <td class="time"><p class="header">Time</p></td>             </tr>      <?php    //Setup connection to the database    $connect = mysql_pconnect("www.domain.com", "user", "pass")    or die(mysql_error());         //Connect to the database     mysql_select_db("dbname", $connect) or die(mysql_error());             // Perform an SQL query on the Address table         $sql_address = mysql_query("SELECT Date, City, Event, Address, Sponsor, Media , Time from events order by date, city")    or die (mysql_error());            // Define the colours for the alternating rows     $colour_odd = "#ffffcc";     $colour_even = "#FFF2BF";    $row_count = 0;  //To keep track of row number         // Fetch the array of records and Loop through them     while($results = mysql_fetch_array($sql_address))    {      // Decide which colours to alternate for the rows      // If Remainder of $row_count divided by 2 == 0.      $row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd;           /* Echo the table row and table data that needs to be looped Check All  /  Uncheck All      <td><a href="' . $results['state'] . '">' .$results      With selected: over until the end of the recordset*/          echo '      <tr bgcolor="' . $row_color . '">       <td><p class=info>' .$results['Date'] . '</p></td>       <td><p class=info>' .$results['City'] . '</a></p></td>       <td><p class=info>' .$results['Event'] . '</a></p></td>       <td><p class=info>' .$results['Address'] . '</a></p></td>       <td><p class=info>' .$results['Sponsor'] . '</a></p></td>       <td><p class=info>' .$results['Media'] . '</a></p></td>       <td><p class=info>' .$results['Time'] . '</a></p></td>       </tr>';           // Increment the row count      $row_count++;    }    // Free the MySQL resource    mysql_free_result($sql_address);    // Close the database connection    mysql_close($connect);    ?>   <!--Close out the table structure-->           </table> <br><br>         </td>   </tr>   <tr bgcolor="ffffcc">     <td height="62">       <div align="center"><font size="2">etc....</font></div></td>   </tr> </table>[/code]
  18. This code works if i keep the action set to form.php which is the same page. But i want it to go to process.php (action="process.php") and echo the results. HOWEVER, if i change the action to another page it will not validate. Any ideas, suggestions? [code] ........FORM.PHP.......<br> <form method="POST" action="form.php"> <table border="0" cellpadding="0" cellspacing="0" bordercolor="#000000" width="600" >   <tr>     <td width="100" align="right">User Name:</td>     <td width="25">&nbsp;</td>     <td width="200">     <input type="text" name="user_name_input" size="30" value="<? echo $user_name_input; ?>"></td>       <td width="275">       <? // only validate form when form is submitted         if(isset($submit_button)){             $error_msg='';             if(trim($user_name_input)=='' || strlen(trim($user_name_input)) < 3 || strlen(trim($user_name_input)) > 12) {                 $error_msg.="Username must be 3 to 12 chars. long<br>";             }             // display error message if any, if not, proceed to other processing             if($error_msg==''){                 // other process here             } else {                 echo "<font color=red>$error_msg</font>";             }         }         ?>     </td>   </tr>   <tr>     <td width="100" align="right">Email:</td>     <td width="25">&nbsp;</td>     <td width="200">     <input type="text" name="email_input" size="20" value="<? echo $email_input; ?>"></td>     <td width="275">     <? // only validate form when form is submitted if(isset($submit_button)){     $error_msg='';     if(trim($email_input)=='') {         $error_msg.="Please enter an email<br>";     } else {         // check if email is a valid address in this format username@domain.com         if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>";     }     // display error message if any, if not, proceed to other processing     if($error_msg==''){         // other process here     } else {         echo "<font color=red>$error_msg</font>";     } } ?></td>   </tr>        <tr>     <td width="100">&nbsp; </td>     <td width="25">&nbsp;</td>     <td width="200">     <input type="submit" value="   Submit   " name="submit_button"></td>     <td width="275">&nbsp;</td>   </tr> </table> </form> [/code]
  19. Simplified Version: Im at yahoo.com, i type in mydomain.com in address bar. i want the user to be redirected to their last current page they were on (yahoo.com). Im doing this so they have to go through my site to that certain page rather than type the exact url into addressbar.
  20. Description: Im at yahoo.com, i type in mydomain.com in address bar. i want the user to be redirected to their last current page they were on (yahoo.com). Im doing this so they have to go through my site to that certain page rather than type the exact url into addressbar. Here is what i got so far: [code] /* Error Checking, if state or city does not exist, then go back to Original URL ... so if you came from Yahoo, go back to Yahoo */ if ($state == "" || $city =="") { $URL=$referrer; header ("Location: $URL"); } /* Error Checking, if here then just do that simple echo more programming would be inserted with includes and what not /* RICHMOND, VIRGINIA: WTVR AND MATTRESS WAREHOUSE*/ elseif ($state == "VA" && $city =="Richmond-Petersburg"){ echo "hi ur from Virginia, Richmond area";} /* Error Checking, this is an else just because who knows what might happen , but hey lets send them back to Yahoo if thats where they came from else { $URL=$referrer; header ("Location: $URL"); } ?> [/code] Everything works except for the fact that it redirects back to the [a href=\"http://www.domain.org/\" target=\"_blank\"]http://www.domain.org/[/a]video/INDEX.PHP not back to say AMAZON or ebay wherever a person is entering the link from. Any ideas? Thanks guys
×
×
  • 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.