-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
There are numerous ways such a task could be accomplished. Separating things out into a bunch of separate variables is probably the least efficient way of handling it though. Use arrays, and rather than using a bunch of separate arrays, just use a single array called $records or similar. $query="SELECT * FROM carer INNER JOIN valid_users ON valid_users.id = carer.valid_users_id WHERE valid_users.id=:id"; $stmt = $dbh->prepare($query); $stmt->execute(array(':id' => $myid)); $records = $stmt->fetchAll(PDO::FETCH_ASSOC); $records[0] would be your first contact, $records[1] would be your second (if it exists). You can check if there is one or two contacts by using count($records). Setup your form using a similar array structure so it's easy to handle when submitting changes. <fieldset> <legend>First Contact</legend> <p>Firstname: <input type="text" name="records[0][firstname]" value="<?=htmlentities($records[0]['firstname])?>"></p> <p>Lastname: <input type="text" name="records[0][lastname]" value="<?=htmlentities($records[0]['lastname])?>"></p> ... </fieldset> <fieldset> <legend>Second Contact</legend> <p>Firstname: <input type="text" name="records[1][firstname]" value="<?=htmlentities($records[1]['firstname])?>"></p> <p>Lastname: <input type="text" name="records[1][lastname]" value="<?=htmlentities($records[1]['lastname])?>"></p> ... </fieldset> When submitting the data you can just loop the records to save the details: foreach ($_POST['records'] as $data){ //Insert or update using $data['firstname'], $data['lastname'], etc }
-
By using any of the browser's debugging tools like Firebug, chrome console, etc. Or by just saving the form, editing the HTML to change it, then submit it.
-
mysql_real_escape_string() would still be fine for a number, intval() is just a common quick alternative for numeric parameters like IDs. It won't prevent anyone from submitting a non-numerical value, you would have to do that validation separately if you want to check for it.
-
If the /issue/ part is constant and only the number varies then you would use a regex like this: $str = preg_replace('~\b/issue/(\d+)\b~', '<a href="/issue/$1">/issue/$1</a>', $str); That will find any instance of /issue/ followed by a sequence of digits and replace it with the link. The $1 in the replacement string is a back-reference to the first parenthesized group which is the issue number.
-
Those extra comments add nothing of value. All they do is say what the code should be doing, which is already obvious. If it were actually doing that, you wouldn't be posting here so what you need to tell us is what it's actually doing. You said it doesn't insert the data, but how exactly does it fail? Do you get redirected to the error page? Do you see the success page but no data in the DB? Have you checked the error message mysql gives you if the query fails? That is all basic debugging steps you should have completed before posting. The results of those steps should have been included in your first post.
-
What exactly do you expect your anchor tag for readtextfile.php to do? If you want it to load that PHP file, you need to fix the href to actually point to that file, right now it's pointing to some non-existent http:readtextfile.php.
-
You need to pass the connection into the function when you call it as a parameter. If you currently only define $conn within your class as shown, then you'll need to change that so you can get a reference to it from outside the class. For example, make your connect method return $conn. function getUserId($conn, $name){ ... } $db = new dbConnect(); $conn = $db->connect(); $id = getUserId($conn, 'blah');
-
Array to json is giving me trouble, help please...
kicken replied to Rita_Ruah's topic in PHP Coding Help
The data parameter to the ajax function needs to be either a string or an object of name/value pairs. What you need to do is create an object with a property and stick your encoded json as the value of the property. For example: var data = { array: <?php echo htmlspecialchars(json_encode($array), ENT_NOQUOTES); ?> }; $.ajax({ type: "POST", url: "process.php", data: data, success: function (msg) { console.log(msg); } }); -
if one insert query fails, 'undo' the previous
kicken replied to paddy_fields's topic in PHP Coding Help
force a failure by introducing a syntax error into your query for example. -
Yea, nobody is going to dig through your entire site to help you. Paste just the relevant portions of your code. The bit where you generate the insert and execute it.
-
Can anyone suggest what Errcode: 2 or [mysqli.query]: (HY000/6) is ?
kicken replied to jason310771's topic in MySQL Help
Basically mysql is trying to delete the files for a temporary file it created but is unable to, apparently because it's already been deleted. Make sure you don't have any other process going though and deleting the files. Make sure your /tmp directory has the proper permissions set. -
No, don't move it. The data belongs where it is, just because you can't currently handle it doesn't mean it doesn't belong there. You should just mark it as processed and optionally include an error code that will indicate it needs to be re-visited. Trying to shuffle stuff around between tables is only going to cause you headaches in the future.
-
Add some margin for UL elements that are a child of a LI element. ul { padding: 0px; margin: 0px; } li > ul { padding: 0px; margin-left: 1em; }
-
You can use your union query, and you don't need the left joins to make a null result set. As mentioned, add another column to identify the queries in the results and then modify your code to check for the specific results. For example, since you mention needing them in a particular order and check for anything missing, you can just number the queries and as you read the results make sure the numbers are contiguous. SELECT 1 as resultNumber FROM `table1` WHERE `id` = '1' UNION SELECT 2 as resultNumber FROM `table2` WHERE `id` = 1 UNION SELECT 3 as resultNumber FROM `table3` WHERE `id` = 2 UNION SELECT 4 as resultNumber FROM `table4` WHERE `id` = 3 ORDER BY resultNumber $count=0; while ($row=$query->fetch()){ $count++; if ($count != $row['resultNumber']){ //Gap found, something is missing } }
-
You'd need to make sure your variables are escaped and that you generate valid SQL statements. As your code stands right now, you are not doing either. UPDATE bloging SET title=$nTitle, tekst=$nText WHERE title=$oldTitleafter substituting the variables you'd yield: UPDATE bloging SET title=novinaslov, tekst=novitekst WHERE title=Stari naslovNotice how there are no quotes around your values? However, forget your variables in the SQL method. You should be using prepared statements with bound parameters: $sql = "UPDATE bloging SET title=:ntitle, tekst=:ntext WHERE title=:oldtitle"; $stmt = $conn->prepare($sql); $stmt->execute(array( ':ntitle' => $nTitle , ':ntext' => $nText , ':oldtitle' => $oldTitle ));
-
Why not just swap the order of them so the second regex is tested first? Order all your rewrites from most-specific to least specific.
-
Actually a leading 0 (in a number literal) causes the number to be treated as octal. In octal 08 and 09 are invalid numbers. The correct way to specify 8 and 9 would be 010 and 011. That is why the code failes on those two cases.
-
You handle it programmatically. You'd have one connection for handling reads, and a separate connection for handling writes. In you're code you'd use which ever connection is needed at the time.
-
Use INNER JOIN not LEFT JOIN when you want to exclude rows with missing scores. SELECT n.name, s.score FROM names n INNER JOIN scores s ON n.man_no=s.man_no WHERE s.score > 0
-
I'm not sure what you're asking for. Do you have an excel file and want to use that as your database? In other words create a PHP script to allow people to search your excel file for information? If that is what you want, it could be done but you'd be better off moving that data into a real database instead.
-
Assuming these are linux servers with SSH access enabled, setup SSH keys for both servers to enable public-key-authentication between the two. Then you can use sftp or scp to transfer files between the two without having to enter password details. As a second option, regardless of OS, you could always just setup FTP servers on each and create a login for the other server to connect and send a file. Either of these options could be done directly from PHP code or you could exec() out to an external tool to handle the transfer. As a third alternative you could setup some kind of periodic sync to keep a certain directory in sync between the two servers. cront + rsync would be one way to handle this. There are other tools out there as well.
-
Your variable characterBackpack doesn't exist when the first line is executed so you get an undefined variable error. Swap the order of the lines so you assign characterBackpack first then characterBackpackDisplay second. Your posted errors are similar undefined variable errors but the code you've posted provides no clues as to why.
-
You should contact the tech support for that software, as only they will really know what is going on and what needs to be done. Mentioning ODBC though, you may need to go into the control panel and setup an ODBC source for mysql. Open up your control panel, search for ODBC to find the config tool and add a new data source for mysql. Then in your app for the data source field enter the same name you used in the odbc dialog.
-
As a very simple example: <script type="text/javascript"> //Wait til the document is ready before running our code. //This is necessary to ensure all the dom elements exist. //See: http://api.jquery.com/ready/ jQuery(function($){ //Set a recurring timer that will trigger every 30 seconds. //See: https://developer.mozilla.org/en-US/docs/Web/API/Window.setInterval setInterval(function(){ //Select the DIV we want to change the contents of var $target = $('#targetDiv'); //Ask jQuery to load the given URL into the DIV's content area //The URL has to be local to your site, you cannot load something external //See: http://api.jquery.com/load/ //And: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript $target.load('yourUrl.php'); }, 30000); }); </script> <div id="targetDiv"></div> http://jsfiddle.net/jXLK8/1/