-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Well...technically I did mention it in Reply #7. Of course, I forgot to carry that through to my following post.
-
Have you checked to see if MySQL is throwing any errors? Note that you can check with mysql_error(): http://php.net/manual/en/function.mysql-error.php And as QuickOldCar suggested, you shouldn't use addslashes() to escape variables being used in a query. Note the following quote from the documentation for addslashes(): If you don't plan to upgrade to PDO or MySQLi at this time, you can use mysql_real_escape_string(): http://php.net/manual/en/function.mysql-real-escape-string.php
-
For what it's worth, variables like $FirstName, $LastName, etc. contain string values. String values in queries need to be surrounded by quotes. Since double quotes are being used around the query so that variables work, you would use single quotes around the variables which contain strings. So you could do something like this: <?php $insert = mysqli_query("INSERT INTO 1141650_sigma22.JoinDNO (ID,FirstName,LastName,City,State) VALUES (NULL, '".$FirstName."', '".$LastName."', '".$City."', '".$State."')"); ?> However, it's much cleaner to use gizmola's suggestion. $insert = mysqli_query("INSERT INTO 1141650_sigma22.JoinDNO (ID, FirstName, LastName, City, State) VALUES (NULL, '$FirstName', '$LastName', '$City', '$State')"); Note that I added the closing parenthesis between the end double quote and the semi-colon.
-
Since mysqli_query() is a function, the parameters / arguments need to be surrounded by parenthesis. Also, the database link needs to be provided to mysqli_query() as the first parameter since you're using the procedural style. More information can be found here: http://php.net/manual/en/mysqli.query.php Once you have that fixed, you'll need to fix the quotes. Your query currently opens with a single quote and closes with a double quote. Once that's fixed, you'll want to note that the following will always evaluate to true (even if the query fails): if(isset($insert)) { Basically, the isset() function isn't needed. mysqli_query() will return the resultset if the query succeeds or false if the query fails.
-
What does line #30 look like now? Also, have you checked to see if MySQL is throwing any errors? You can view more information on how to do that here: http://php.net/manual/en/mysqli.error.php
-
No problem; glad to help!
-
Note that PHP code shouldn't be viewable through the source code. If it is, the server may not be configured properly...or it doesn't support PHP.
-
Do you know if MySQL is throwing errors? Note that you can use mysql_error() to check. http://php.net/manual/en/function.mysql-error.php Also note that your queries are vulnerable to SQL injection attacks. If you haven't done so already, you'll want to look into mysql_real_escape_string(). http://php.net/manual/en/function.mysql-real-escape-string.php
-
For what it's worth, the original question asked if there was a better way or if you were on the right track. Barand and the others were directing you down a different path. Unless I missed it, the original question didn't state that all the records needed to be on the same page. If that's truly the case, then pagination might not be the answer. With that said, I can understand your frustration. But there's no reason for the offensive language and calling people names. This type of activity will likely lead to you being banned from the forum (note the Forum Rules).
-
Set variable based on another variable - CASE?
cyberRobot replied to simonp's topic in PHP Coding Help
For what it's worth, you could also use if / elseif. More information, including examples, can be found here: http://php.net/manual/en/control-structures.elseif.php Note that you are using an assignment operator here: if ($var1 = "1") { As the code stands now, all three if tests will evaluate to true. Of course, you'll need to add the missing semi-colons after your $var2 statements for the code to even run. -
Have you looked into MySQL's date and time functions: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Perhaps you could use something like DATEDIFF() or PERIOD_DIFF().
-
Just to clarify, is the first name stored in $row_rs1['fname']? If so, you can modify Muddy_Funster's suggestion to: <?php echo substr($row_rs1['fname'], 0, 1); ?>
-
It sounds like you are using $_SESSION variables. Is the session_start() function being placed at the top of all the scripts that need access to those variables?
-
Where is the data coming from...MySQL? What have you tried so far / where are you stuck? If the data comes from MySQL, you should be able to find a solution here: https://www.google.com/search?q=php%20mysql%20data%20as%20an%20html%20table&rct=j
-
Do something with highest variable from an array of variables
cyberRobot replied to peterhuynh's topic in PHP Coding Help
@peterhuynh - It depends on your setup. You could look into using a header() redirect. Or maybe you could import the script to execute with something like require(). -
Technically, it's being overwritten by $POST['name'] which will never work with the form. Note the missing underscore.
-
Do something with highest variable from an array of variables
cyberRobot replied to peterhuynh's topic in PHP Coding Help
You could use current() or array_shift to get the first element. Then run a simple if test. -
Basically, you would add something like this: <input type="hidden" name="name" value="<?php echo htmlentities($id); ?>"> <div class="form-actions"> <button type="submit" class="btn btn-success">Create</button> <a class="btn" href="workorders.php">Back</a> </div> </form> Note: with the hidden field added, you'll need to modify the code for setting $id to something like this: <?php //... if(!empty($_GET['id'])) { $id = $_GET['id']; } elseif(!empty($_POST['id'])) { $id = $_POST['id']; } else { $id = null; } //... ?> That way the header() function doesn't get triggered. You'll also need to get rid of the following line so you're not overwriting $id: $id = $POST['name'];
-
Just to clarify, is the code shown in Reply 7 in a page called "createworkorder.php"? Also, is there a step before the user fills out the form? Does that step pass a GET variable called "id"? Note that if you're trying to pass the ID along with the form submission, you need to include it in the form somehow. You could, for example, add a hidden form field where $id / $_GET['id'] is the value.
-
It looks like you might be overriding $id here: $id = $POST['name'];
-
You could try adding the following debugging statement to your code right before you attempt to call the display() method: print '<pre>' . print_r($tp, true) . '</pre>'; Does it say that $tp is a "template Object"?
-
Are all PHP errors and warnings enabled? Are they being shown? Note that you can add the following to the top of your script during the debugging process: error_reporting(E_ALL); ini_set('display_errors', 1); Also, have you tried adding some debugging statements to your class to know if things are even being called? For example, you could try something like this: <?php public function display($filename) { print '<div>In display() method</div>'; if(file_exists($filename)) { ?>
-
Is the code to test the existence of $_GET['id'] and set $id in the same script as the PDO query?
-
It's probably not this simple, but have you tried displaying the returned result? print $tp->display(ROOT_PATH.'home.php');
-
passing serialized object in URL not working
cyberRobot replied to roshni's topic in PHP Coding Help
If it makes you feel any better, you're not the only one who's had these problems. I (along with the other gurus, moderators, and admins) do our best to remove the duplicate responses in a timely fashion. Note that your duplicates have been removed.