-
Posts
827 -
Joined
-
Last visited
-
Days Won
9
Everything posted by fastsol
-
What does your content.php code look like?
-
You're going to have to give us more code than that then. You're basically asking us to blindly write code for you on something that you seemingly don't have written. We can help you if you have issues along the way but we aren't here to write the code for you, especially without previous code provided by you. There are tons of youtube videos on how to use the jquery ajax stuff, start there if you don't know how to do this or where to start.
-
Without knowing a bit more about how you are building the $currentPage var or how you are directing people to the other pages, it's kind of hard to say for sure. Here is an example though using $_GET vars to decide what page it needs to ajax info for. $currentPage = (!empty($_GET['page'])) ? $_GET['page'] : ''; $difference = (empty($currentPage)) ? 'index' : $currentPage; $select = "SELECT * FROM `".$difference."`"; BUT, links that are for anything besides the index would need to have a $_GET var attached. So like index.php?page=tomorrow. Also based on the single $select string I can tell that your DB structure is highly flawed. I am sure you are just learning at this point, so we don't have to get to deep into that right now. I also assume you are using the basic mysql functions, if so, I would highly suggest stopping that practice now before you learn to much of the wrong thing. The mysql functions have now been deprecated and will be removed from PHP in the coming versions. You should learn mysqli of more preferably PDO. If you're learning, then now is the time to get in good habits. Lastly, I truly hope that this is just practice code, cause it's not secure in any fashion. It's also not common to use a var to indicate a table name to gather FROM. It can be done but it's usually for very specific reasons and with several lines of code to ensure it's secure to do so.
-
$sql = "SELECT * FROM login WHERE id='1'"; $get = $connect->query($sql); $row = $get->fetch(PDO::FETCH_ASSOC); echo $row['username']; echo $row['password'];
-
Well there are number of things wrong in the code, but lets start with the error you seem to get. What is the error? You didn't tell us that.
-
What connection library are you using? mysqli or PDO?
-
Very interesting, I just tried your examples to see for myself. I will say that it's pretty stupid of php to typecast when you didn't tell it too. For me it's never an issue cause I always appropriately typecast or know it's type beforehand to know what comparison to do with it. But very good to know none the less. Thanks!
-
Display mysql table after selection from dropdown list
fastsol replied to faie's topic in Javascript Help
You would be wise to look into the jquery library, it would make this far easier for you. Also research the onchange function of jquery to detect when the select option has changed.- 1 reply
-
- ajax
- javascript
-
(and 2 more)
Tagged with:
-
Take a look at this, might lead you somewhere. http://stackoverflow.com/questions/12719859/no-visible-cause-for-unexpected-token-illegal This line I would personally use var mydata = $(this).serialize(); // OR var mydata = $(this).serializeArray(); I recently found the serializeArray() to be more handy, especially when you need/want to add hidden values to the posting array, like 'ajax' => true. So then the receiving php can know if the form was posted via ajax or not. Yes I know it's not foolproof on that, so I always make my form work with or without ajax.
-
I am confused as to how that comparison would be weird. If the md5 hash is the same result for both strings, then yeah they would equal each other. MD5 is highly know to produce same hashes for different strings. I guess I have never ran into a scenario that comparing string values together would not work as expected if they are both strings. By all means there are plenty of times I use === on INT or Bool type values, but never found a reason to on strings. Can you provide us a better example of bad scenario, I am very interested.
-
Php code doesn't recognize include HELP!
fastsol replied to starlight1992's topic in PHP Coding Help
I see product info when I click on 'view product'. What am I supposed to see? -
This part makes no sense. foreach ($connect->query($sql) as $row) { $db_username = $row['username']; $db_password = $row['password']; } Why would you use a foreach on this? You should be only getting a single row from the db, so absolutely zero reason to use a loop of any kind. Also it's rather pointless, but not necessarily wrong, to use a === to compare the values. The POST will only hold string type values and so will the returned varchar columns of a db query. So they are obviously going to match type anyway. I only mention it cause when you read the code it makes it seem like you could be expecting something else besides a string value to compare against, when it's not really possible.
-
Trying to get a several rows and colums with data.
fastsol replied to rvdveen27's topic in MySQL Help
Relying on the html to only allow numbers is a very bad thing to do. The html side can certainly be used to help the user experience but it is NO substitute for real server side validation. You MUST validate EVERY input on the server side, even if it's coming from a secured area. The reason he asked about the column types is cause when you have things like numbers or dates in a varchar type, it's impossible to accurately compare and gather correct data based on the value in the column. Anything that is a number format must be stored in it's according type of column. So prices, if they can have decimal places should be stored as Float, ID's would be INT, dates or time can have a few different types depending on the end usage needed, but I find it easiest to just use DATETIME so that you have an entire date time to compare to no matter what the circumstance. The main point is that you need to store the info in the proper way to be able to retrieve it in the proper way. -
Insert checkbox into database and the select checked ones!
fastsol replied to zazu's topic in PHP Coding Help
Yes assuming that $row is the name of the var you are using and assuming that you have a comma and a space between each value in the string. If you don't understand how to use explode() then check the php.net for documentation, it's a very easy simple function to use.- 11 replies
-
- html checkbox
- checkbox
-
(and 1 more)
Tagged with:
-
Insert checkbox into database and the select checked ones!
fastsol replied to zazu's topic in PHP Coding Help
So you're saying that the selections are stored in the db as a comma separated list like 1-3 years, 3-6 years ? That's still pretty easy to deal with, although not the best way to store the data. Ideally you should have another table that holds the individual selections, similar to a previous post on here. But for your current setup, all you need to do is use explode() on the returned db string to make the $child_age array. $child_age = explode(', ', $row['child_age']);- 11 replies
-
- html checkbox
- checkbox
-
(and 1 more)
Tagged with:
-
Insert checkbox into database and the select checked ones!
fastsol replied to zazu's topic in PHP Coding Help
You mean 2+ values for each User or 2+ values in the db records at all? You should only be gathering records for the particular User of those records right? Honestly it's hard to say cause we don't know your DB structure and how these things you are asking all tie together cause you haven't shown or told us any of that. But to answer your specific question, the code I provided was designed with only a single value in mind for $child_age. You would need to make an array of $child_age instead. Here is a modified version of what I gave you. $child_age = ['2-4 years', '1-3 years']; // I preset a value here to show you how it checks the box when it sees a match. $ages = array( '1-3 years', '2-4 years', '4-6 years' ); $html = ''; foreach($ages as $a) { $html .= '<input type="checkbox" name="children_age" value="'.$a.'"'; // Build first part of the input $html .= (in_array($a, $child_age)) ? 'checked="checked"' : ''; // Check if the db value matches the inputs value $html .= '>'; // Close the input } echo $html;- 11 replies
-
- html checkbox
- checkbox
-
(and 1 more)
Tagged with:
-
Echo out results comma and apostrophe delimited
fastsol replied to solidrocketfuel's topic in PHP Coding Help
The code works for me when I test it like this, basically simulating an array. $a = array( "_IvF4X658hY", "DRF6b1N_KFk", "G-keFAKQHy4" ); echo '"' . join('","', $a) . '"' The problem is likely that $row is not what you want to give the join(), meaning it's probably not formatted right. Do a print_r($row); in the while() and post it back here so I can see what the array looks like. -
I tested your code and it works just fine. The issue is that gmail is likely not accepting your email cause it lacks an immense amount of required things that a legitimate email should have. Hence the highly suggested use of PHPMailer You can achieve it by simply using the mail() with more appropriate headers being set but take it from someone that has spent an tremendous amount of time on this subject for my own online business, use PHPMailer, it's stupid not to.
-
Echo out results comma and apostrophe delimited
fastsol replied to solidrocketfuel's topic in PHP Coding Help
That's cause you are giving the join() a resource, not an array like it needs. You need to get the array of results first with like mysqli_fetch_assoc() -
You can't send an email in localhost unless you setup a local email server or use smtp to someplace like gmail or yahoo. There could be many reasons beyond your code as to why you don't get the email. First, did you check you spam box? It's seriously best to use a php library like PHPMailer to send emails. There is a TON of things that go into actually sending and receiving an email, far beyond the simple mail() in php. PHPMailer handles pretty much all of those other things for you, which will "help" with delivery. Go HERE and download the zip file for PHPMailer. Then HERE for a basic working example code on how to use it. As for your code, remove the @ in front of the mail(). You should never use the @ to suppress php errors, you'll have a very difficult time diagnosing issues like that.
-
Insert checkbox into database and the select checked ones!
fastsol replied to zazu's topic in PHP Coding Help
Ok, then you would be better off using arrays to dynamically build the checkboxes and compare the values. Here's a working concept based on the html you posted. $child_age = '2-4 years'; // I preset a value here to show you how it checks the box when it sees a match. $ages = array( '1-3 years', '2-4 years', '4-6 years' ); $html = ''; foreach($ages as $a) { $html .= '<input type="checkbox" name="children_age" value="'.$a.'"'; // Build first part of the input $html .= ($a == $child_age) ? 'checked="checked"' : ''; // Check if the db value matches the inputs value $html .= '>'; // Close the input } echo $html; $child_age would need to edited to equal the value from the db. So something like $child_age = $row['children_age']; // $row['children_age'] would be the value from the db, just make sure to change the name to whatever the column name is in the db.- 11 replies
-
- html checkbox
- checkbox
-
(and 1 more)
Tagged with:
-
Insert checkbox into database and the select checked ones!
fastsol replied to zazu's topic in PHP Coding Help
To give you a more specific answer, we would need to know more about the html for the checkboxes and the kind of values you are storing in the db for these checkboxes. Here is the most basic of answers though. You simply need to compare the value in the db to the value of the checkbox and if they match, you output the checked attribute with php. For that basic scenario to work, you would need the "name" of the checkbox to be the same as the name of the column in the db that is storing the value for that specific checkbox. // php code in here is basically saying "if var1 equals 1 then echo checked" <input type="checkbox" name="var1" value="1" <?php echo ($db['var1'] == 1) ? : 'checked="checked"'; ?>> <input type="checkbox" name="var2" value="1" <?php echo ($db['var2'] == 1) ? : 'checked="checked"'; ?>> Again, that is the most basic of concepts, which all I can provide without more detailed info about your code / db structure.- 11 replies
-
- html checkbox
- checkbox
-
(and 1 more)
Tagged with:
-
You need to use the prepare() beforehand and placeholders in the query string. $sql_string = "INSERT INTO users SET username = :a, password = :b"; $sql->prepare($sql_string); $sql->bindParam(":a", $username); $sql->bindParam(":b", $password); $sql->execute(); Personally I like to use SET instead of the VALUES method. This way you can easily see what column is getting what value and you can use the same string for the most part when you do a UPDATE too. You also had the spelling wrong on the bind_param which should be bindParam. Here is the manual documentation http://php.net/manual/en/pdostatement.bindparam.php Plus because you set the sql string to $sql, you probably over writen the $sql of the DB object, unless your DB object is named something else. You didn't show the connect .php code so I can't say for sure. But for the code you showed, $sql is NOT a DB object and certainly wouldn't be after you set $sql to the sql string like you did.
-
No, like this if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } mysql_query("DELETE FROM alert WHERE idalert IN(".implode(",", $ids).")"); print_r($ids); In you last post, neither example you showed was even running the query. All you did was, again, define the sql string.
-
Well now that you moved the delete outside the while(), you need the IN() and implode to build the query properly. You don't need the IN() if the delete is INSIDE the while() cause you would just delete the row directly by the $row['idalert'], understand?