-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Ok - let's walk thru the code you just posted. It is a function so there should be something returned from that function. You are not. You make a call to have the connection established with the proper arguments. That is good. You then print out a result. That is not good. HOW do you know that the connection was successful? You have not turned on error checking nor do you test the result of the call to PDO for success or failure. You simply say you had success and THEN you turn on the errormode attributes. I have to wonder how much programming you did 10 years ago. You don't seem to have the mind of a programmer since all of the things I have pointed out are perfectly normal ways of doing things for a programmer. Where did you get this code? You should be - setting the values (you did) - setting the attributes - make the call to create the connection USING AN IF - handle the if result by returning a value to the calling code. Let it decide what to do. I'm no expert but I do think your setting of $host is not right at all. For one thing that is where the database is selected, not as a separate argument to the PDO call. So once again I ask - Where did you get this code?
-
Option tags are not input tags. The value you give them when you write out the html will always be there. As for what you are asking, I have no clue what you want to do.
-
No, I was getting tired of the same questions over and over too. And - I didn't see his previous ending message until I read the beginning of what looks like another 5-pager. Let's start our own question here. If one is using prepared statements do you really have to use htmlentities on the incoming POST values before putting them to use in a query? Seems to me like the prepare takes care of that but since I don't ever use it I don't know.
-
looking for an easy way to implement pagination
ginerjm replied to alexandre's topic in PHP Coding Help
You know - you don't really have to repeat every post when you make a response..... Here is the sample //******************************* //******************************* function DisplayPage() { global $action, $errmsg, $hide, $focusid, $ah_php_path, $show_div_titles, $show_borders; /* hide is to turn on/off input tags that are hidden ah_php_path is the path to my saved modules that get used here The show.... vars are to enable showing the titles of my div tags and their borders if I am rearranging things during page design. focusid is used by my php to set focus on different inputs */ if ($show_div_titles) $div_title = ''; else $div_title = "title=''"; if ($show_borders) $border = " style='border:1px solid white; '"; else $border = ''; $code=<<<heredocs <!DOCTYPE html> <html lang='en'> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>xxx</title> <style type="text/css"> body { height:100%; width: 100%; margin: 0px; padding: 0px; border: none; background-color:#c0c0c0; font-family:'Segoe UI','Trebuchet MS',Tahoma,Arial,Sans-serif; } p, h1, h2, h3, h4, h5, h6 { margin:0px; padding:0px; } .bold {font-weight:600;} .red { color:red;} .black {color:black;} .yellow {color:yellow;} .orange { color:#f71602; font-weight:800; } label,input {font-size:16px;} input { color:black; background-color:white; } .smltxt {font-size:12px;} .regtxt {font-size:18px;} .medtxt {font-size:22px;} .lgtxt {font-size:26px;} #form_box { position:relative; float:left; margin:1% 1%; padding:10px; border:1px solid yellow; } /* MEDIA QUERY */ /* MEDIA QUERY */ /* MEDIA QUERY */ @media screen and (max-width: 600px) { #form_box { position:relative; float:left; margin:1% 1%; padding:10px; border:1px solid yellow; } label,input{font-size:14px;} .smltxt {font-size:12px;} .regtxt {font-size:16px;} .medtxt {font-size:20px;} .lgtxt {font-size:24px;} } /* end of media query */ </style> heredocs; echo $code; require $ah_php_path . 'js/setFocus.js'; $code =<<<heredocs </head> <body bgcolor='#c0c0c0' onload='setFocus("$focusid")'> <center> <span class='lgtxt'> xxx Page Title </span> </center> <br> <span class='red regtxt'> $errmsg </span> <div id='form_box' $border $div_title title='form_box'> <form name='thisform' method='POST' action='$action' autocomplete='off'> <input type='submit' name='btn' id='rtnbtn' value='Return' accesskey='r'> </form> </div> <br> </body> </html> heredocs; echo $code; } Any new divs of forms that you create with your php you place into a var and then add that var to the global line and put it where you want that code to appear. I do very little php in this function as you can see. -
looking for an easy way to implement pagination
ginerjm replied to alexandre's topic in PHP Coding Help
The trick that I use is to always use a single function to display my page once I am done using php to generate the dynamic content. As recommended above I use php vars to assemble all of that and then my function uses references those vars globallly to display those results where they need to fit in to the html. Pretty much I have a nice html template that has all of my most common features for any page that I develop so it's simply a matter of getting the inputs of the form being displayed and creating the desired output from them and creating a var to hold the query results (an html table or a select tag, etc.) and then call my displaypage function and then exit. PS - I ALWAYS use the heredocs construct to build my html content that way the php vars fit right without having to use any php tag EVER. Check it out in the manual. It is invaluable. -
trying to make a div parent of all rows pulled from database
ginerjm replied to alexandre's topic in PHP Coding Help
Well you don't need multiple divs to accomplish that. One is enough. Just add the CSS to it. -
trying to make a div parent of all rows pulled from database
ginerjm replied to alexandre's topic in PHP Coding Help
you've lost me. Good luck. -
trying to make a div parent of all rows pulled from database
ginerjm replied to alexandre's topic in PHP Coding Help
What does this mean? I thought we were talking about a row? You want to output a set of headings for ever data row in your report/screen? Kinda messy to me. -
Which line exactly is 131? Show it HERE Please do the following: 1 - you should have only one '<form' tag and only one '</form' tag. Please confirm 2 - the contents of that form between the 2 form tags should have a submit button ie. "<input type='submit'" . Confirmed? 3 - the line 131 should be this one by my reckoning: <form method='POST'> <label><b>First Name: </b> <br> <!--- LINE 131 BELOW --> <input type='text' name='fname' size='20' maxlength='40' value='$fname' required> </label> If all 3 of my question are true then I have no idea what else you have in your code that is causing the problem. I'm guessing it is something to do with the initialization of all your php vars when you don't detect a POST array. One thing we could do is move that block to define all the vars before you begin any code.
-
trying to make a div parent of all rows pulled from database
ginerjm replied to alexandre's topic in PHP Coding Help
And I think you only need the one div to wrap the entire table in. And yes - use the <th> tags for your headings and then don't echo them out any more. // Begin table echo " <div class='tbl_box'> <table class='rankingtable'> <tr> <th>username</td> <th>last donation</th> <th>total donated</th> <th>total_received</th> </tr> "; // data rows into table while($result_row ->fetch()) { echo " <tr> <td class='remain1'>{$result_row['users_name']}</td> <td class='remain2'>{$result_row['donation']}</td> <td class='remain3'>{$result_row['total_donated']}</td> <td class='remain4'>{$result_row['total_received']}</td> </tr> "; } // end the table and div echo " </table> </div> "; Note the use of {} to wrap your row data fields instead of what you were doing. as for the height of your headings row: That' s simply some Css that you could add for that row. Or simply add a <br> tag to the heading text -
Now isolate the line (or two) that is giving you the error.
-
Post your entire NEW code so that I can see what you are really running. Hopefully I am going to recognize ALL of my code and only have to be concerned with what you added. If that is not the case then why bother?
-
It sounds like you are having the same problems that you and us have already gone over multiple times. If you had simply pasted in a line of code to go with one of those errors, we could condescendingly tell you once again what to change. And at the same time maybe you will begin to understand. I have never been involved with a topic that has taken 4 pages of back and forth to finish. AND - I don't see how you could be getting that error for fname when I replace the code that used that. You must not be using MY code with your additions to it.
-
USE THE CODE I WROTE FOR YOU. AND DON'T CHANGE A THING UNTIL YOU UNDERSTAND EVERY LITTLE THING THAT IT DOES.
-
Why do you care so much about a name? If they can't spell their name correctly, why bother checking it? You could learn something by reading up on "filter_var" in the PHP Manual. And - while you are probably using a varchar for your table columns for the name fields, do you really want them to run 255 chars in length? You're specifying a size of 20 in your html (which means nothing) and a max length of 40 (which does) so why are you accepting input up to 255?
-
Tired of waiting so I re-wrote your supposed code that you posted. This is how I would do it even though I'm not sure about some of what you are doing. PLEASE read this and try to understand it before you CHANGE A THING. This is a learning experience so please try instead of just changing things. <?php // THIS IS HOW YOU WRITE A SCRIPT // THIS IS HOW YOU WRITE A SCRIPT // THIS IS HOW YOU WRITE A SCRIPT // // start your php code here. session_start(); error_reporting (E_ALL); ini_set('display_errors','1'); $errors = array(); require "conn/connect_seniorform2.php"; // MORE PHP CODE IF ANY // MORE PHP CODE IF ANY // MORE PHP CODE IF ANY // DO WE HAVE A FORM TO PROCESS?? if($_SERVER["REQUEST_METHOD"] == "POST") { // read the inputs $fname = htmlentities($_POST['fname'],ENT_QUOTES); $sname = htmlentities($_POST['sname'],ENT_QUOTES); $email = htmlentities($_POST['email'],ENT_QUOTES); if(strlen($fname)>= 255 || !preg_match("/^a-zA-Z-'\s+$/", $fname)) $errors[] = "Please enter a valid first name"; // whey are you not checking the other inputs here? //*************************** // process the data now if (count($errors) == 0) { $sql = "INSERT INTO senior_dat(fname,sname,email) VALUES (:fname, :sname, :email)"; $stmt = $pdo->prepare($sql); $parms = array( 'fname'=>$fname, 'sname'=>$sname, 'email'=>$email ); if (!$stmt->execute($parms)) $errors[] = "Insert query did not run"; else $errors[] = "Your entries have been accepted"; } } else // no inputs yet { $fname = ''; $sname = ''; $email = ''; } // Done with the inputs - redisplay the form screen with the messages we produced. // // implode the errrors array to show the result message or the errors $errmsg = implode('<br>', $errors); // // BEGIN the HTML output HERE // BEGIN the HTML output HERE // BEGIN the HTML output HERE echo " <!DOCTYPE html> <html lang='en'> <head> <style type='text/css'> #form_box { position:relative; float:left; margin:3% 1%; padding:5px; border:2px solid black; } .red{color:red;} </style> </head> <body> "; echo " <div id='form_box'> <center> <h1>SENIOR RENEWAL FORM</h1> </center> "; if(!empty($errmsg)) echo "<p class='red'>$errmsg</p>"; echo " <form method='POST'> <label><b>First Name: </b> <br> <input type='text' name='fname' size='20' maxlength='40' value='$fname'> </label> <br> <label><b>Surname: </b> <br> <input type='text' name='sname' size='20' maxlength='40' value='$sname'> </label> <br> <label><b>Email: </b> <br> <input type='text' name='email' size='20' maxlength='40' value='$email'> </label> <br><br> <center> <input type='submit' value='Submit'> </center> </form> </div> "; // any more html code.... // Done echo " </body> </html> "; exit(); Please study this. I am attempting to show you something and hoping it gives you something to understand and grow from. I do think your edit of the fname field is incorrect. Don't use that code myself so I can't help you with it. Plus if you are going to edit one input why not all the inputs to be sure the user is doing his part correctly. And I am dropping out. Any topic that goes to 4 pages is way over-done. If this doesn't get you on the right path then I'll let someone else pick up and see if they can do it. PS - Note how one can insert PHP vars into the html code rather than trying to produce that output while writing the html. Build the vars before you start the html and just insert the vars into the portion of the html code that you want that data to appear. See how I did the errors array.
-
Yes that is the code I posted. It is not the code you tried to run because the word 'echo' would not have come out of MY code. As for the error message: Parse error: syntax error, unexpected 'fname' (T_STRING), expecting ';' or ',' in /homepages/30/d593365489/htdocs/MFC1066/senior_data4.php on line 59 You have to locate line 59 and show it to us. You have an issue with something on it so let us see it. That's how WE solve these problems. Do not change a THING! :13 minutes later: I think I know the line. Waiting to see if YOU can locate it too.
-
Based upon the topic we have to assume something since one who has utterly no knowledge probably should not be getting in too deep. As for this post I don't get it. You showed us some output from the code I posted days ago that could not have occurred unless you altered it. Then you showed me your code that would not have produced what you showed me.
-
Empty function no longer detects an empty select list
ginerjm replied to Phphineas's topic in PHP Coding Help
Where does $_REQUEST have to do with this? You are apparently processing a POST method on a form so stick with that! And what do the fields "field_value" and "select_value" have to do with this topic? You are only showing us one form field and it is named "my_select". And you are trying to access a field named "myselect" but you are not showing us that field in your code example either. And - when one posts code here you should use the <> symbol at the top of you window to post the code into. Makes for nicer reading. And leave out the extra blank lines too if you can. -
Array Question: brackets within brackets syntax
ginerjm replied to ChenXiu's topic in PHP Coding Help
I blew my answer. Should have drank a bit more coffee -
Array Question: brackets within brackets syntax
ginerjm replied to ChenXiu's topic in PHP Coding Help
Cause $_GET is NOT an element of $_SESSION -
I have no idea what that line "echo 'active'; is suppose to be doing. I see the word 'active' being output to your page but for what purpose? Then I see a loop that uses some very complex code to output your links to your different menu pages. Perhaps you need to change that function to return the value rather than output it? Even better combine those two operations into a single block the uses the loop to produce your desired output. And what class do you want to use for the items you don't see as being active? How do you like this attempt? $pageArray = array('Page1','Page2','Page3','Page4'); $menu_array = explode('/', $_SERVER['REQUEST_URI']); $current = end($menu_array); echo '<ul>'.PHP_EOL; foreach($pageArray as $pg) { echo "<li><a "; if($pg == $current) echo "classs='active' "; else echo "class='inactive' "; echo "href='(I do not know)?page=\"$pg\"'>$pg</a></li>".PHP_EOL; } echo "</ul>".PHP_EOL; Which gave me this which may be close: <ul> <li><a class='inactive' href='(I do not know)?page="Page1"'>Page1</a></li> <li><a class='inactive' href='(I do not know)?page="Page2"'>Page2</a></li> <li><a class='inactive' href='(I do not know)?page="Page3"'>Page3</a></li> <li><a class='inactive' href='(I do not know)?page="Page4"'>Page4</a></li> </ul> Of course I ended up with no active classes since my uri doesn't match your array.
-
I would choose a db table instead of an array. That way when you have to make additions or removals it's a simple update to a table rather than a coding exercise.