Jump to content

2020

Members
  • Posts

    96
  • Joined

  • Last visited

Everything posted by 2020

  1. Php Buddies, Line 67: $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE $_SESSION['search_column'] = ?"; I get error for the above: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\test\select.php on line 67 How to fix this ? Context: <?php //include('error_reporting.php'); ini_set('error_reporting','E_ALL');//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); require('conn.php'); ?> <form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <label for="search_column">Search in ... ?</label> <select name="search_column" id="search_column"> <option value="page_url">Page Url</option> <option value="link_anchor_text">Link Anchor Text</option> <option value="page_description">Page Description</option> <option value="keyphrase">Keyphrase</option> <option value="keywords">Keywords</option> </select> <br> <label for="tos_agreement">Agree to TOS or not ? *</label> <select name="tos_agreement" id="tos_agreement" required> <option value="Yes">Yes</option> <option value="No">No</option> </select> <br> <input type="button" name="search_links" id="search_links" value="Search Links!"> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['search_links'])) { if(ISSET($_POST['page_url'])) { $_SESSION['search_column'] = $_POST['page_url']; } elseif(ISSET($_POST['link_anchor_text'])) { $_SESSION['search_column'] = $_POST['link_anchor_text']; } elseif(ISSET($_POST['page_description'])) { $_SESSION['search_column'] = $_POST['page_description']; } elseif(ISSET($_POST['keyphrase'])) { $_SESSION['search_column'] = $_POST['keyphrase']; } elseif(ISSET($_POST['keywords'])) { $_SESSION['search_column'] = $_POST['keywords']; } //Re-write the following 4 lines ... mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $conn->set_charset('utf8mb4'); //Always set Charset. $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE $_SESSION['search_column'] = ?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$_SESSION['search_column']); $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); mysqli_stmt_execute($stmt); mysqli_stmt_fetch($stmt); while(mysqli_stmt_fetch($stmt)) { echo "url"; echo "<br>"; echo "anchor_text"; echo "<br>"; echo "description"; echo "<br>"; echo "keyphrases"; echo "<br>"; echo "keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { echo "1. QUERY failed!"; } if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); while($row = mysqli_fetch_array($result,mysqli_assoc)) { $page_url = $row['page_url']; echo $page_url; echo "<br>"; $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>"; $page_description = $row['page_description']; echo $page_description; echo "<br>"; $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>"; $keywords = $row['keywords']; echo $keywords; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("2. QUERY failed!"); } } } ?>
  2. What is the difference between these 2 and which one better ? mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT);
  3. Thanks for the stackoverflow.com link. learnt something. When I come across a malfunction problem, i will just inistialise it mysqli_stmt_init() and problem should vanish! As for my own thread! I guess I haven't visited lately! Running there now. One question: If I come across a good project idea, would you like to work together just for the fun of it ? Experimenting, fiddling, messing with php etc. ? I'll probably do most of the work (structure), you can deal with the security parts as you're better at that compared to me. I think best I PM you when I thinkup any unique or simple good ideas for you to review the ideas. I don't start on any project to build a website just for furn of it. My motto: It should be unique & must have viral money making & viral traffic building features. Else, not my worth while. Wanna get google, youtube & facebook stand on their 2 feet shivering when I walk their paths. Lol! If you can't kill them (big guys), atleast try maiming them before they kill you!
  4. You don't know pdo yet ? We're in the same boat. We can start a race to see who learns faster! Lol! Stick with me, I put a project on hold, you can check it out once the current project is complete. I think you will enjoy it as it seems we sort of think alike. As I too mess about with php to experiment and that project I put on hold is just exactly that.
  5. @StevenOliver, Here you go. Without all the comments you asked for. Why is not this working ? <?php //include('error_reporting.php'); ini_set('error_reporting','E_ALL');//error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); require('conn.php'); ?> <form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <label for="search_column">Search in ... ?</label> <select name="search_column" id="search_column"> <option value="page_url">Page Url</option> <option value="link_anchor_text">Link Anchor Text</option> <option value="page_description">Page Description</option> <option value="keyphrase">Keyphrase</option> <option value="keywords">Keywords</option> </select> <br> <label for="tos_agreement">Agree to TOS or not ? *</label> <select name="tos_agreement" id="tos_agreement" required> <option value="Yes">Yes</option> <option value="No">No</option> </select> <br> <input type="button" name="search_links" id="search_links" value="Search Links!"> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['search_links'])) { $_POST['page_url']; $_POST['link_anchor_text']; $_POST['page_description']; $_POST['keyphrase']; $_POST['keywords']; $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE page_url = ?, link_anchor_text = ?, page_description = ?, keyphrases = ?, keywords = ?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrase'],$_POST['keywords']); $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); mysqli_stmt_execute($stmt); mysqli_stmt_fetch($stmt); while(mysqli_stmt_fetch($stmt)) { echo "url"; echo "<br>"; echo "anchor_text"; echo "<br>"; echo "description"; echo "<br>"; echo "keyphrases"; echo "<br>"; echo "keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { echo "1. QUERY failed!"; } if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); while($row = mysqli_fetch_array($result,mysqli_assoc)) { $page_url = $row['page_url']; echo $page_url; echo "<br>"; $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>"; $page_description = $row['page_description']; echo $page_description; echo "<br>"; $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>"; $keywords = $row['keywords']; echo $keywords; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("2. QUERY failed!"); } } } ?>
  6. You know what. Ignore my previous post as the short version prepared statement sample is in full error. Sorry! >>This is a no-no, by the way: <?php echo $_SERVER['PHP_SELF']; ?> Oh! How so ? Care to show an example how injection will take place if I code like that ? Here is tutorial for you to learn the long version I was talking about using mysqli_stmt_init(): https://www.w3schools.com/php/func_mysqli_stmt_init.asp And here is the short version not using the mysqli_stmt_init(): https://www.php.net/manual/en/mysqli.prepare.php Note on the long version it is: mysqli_stmt_prepare(); While in short version it is: mysqli_prepare(). Note also that, on the short version, mysqli_prepare(), the 1s param is "$conn" or "$link" (connection to mysql), while on the long version mysqli_stmt_prepare(), 1st param is $stmt which points to $conn anyway. Like so: $stmt = mysqli_stmt_init($conn); Hence, I call this last one "long version". Long Version sample: // Create a prepared statement $stmt = mysqli_stmt_init($con); if (mysqli_stmt_prepare($stmt, "SELECT District FROM City WHERE Name=?")) { // Bind parameters mysqli_stmt_bind_param($stmt, "s", $city); // Execute query mysqli_stmt_execute($stmt); // Bind result variables mysqli_stmt_bind_result($stmt, $district); // Fetch value mysqli_stmt_fetch($stmt); Short version sample: if ($stmt = mysqli_prepare($link, "SELECT District FROM City WHERE Name=?")) { /* bind parameters for markers */ mysqli_stmt_bind_param($stmt, "s", $city); /* execute query */ mysqli_stmt_execute($stmt); /* bind result variables */ mysqli_stmt_bind_result($stmt, $district); /* fetch value */ mysqli_stmt_fetch($stmt);
  7. Again writing from memory and I have a bad memory ... You want to knwo what mysqli_stmt_init() is ? Forget it as it's a long version of mysqli prepared statement. i first learnt the shorter way and now sticking to the longer way. Short way was something like this ... $conn = //Mysql Connection details. $query =// Mysql Query. mysqli_prepared($conn,$query); mysqli_bind_param($conn,'ss',$_POST[first_name'],$_POST[surname']); mysqli_stmt_execute($conn,$query); Long version ... $conn = //Mysql Connection details. $query =// Mysql Query. $stmt = mysli_stmt_init($conn); mysqli_stmt_prepared($stmt,$query); mysqli_stmt_bind_param($stmt,'ss',$_POST[first_name'],$_POST[surname']); mysqli_stmt_execute($stmt,$query); Compare the 2. Look at the 1st params of each line. On the short version it is "$conn". On the long version it is "$stmt" which actually points to "$conn" though the "mysqli_stmt_init($conn)" function. So, why am I sticking to the long version ? Have you noticed the short version doesn't have "stmt" on the 2 functions ? mysqli_prepared($conn,$query); mysqli_bind_param($conn,'ss',$_POST[first_name'],$_POST[surname']); I don't feel safe without the "stmt" as it feels sort of unprepared statement. Yeah, I know stupid reason. Hence, sticking to the long version: mysqli_stmt_prepared($stmt,$query); mysqli_stmt_bind_param($stmt,'ss',$_POST[first_name'],$_POST[surname']); Remember, don't take my word for it and do your own research as I just wrote the 2 above samples from memory and like I mentioned earlier I am not fit in the head. Sort of. I am starting to like you. You give me responses. Stick with me. But hold your breath and grab some patience as I can be really annoying when I forget things and ask the same again on another thread of mine.
  8. And, I am over 40 now. Guess if mid 40's or early or late. I learn fast and forget triple fast! That is why you will be teaching me the same stuff over and over again on different threads of mine. Plus, i got high cholesteral, high blood pressure, blood clot issue and gull bludder issue. And a whole lot of others but these ones are troubling me the most. Always got headache. Right now sitting infront of my pc under a fan, wetting my body with wet cloth to remain cool. Very hot. Not well. Shouldn't discuss private stuffs. But hey, not that I'm flashing my id or contact details! If your body don't feel good nor your head, especially at mid-age, or worst at old age, then you become a little "thick in the head" or 'dense" as the yanks would put it (no offense to USA people here!). And, you can forget about managing to stick to plans to carry-out your studying or working plans that you have for the next day. I always make plans but can't be punctual. Atall. Let's see if I can finish sorting the issues I am having now here without getting a headache and quitting for the day to have coffee. Have coffee when you get a headache. Tea, capuccino, etc. doesn't really help. And chew garlic! ThatEven though I'm a Brit like you. Currently in Asia. Long holiday. And it's "bleeming hot here" as we Brits would put it! helps rid the cholesteral and headache or blood pressure a little! Anyway, I won't say anymore or people like Benanamen would be complaining this is a programming forum. And Mac Guyver will ban me.
  9. Php Folks, I started learning php originally from 2015. On & off. Part time. Started getting into it seriously around 2017. From home. No classes. From forums and php manual and tutorial sites. Still at oop & mysqli. Had ups & downs as first learnt a lot of old stuffs then found out they been deprecated. For example, if I had originally known pdo is modern over mysqli then I would started on pdo from beginning. Got no real guidance anywhere. Just learnt things the hard way, coming across obstacles and bugging forums. Half-way learning mysqli I come across pdo. So you see, if I had taken school classes then they would have started me on the new stuffs. But because I learning from home, I came across a lot of old tutorials and started from there without knowing they are sort of outdated stuffs. Anyway, I don't like quitting half-way and so did not quit mysqli for pdo when a lot of programmers advised me to dump mysqli for pdo. Thought, since I "wasted time" on mysqli then might aswell build a few sites with it before ditching it. Part time study. Full time working on projects for 3yrs now. projects are own "hobby sites" so to speak and not for clients. I am not the freelancer type or professional type. layman type. Never really have launched any sites. I finish one site/project then move onto another project for learning purpose. So I learn very little then moving onto building sites based on what little I learnt. When I learnt how to use the SELECT, INSERT. DELETE, UPDATE in sql, I jumped into learning to build my own membership site (reg, log-in, logout, etc. pages) to deal with mysql db. So far, built membership parts (login, logout, account homepage, pagination). All by copying codes from tutorials and forums from people like you and changing here and there according to my needs. And when I get stuck. I bug programmers like you. I do have a conscious and do not like plagiarism even while learning and so everytime I copy paste codes from tutorials or forums (where I get help), I retype every line and then delete the copy-pasted lines and leave my typed lines in the file. that way, I feel good I atleast made some effort to build the site rather than copy & paste. Then, I change the codes here and there to suit my purpose. Don't you like me ? ;). You probably chuckling inside reading this. Here's an example of how I copy-paste then re-write the lines. <?php //Code from: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_login_form ?> <!DOCTYPE html> <!DOCTYPE html> <html> <html> <head> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> <style> body {font-family: Arial, Helvetica, sans-serif;} body {font-family: Arial, Helvetica, sans-serif;} form {border: 3px solid #f1f1f1;} form {border: 3px solid #f1f1f1;} input[type=text], input[type=password] { input[type=text], input[type=password] { width: 100%; width: 100%; padding: 12px 20px; padding: 12px 20px; margin: 8px 0; margin: 8px 0; display: inline-block; display: inline-block; border: 1px solid #ccc; border: 1px solid #ccc; box-sizing: border-box; box-sizing: border-box; } } button { button { background-color: #4CAF50; background-color: #4CAF50; color: white; color: white; padding: 14px 20px; padding: 14px 20px; margin: 8px 0; margin: 8px 0; border: none; border: none; cursor: pointer; cursor: pointer; width: 100%; width: 100%; } } button:hover { button:hover { opacity: 0.8; opacity: 0.8; } } .cancelbtn { .cancelbtn { width: auto; width: auto; padding: 10px 18px; padding: 10px 18px; background-color: #f44336; background-color: #f44336; } } .imgcontainer { .imgcontainer { text-align: center; text-align: center; margin: 24px 0 12px 0; margin: 24px 0 12px 0; } } img.avatar { img.avatar { width: 40%; width: 40%; border-radius: 50%; border-radius: 50%; } } .container { .container { padding: 16px; padding: 16px; } } span.psw { span.psw { float: right; float: right; padding-top: 16px; padding-top; 16px; } } /* Change styles for span and cancel button on extra small screens */ /* Change styles for span and cancel button on extra small screens */ @media screen and (max-width: 300px) { @media screen and (max-width: 300px) { span.psw { span.psw { display: block; display: block; float: none; float: none; } } .cancelbtn { .cancelbtn { width: 100%; width: 100%; } } } } </style> </style> </head> </head> <body> <body> <h2>Login Form</h2> <h2>Login Form</h2> <form action="/action_page.php" method="post"> <form action="/action_page.php" method="post"> <div class="imgcontainer"> <div class="imgcontainer"> <img src="img_avatar2.png" alt="Avatar" class="avatar"> <img src="img_avatar2.png" alt="Avatar" class="avatar"> </div> </div> <div class="container"> <div class="container"> <label for="uname"><b>Username</b></label> <label for="uname"><b>Username</b></label> <input type="text" placeholder="Enter Username" name="uname" required> <input type="text" placeholder="Enter Username" name="uname" required> <label for="psw"><b>Password</b></label> <label for="psw"><b>Password</b></label> <input type="password" placeholder="Enter Password" name="psw" required> <input type="password" placeholder="Enter Password" name="psw" required> <button type="submit">Login</button> <button type="submit">Login</button> <label> <label> <input type="checkbox" checked="checked" name="remember"> Remember me <input type="checkbox" checked="checked" name="remember"> Remember me </label> </label> </div> </div> <div class="container" style="background-color:#f1f1f1"> <div class="container" style="background-color:#f1f1f1"> <button type="button" class="cancelbtn">Cancel</button> <button type="submit" class="cancelbtn">Cancel</button> <span class="psw">Forgot <a href="#">password?</a></span> <span class="psw">Forgot <a href="#">password?</a></span> </div> </div> </form> </form> </body> </body> </html> </html> One thing I gain from this type of re-writings is that, typing the same thing over and over again sort of gets codes sink into my subconscious. Helps to memorise the codes. Ok. So now you know a little about me. As you can see, I always start on somebody else's skeleton, be it from a tutorial forum or a tutorial site or php manual. I have completed 3 websites, so to speak, in that way. 2 days ago I thought, I been doing this for 3yrs now. Let's test and see how well I can code without working on somebody else's skeleton. No copy-pasting from forums or tutorial sites or php manual. And so, look what I did. I coded all the following from my own memory. let me know how well I did. That repetition of lines re-writing has done me some good to memorise codes. I did make 2 mistakes. Note the comments in the code. You will notice "MY CODE ..." and then a correction "WHAT IT SHOULD BE ...". Compare the 2 and see how close or far away I was from the correction. And then give me score from 1-10 (where 10 is best) how well I did as a home study middle aged guy. Hard learning things at middle age. I think, if I had toild you I started learning a month ago then you'd give 9/10 but because it's been 3 yrs, you'll give 1/9 or 0. Just bear in mind it's not easy to learn things at middle age and remember them without forgetting. I learn fast but forget double fast. Lol! One thing though. My codes are not working. They do not INSERT data into db nor extract & display data from db. What is wrong ? TEST NUMBER 1: On this one, I first tried displaying data rows from mysql using mysqli_stmt_get_result(). That failed and so I tried with mysqli_stmt_bind_result() afterwards and so bear that in mind and don't ask me why I used both instead of one. Clicking the "search" button gives no response. Nothing happens on page. I did search for a ketywords that exist in each mysql tbl columns. <?php include('error_reporting.php'); require('conn.php'); //require('search_form.php'); ?> <form name = "search" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <label for="search_column">Search in ... ?</label> <select name="search_column" id="search_column"> <option value="page_url">Page Url</option> <option value="link_anchor_text">Link Anchor Text</option> <option value="page_description">Page Description</option> <option value="keyphrase">Keyphrase</option> <option value="keywords">Keywords</option> </select> <br> <label for="tos_agreement">Agree to TOS or not ? *</label> <select name="tos_agreement" id="tos_agreement" required> <option value="Yes">Yes</option> <option value="No">No</option> </select> <br> <input type="button" name="search_links" id="search_links" value="Search Links!"> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['search_links'])) { $_POST['page_url']; $_POST['link_anchor_text']; $_POST['page_description']; $_POST['keyphrase']; $_POST['keywords']; //I WROTE 2 QUERIES HERE AS I WASN'T SURE HOW IT SHOULD BE. FINALLY, STUCK TO THE LATTER. HOWEVER, ON TESTS NONE OF THEM WORK! //QUERY 1. $query = "SELECT FROM links (page_url,link_anchor_text,page_description,keyphrases,keywords) WHERE keywords = ?"; //QUERY 2... $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE page_url = ?, link_anchor_text = ?, page_description = ?, keyphrases = ?, keywords = ?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrase'],$_POST['keywords']); //WRONG: FORGOT TO ADD "$result = " ... //mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); //CORRECTION: WHAT IT SHOULD BE ... $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); //mysqli_stmt_execute($stmt);WRONG! THIS LINE SHOULDN'T EXIST UNLESS IT'S mysqli_stmt_get_result(). mysqli_stmt_fetch($stmt); //WASN'T SURE WHICH OF THE 3 FOLLOWING LINES ARE CORRECT REGARDING THE WHILE LOOP. FINALLY, STUCK TO THE 1ST LINE ... //1)... while(mysqli_stmt_fetch($stmt)) //2)... //while(mysqli_fetch_array($stmt,mysqli_assoc)) //3)... //while(mysqli_fetch($stmt)) { echo "url"; echo "<br>"; echo "anchor_text"; echo "<br>"; echo "description"; echo "<br>"; echo "keyphrases"; echo "<br>"; echo "keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt);//CORRECTION: THIS SHOULD BE OUTSIDE THE "WHILE LOOP" mysqli_close($conn);//CORRECTION: THIS SHOULD BE OUTSIDE "IF" } else { echo "1. QUERY failed!"; } if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']); mysqli_stmt_execute($stmt); //CORRECTION: FORGOT TO ADD "$result = " $result = mysqli_stmt_get_result($stmt); /* MY CODE WRONG! TRIED ECGHOING THE ARRAY "$row[]"! while($row = mysqli_fetch_array($result,mysqli_assoc)) { echo $row['page_url']; echo "<br>"; echo $row['link_anchor_text']; echo "<br>"; echo $row['page_description']; echo "<br>"; echo $row['keyphrases']; echo "<br>"; echo $row['keywords']; echo "<br>"; echo "|"; echo "<br>"; } */ //CORRECTION: HOW IT SHOULD BE: //$VARIABLE SHOULD BE ECHOED. NOT THE ARRAY $row[] while($row = mysqli_fetch_array($result,mysqli_assoc)) { $page_url = $row['page_url']; echo $page_url; echo "<br>"; $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>"; $page_description = $row['page_description']; echo $page_description; echo "<br>"; $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>"; $keywords = $row['keywords']; echo $keywords; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("2. QUERY failed!"); } } } ?> TEST NUMBER 2: On this one, clicking the "submit links" button gives no response atall!. <?php include('error_reporting.php'); require('conn.php'); //equire('link_submission_form.php'); ?> <form name = "submit_link" method = "POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="domain">Domain:</label> <input type="text" name="domain" id="domain" placeholder="Input Domain"> <br> <label for="domain_email">Domain Email:</label> <input type="email" name="domain_email" id="domain_email" placeholder="Input Domain Email"> <br> <label for="url">Url:</label> <input type="url" name="url" id="url" placeholder="Input Url"> <br> <label for="link_anchor_text">Link Anchor Text:</label> <input type="text" name="link_anchor_text" id="link_anchor_text" placeholder="Input Link Anchor Text"> <br> <textarea rows="10" cols="20">Page Description</textarea> <br> <label for="keywords">Keywords:</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords related to Page"> <br> <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select> <br> <input type="button" name="submit_link" id="submit_link" value="Submit Link!"> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['submit_link'])) { $query = "INSERT into links (domain,domain_email,url,link_anchor_text,page_description,keywords) VALUES ?,?,?,?,?,?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'ssssss',$_POST['domain'],$_POST['domain_email'],$_POST['url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keywords']); mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("INSERT failed!"); } } } ?> What is wrong ? Why both codes don't work ?
  10. You mean, by default if the programmer doesn't set an option to select "selected>" then by default the first option gets selected ? Well, I didn't have any selected by default, no option had the "selected>" and still my dropdown didn't work. Can't remember how it malfunctioned. I think the drop down menu was not appearing to show any options until I added the snippet: <option value="">Select here</option> Then it worked.
  11. I remember now! When my dropdown wasn't working, i was advised to add at the top of all options: <option value="">Select here</option> How come tutorials don;t teach this ? I gave 2 links, you can easily see they don't teach this. How did you programmers figure it out to do it like that to rid the problem, if tutorials didn't teach you ? Confused.
  12. @StevenOliver, Thank you very much! I did not know the differences between the 3 (error reporting, warning, exception handler). Though, I will need to learn more on exception stuff. I didn't know we shouldn't put db credentials on public_html. Thanks for bringing this to my attention. One question, if we put it outside the public folder, then how can files inside the public folder access the credential files without the www ?
  13. Folks, I remember once having a php or html5 issue where the first option had to be blank in the drop down. Otherwise, it wasn't working. What wasn't working ? How wasn't working ? I can't remember. either php had difficulty reading user input or the drop down was not showing any options. And so, I had to add a blank value. So, something like this wasn't working ... <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select> And, I think I added a blank value, at somebody's advice, to get it to work. I think it was something like this, if I remember correctly: <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value=" ">Select here</option> <option value="yes">Yes</option> <option value="no">No</option> </select> Or, maybe it was something like this: <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value=" "></option> <option value="yes">Yes</option> <option value="no">No</option> </select> I can't remember. All I remember slightly that there was a blank value. I been going through my php files to find that particular file to jog my memory but I failed to find it. Can you folks explain to me if a blank value is required or not ? What is the benefit/disaster of adding it and how should the blank value be added ? Show me an example. Was this a php or html 5 issue ? Can anybody fugure ? Thank You
  14. @Kicken, You said: "First of all, it is <label for="">, there's no underscore in there anywhere. Second, no you do not provide labels for each option in a select. The label is to describe the input as a whole, your options are labeled by their text content." I knew this to be true too. So, it should be: <label for="gender">gender</label><br> <input type="radio" id="male" name="gender" value="male"> <input type="radio" id="female" name="gender" value="female"> Q1. Am I right it really should be like the above. Do you people do it like it too ? Anyway, why they complicated here by giving "label for=" for each option ? https://www.w3schools.com/tags/att_input_type_radio.asp <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label><br> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label><br> <input type="radio" id="other" name="gender" value="other"> <label for="other">Other</label> It is this sample that confused me. And so, I opened this thread. Now you know where all my questions and confusions are coming from. Also, @barand, @macguyver, @requinix, @benanamen, Which one out of the 2 would you lot use. (I really shouldn't be naming you folks like this. But hey, no harm in learning your styles and hassling you just a little to squeeze some info out for learning purposes. It would benefit new people to this thread too! )!
  15. Thank you. I thought the "label_for" must match the "name=" and not the "id=". Thanks for bringing this to my attention. Look, here's the confirmation: https://html.form.guide/snippets/html-radio-button-label/ <input type="radio" id="sizeSmall" ... /> <label for="sizeSmall">Small </label> https://www.w3schools.com/tags/att_input_type_radio.asp <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label><br> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label><br> <input type="radio" id="other" name="gender" value="other"> <label for="other">Other</label> I was blind not to see them examples staring at my face. So, I guess both are correct, especially the 1st one: 1. <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label><br> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label><br> https://www.w3schools.com/tags/att_input_type_radio.asp 2. <label> <input type="radio" id="male" name="gender" value="male /">Male </label> <label> <input type="radio" id="female" name="gender" value="female /">Female </label> https://html.form.guide/snippets/html-radio-button-label/ I guess they did the xhtml thing on the 2nd one and so ignoring the " /". I read once about this that for xhmtl they do the closing thing " /" but I forgot about it and Kicken reminded me. But, I did not udnerstand what Kicken meant about <label>. Why some do <label for=> while others do just <label> ? I thought the latter was old stuff. But,
  16. Thank you. Sorry, I did not understand this part and so care to elaborate: "<label> can be be associated with an input either with the for attribute, or by having the input enclosed within it. Enclosing the input is convenient, but it may not always be possible when considering layout requirements. " Also, are you saying these 2 are identical: <button type="submit"> <img src="/images/search.png" alt=""> Search </button> <input type="submit"> <img src="/images/search.png" alt=""> Search </button> From what I understood, if I need to add img on the button then I use the former. But, latter will be wrong ? Cannot use "<input type=" if I want to add img on the button ?
  17. Phew! A lot to digest. No offense, would help if you CAPITALISE your first letter of the sentence. I never really understood the EXCEPTION thing. I have to research on this to understand your reply. Only thing I understood from you is to get php show errors on my DEV version for debugging purpose and not on the production version or it somehow gives the hacker an exray of the skeleton of my php script's security side. And if I still want php to show these errors then best show it to me on a file that is accessible to Admin only and not to the world. Especially, not to a visitor as it will scare them the hell out of my website. Did I understand you atleast 15% ? Like I said, I have to research on the php EXCEPTION thing before I can understand what you really saying. Thank You.
  18. @barand, @requinix, @macguyver, Admin Folks, teach me your way of coding! How to add Labels on Radio Buttons ? Well, 2 tutorials show 2 different ways. Which one is html 5 correct ? 1. https://www.w3schools.com/tags/att_input_type_radio.asp <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label><br> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label><br> 2. https://html.form.guide/snippets/html-radio-button-label/ <label> <input type="radio" id="male" name="gender" value="male /">Male </label> <label> <input type="radio" id="female" name="gender" value="female /">Female </label> IMPORTANT: Why is the a "/" at the end of the "value" on the 2nd example but not on the 1st example ?
  19. @requinix @macguyver I appreciate your feed backs.
  20. Hi, If you notice, all html 5 input types have a "label for="", apart from the drop down. it is like this: Agree to TOS or not ? <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <label for="yes">Yes:</label> <option value="no">No</option> <label for="no">No:</label> </select> Is it ok to add it like this ("label_for" on both the question and options): <label_for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <label_for="yes">Yes:</label> <option value="no">No</option> <label _for="no">No:</label> </select> .... or like this ("label_for" on the question only and not on the options): <label_for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select> ...or like this ("label_for" on options only and not on the question): Agree to TOS or not ? <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <label_for="yes">Yes:</label> <option value="no">No</option> <label_for="no">No:</label> </select> NOTE: I made a mistake above. It should be "label for" and not "label_for".
  21. Also, why some line breaks like this ? <br> while others like this: < /br> https://html5-tutorial.net/forms/multiline-textboxes-textarea/
  22. Why do they add closing "/" at the end ? <input type="submit" value="Submit now" /> https://html5-tutorial.net/forms/multiline-textboxes-textarea/ What is the purpose of "/" at the end ? <input type = "text" name = "search" placeholder = "search the web"/> https://www.tutorialspoint.com/html5/html5_web_forms2.htm
  23. Should I use single or double quotes on html input type mentions ? <input type='radio' <input type="radio"
  24. Html 5 Folks, I got the code from here: https://www.tutorialspoint.com/html5/html5_web_forms2.htm It shows the Submit & reset button html 5 code to be this: <input type = "submit" value = "send"> <input type = "reset"> Q1. Will this be incorrect or not and if not then why not ? <input type = "reset" value = "reset"> Q2. On some tutorials, I see the Submit button code to be like the following if I remember correctly. None of them are not the same as the one I mentioned just above. Which ones are correct ? Give your ranking according to preference and explain your preference reason. <input type = "button" value = "submit"> <input type = "submit" value = "submit"> <button type="submit" class="login" name="login">Login</button> Why is this one "button=type" while all the rest "input type='submit' ? Which one better to use ?
  25. @requinix, @macguyver I need you two's inputs too.
×
×
  • 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.