jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Trying to Run Different SQL Queries to Same Page
jcbones replied to klotzdr's topic in PHP Coding Help
What you need to do is take the WHERE clause out of all of your queries. drapedbustquery.php through walkingquery.php has queries in them, look for the where clause in each files query. Add a hidden field to each form (this is because IE doesn't pass name attributes with image inputs, IIRC), and make sure they are all the same name (type). Notice the empty action attribute. <form id="drapedbusthalves" name="drapedbusthalves" method="post" action=""> <input type="hidden" name="type" value="drapedbusthalves" /> <input type="image" src="images/Draped-Bust-Halves.jpg" alt="SUBMIT" width="330" height="22" /> </form> Then make you a switch statement, and check for the type index in your post query. <?php $where = NULL; //where is built but is empty (NULL). if(!empty($_POST['type'])) { //if the form is sent with the right named input. $where = 'WHERE '; //where starts to build the WHERE clause. switch($_POST['type']) { //switch the variable depending on the case. case: 'drapedbusthalves'; //if this is the contents of the type input element. $where .= ''; //this is where you put the "WHERE" clause from the corresponding drapedbustquery.php break; //dont' forget to end the switch here. case: 'cappedbusthalves'; //else if this is the contents of the input element "type". $where .= ''; //this is where you put the "WHERE" clause from the corresponding cappedbustquery.php break; //always break the switch at the end of case arguments for this switch (there are reasons not to do this, but in this switch you will need to). //etc... //continue until all cases are made. } } Then you need to add one more thing. The where clause to the query. <?php $query = ("SELECT * FROM listings $where" ); //add the where clause we built with the switch to the query. This will be empty (showing a full page) if no button is pushed. -
Yes, PHP prints exactly what you ask it to. While it may show a single line in the source, the browser will read the HTML, and output it correctly. If this is still an issue, you can look into adding line breaks with \n or \r\n. Or, you could use the php constant PHP_EOL. <?php //examples. echo 'Create a line break' . "\n" . 'before this line!'; //notice that the line break must be enclosed in double quotes. echo "Yes it will\nwork here too"; echo "This will" . PHP_EOL . 'also work';
-
You don't need a index in your form. while ($rows = mysql_fetch_array($SqlResult)); ?> <td align="center" bgcolor="#FFFFFF"><input name="need_delete[]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td> <?php Should be fine. Remove_Message() is returing a string of "False". It also has no database interaction, just sets a string in the form of a query.
-
So, how is your table in the database set up? IMHO, you should have relational tables. How many would depend on just how far this application goes.
-
Localhost means exactly that, the local server. Meaning the server that resides on the machine that you are accessing. Each server is local to somewhere. If port 80 (default http port) is opened, anyone can access the server (theoretically).
-
For a small site, I tend to steer clear of typed captcha's, and prefer other forms of form security. Tokens, honeypots, etc. I do this, because even I (who understands why captchas are a must) will leave a low traffic site, if it requires a typed captcha to comment, or join.
-
This section: if($_SERVER['REQUEST_METHOD'] == 'POST'){ die(header("Location: $baseurl/slorg/upload.php?error=Please+do+not+leave+any+info+blank."));} Reads: If POST data has been send, redirect to upload?error=Please+do+not+leave+any+info+blank, then exit the script. I'm not sure that is what you want (I know it isn't). Doing this responded in Please do not leave any info blank. The quoted section, and the section that gives this error, isn't related to each other.
-
Most likely it is because the 'eregi' function is depreciated. Try changing: if (!eregi("image/", $_FILES['Image']['type'])) { to: if(substr($_FILES['Image']['type'],0,5) == 'image' ) {
-
cycling through array with foreach to create another array
jcbones replied to galvin's topic in PHP Coding Help
Try this: <?php //syntax highlighting $startingRBsbefore = array(); foreach($startersrosterbefore as $ID => $row) { if($row['positionid'] == 2) { $startingRBsbefore[] = $row; } } foreach($startingRBsbefore as $value) { echo implode('<br />',$value); } Don't know why it is only returning the last one, as the code in the OP should work. IF each players id is unique. -
Trying to Run Different SQL Queries to Same Page
jcbones replied to klotzdr's topic in PHP Coding Help
So, post what code that you have. Yes, you can make it work all on one page, but we cannot point you in the right direction, if we don't see what you already have. Make sure you wrap your code in the code blocks, its the # button. Cheers, JC -
MySQLi Prepared Statements - Passing a Variable: Question
jcbones replied to Mko's topic in PHP Coding Help
The mysqli object handles all escaping internally. Being that you are passing the salt as a string, it will pass the variable (by reference) through the mysqli::real_escape_string() function. -
array Fatal error: Unsupported operand types
jcbones replied to mrooks1984's topic in PHP Coding Help
What does this give you? $option_price = 0; foreach ($product_option_prices as $product_option_price) { $option_price += $product_option_price['option_price']; } You could even type cast to (float). -
Sometimes a picture is worth a thousand words. So, I dug way back in the library, and dusted off a very old function that I had. It was tucked way back there, in amongst some crumpled paper. <?php //include connection info. include('config.php'); //point to file that holds database connection info. //function to show all results from a table. function browseData($tbl) { //declare function, argument says to pass the function the table name. $result = mysql_query("SELECT * FROM `$tbl`"); //get the resource. $output = NULL; //start the output variable. $output .= mysql_num_rows($result) . " Results!"; //show rows returned. $c = mysql_num_fields($result); //get a count of the fields. $output .= "<table class=\"search\">"; //start a table. for ($i=0; $i < $c; $i++) { //for( start i at 0, if i is less than fields count then continue, incrementing i as it continues) $output .= '<th style="background-color:blue;">'.ucwords(mysql_field_name($result, $i)).'</th>'; //print a table header for each field name. } $d = 1; //yep, I made useless variables too, long ago. Ah, closer look it is for the background alteration of colors. while($r = mysql_fetch_array($result)) { //fetch the array, should either be row, or assoc (in this case row). $output .= '<tr style="background-color:'; //new table row for each row of data. $output .= (($d % 2) == 0) ? '#ACCDE2;' : '#0088E2;' ; //alternate background color for each row. $output .= '">'; //closing the tr element. $i = 0; //start a new $i variable. while($i < $c) { //while i is less than c (field count). $output .= "<td>" . $r[$i] . "</td>"; //print a td element with the contents of the data row/column. $i++; //increment i } $output .= "</tr>"; //close row. $d++; //increment d (who knows). } $output .= "</table><br/><br/>"; //close table, adding spacing. return $output; //return the function contents. } //call the function, and print the results to the page. $db_table = 'test'; //Your table name. echo browseData($db_table); //echoing a function will print the return of that function. (in this case $output) ?> I commented this function, and even left in those things that I used to do that are not the best coding practices. Although, I told how to fix them in the comments.
-
Ujj, if I could offer another suggestion. In the future, store you dates as a DATETIME or TIMESTAMP column type. This is because MySQL has VAST amounts of functions just for dates, and times. Which would make reports a breeze to produce.
-
Ujj, in an effort to understand why we are suggesting to restructure your database, please take the time to watch and understand . IMHO, databases should extend to at least the 3rd Normal Form.
-
Ah Pik, the `ole "stop trying to help me, but give me what I want" thread. You never win in this one. Back to the OP, the request you posted, has nothing to do with the code you posted. <?php session_start(); if(isset($_GET['name'])) { $name = $_GET['name']; $_SESSION['name'] = $_GET['name']; } elseif(isset($_SESSION['name'])) { $name = $_SESSION['name']; } else { $name = 'Guest'; } echo 'Welcome ' . $name;
-
Bldg a FORUM - the FORM doesn't display - WHY?
jcbones replied to Scotty13's topic in PHP Coding Help
You need to find out why: $u_id = mysql_real_escape_string($_SESSION['id']); $u_name = mysql_real_escape_string($_SESSION['username']); $u_email = mysql_real_escape_string($_SESSION['useremail']); $u_loca = mysql_real_escape_string($_SESSION['userloca']); $sql = mysql_query("SELECT * FROM myMembers WHERE id='$u_id' AND username='$u_name' AND email='$u_email' AND locator='$u_loca'"); $numRows = mysql_num_rows($sql); if ($numRows < 1) { echo "ERROR: You do not exist in the system."; exit(); } This database query doesn't work. Try looking at your session variables, and finding why they do not match what is in the database. echo '<pre>' . print_r($_SESSION,true) . '</pre>'; Additionally, please put your code inside of the [ code ] ... [ /code ] blocks provided, they make reading it much easier. -
Do you wish to get the parsed content from server A, to use on server B? Just call the file with a file_get_contents. If you wish to send variables to server A from server B, and have the file parse them, you will have to send those variables via POST, or GET.
-
HTML Form not inserting to mysql... no errors reported
jcbones replied to Doc20's topic in PHP Coding Help
Original Post(er). -
Sorry, I was under the impression that multiple invitations were to be printed. I changed a line or two that should satisfy your interest, although, the code is merely an example. <?php //syntax highlighting while($row = mysql_fetch_row($result)) { //while rows exist in the database. $names[] = $row[4]; //store names in an array. *CHANGED looks like you had 4 and 1 reversed from what you gave. $links[] = '<a href="' . $row[1] . '">' . $row[4] . '</a>'; //store facebook links in an array. *CHANGED looks like you had 4 and 1 reversed from what you gave. } foreach($names as $name) { //loop through the names, and write them a letter. //heredoc syntax. echo <<<EOF Dear {$name},<br /> Please join me this friday at 6pm.<br /> Total quest list: <br /> EOF; echo implode('<br />',$links); //implode all the links with a pipe in between each one. *CHANGED the pipe to a break rule* echo '<hr />'; //*ADDED a horizontal rule. FOR DISPLAY PURPOSES. }
-
Parse error: syntax error, unexpected T_STRING
jcbones replied to MrXortex's topic in PHP Coding Help
Yes, I agree with jazzman, use heredoc syntax, or break out of PHP and use straight HTML since there are no variables in there. The reason why you get that error, is you started the string with a double quote ("), so the next time PHP sees another double quote, it thinks you are ending your string. Other than changing to heredoc, or nowdoc, you can start the string with a single quote ('), or escape the double quotes like (\"). Valid: <?php //syntax highlighting $form = "<form method=\"post\" action=\"signup-p.php\" id=\"signupform\">"; //will populate variable inside the string. //or $form = '<form method="post" action="signup-p.php" id="signupform">'; //will not populate variables in the string. //or //will populate variables in the string. $form = <<<string <form method="post" action="signup-p.php" id="signupform"> string; //or //will not populate variables in the string. $form = <<<'string' <form method="post" action="signup-p.php" id="signupform"> string; -
No need for 2 while loops. Store everything in array's, that way you have a complete list of everyone's facebook links. Then go through the 1st array making invitations, then implode the facebook links to the bottom. <?php //syntax highlighting while($row = mysql_fetch_row($result)) { //while rows exist in the database. $names[] = $row[1]; //store names in an array. $links[] = '<a href="' . $row[4] . '">' . $row[1] . '</a>'; //store facebook links in an array. } foreach($names as $name) { //loop through the names, and write them a letter. //heredoc syntax. echo <<<EOF Dear {$name},<br /> Please join me this friday at 6pm.<br /> Total quest list: <br /> EOF; echo implode('|',$links); //implode all the links with a pipe in between each one. }
-
Or, you could do it with systems that are already available. Like Fusion Charts Free
-
HTML Form not inserting to mysql... no errors reported
jcbones replied to Doc20's topic in PHP Coding Help
Why did you change the information given? $app_application is not what Pik wanted you to test for.